Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbranco80 committed Aug 22, 2024
1 parent 4441ecc commit 8cf78b2
Show file tree
Hide file tree
Showing 28 changed files with 1,267 additions and 947 deletions.
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ writeVersionToFile := {

lazy val root = (project in file("."))
.aggregate(
protocolCompiler,
protocolRaw,
protocolCompiler,
utilsCore,
utilsSources,
compiler,
Expand Down Expand Up @@ -115,12 +115,17 @@ lazy val protocolRaw = (project in file("protocol-raw"))
)

lazy val protocolCompiler = (project in file("protocol-compiler"))
.dependsOn(
protocolRaw % "compile->compile;test->test;protobuf->protobuf"
)
.enablePlugins(ProtobufPlugin)
.settings(
commonSettings,
commonCompileSettings,
testSettings,
ProtobufConfig / version := "3.25.4",
ProtobufConfig / protobufIncludePaths += (protocolRaw / ProtobufConfig / sourceDirectory).value,

// Include the protobuf files in the JAR
Compile / unmanagedResourceDirectories += (ProtobufConfig / sourceDirectory).value
)
Expand Down
1 change: 1 addition & 0 deletions compiler/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
requires com.fasterxml.jackson.datatype.jsr310;
requires com.fasterxml.jackson.datatype.jdk8;
requires raw.utils.core;
requires raw.protocol.raw;
requires raw.protocol.compiler;

exports com.rawlabs.compiler;
Expand Down
1 change: 1 addition & 0 deletions protocol-compiler/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

module raw.protocol.compiler {
requires com.google.protobuf;
requires raw.protocol.raw;

exports com.rawlabs.protocol.compiler;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2024 RAW Labs S.A.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.txt.
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0, included in the file
* licenses/APL.txt.
*/

syntax = "proto3";

option java_package = "com.rawlabs.protocol.compiler";
option java_multiple_files = true;

package com.rawlabs.protocol.compiler;

message PackageDoc {
string description = 1;
optional string info = 2;
optional string warning = 3;
optional string danger = 4;
}

message EntryCompletion {
string name = 1;
EntryDoc doc = 2;
}

message EntryDoc {
string summary = 1;
optional string description = 2;
repeated ExampleDoc examples = 3;
repeated ParamDoc params = 4;
optional ReturnDoc ret = 5;
optional string info = 6;
optional string warning = 7;
optional string danger = 8;
}

message ExampleDoc {
string example = 1;
optional string result = 2;
}

message ParamDoc {
string name = 1;
TypeDoc typeDoc = 2;
string description = 3;
bool isOptional = 4;
bool isVarArg = 5;
optional string info = 6;
optional string warning = 7;
optional string danger = 8;
optional string customSyntax = 9;
}

message ReturnDoc {
string description = 1;
optional TypeDoc retType = 2;
}

message TypeDoc {
repeated string possibleTypes = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 RAW Labs S.A.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.txt.
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0, included in the file
* licenses/APL.txt.
*/

syntax = "proto3";

option java_package = "com.rawlabs.protocol.compiler";
option java_multiple_files = true;

package com.rawlabs.protocol.compiler;

message Message {
string message = 1;
repeated Range positions = 2;
optional string code = 3;
enum Severity {
HINT = 0;
INFO = 10;
WARNING = 20;
ERROR = 99;
}
}

message Range {
Position begin = 1;
Position end = 2;
}

message Position {
uint32 line = 1;
uint32 column = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 RAW Labs S.A.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.txt.
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0, included in the file
* licenses/APL.txt.
*/

syntax = "proto3";

option java_package = "com.rawlabs.protocol.compiler";
option java_multiple_files = true;

package com.rawlabs.protocol.compiler;

import "com/rawlabs/protocol/raw/types.proto";
import "com/rawlabs/protocol/raw/values.proto";

message ProgramDescription {
map<string, Decls> decls = 1;
optional Decl body = 2;
optional string comment = 3;
}

message Decls {
repeated Decl decls = 1;
}

message Decl {
optional Params params = 1;
optional com.rawlabs.protocol.raw.Type outType = 2;
optional string comment = 3;
}

message Params {
repeated Param params = 1;
}

message Param {
string name = 1;
com.rawlabs.protocol.raw.Type tipe = 2;
optional com.rawlabs.protocol.raw.Value defaultValue = 3;
optional string comment = 4;
bool required = 5;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 RAW Labs S.A.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.txt.
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0, included in the file
* licenses/APL.txt.
*/

syntax = "proto3";

option java_package = "com.rawlabs.protocol.compiler";
option java_multiple_files = true;

package com.rawlabs.protocol.compiler;

import "com/rawlabs/protocol/compiler/location_config.proto";

message ProgramEnvironment {
string uid = 1;
optional Arguments arguments = 2;
repeated string scopes = 3;
map<string, string> secrets = 4;
map<string, LocationConfig> locationConfigs = 5;
map<string, string> options = 6;
optional string jdbcUrl = 7;
optional string traceId = 8;
}

message Arguments {
repeated Argument arguments = 1;
}

message Argument {
string name = 1;
string value = 2;
}
1 change: 1 addition & 0 deletions snapi-compiler/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
requires com.fasterxml.jackson.dataformat.csv;
requires com.fasterxml.jackson.core;
requires raw.utils.sources;
requires raw.protocol.raw;
requires raw.protocol.compiler;
requires raw.compiler;
requires raw.snapi.frontend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,24 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
// Prior to .execute, some checks on parameters since we may have
// to fill optional parameters with their default value

// mandatory arguments are those that don't have a matching 'name' in optional parameters
// Mandatory arguments are those that don't have a matching 'name' in optional parameters
val namedArgs = funType.os.map(arg => arg.i -> arg.t).toMap

// split the provided parameters in two (mandatory/optional)
// Split the provided parameters in two (mandatory/optional)
val (optionalArgs, mandatoryArgs) = environment.maybeArguments match {
case Some(args) =>
val (optional, mandatory) = args.partition { case (idn, _) => namedArgs.contains(idn) }
(optional.map(arg => arg._1 -> arg._2).toMap, mandatory.map(_._2))
case None => (Map.empty[String, RawValue], Array.empty[RawValue])
}

// mandatory args have to be all provided
// Mandatory args have to be all provided
if (mandatoryArgs.length != funType.ms.size) {
return ExecutionRuntimeFailure("missing mandatory arguments")
}
val mandatoryPolyglotArguments = mandatoryArgs.map(arg => rawValueToPolyglotValue(arg, ctx))
// optional arguments can be missing from the provided arguments.
// we replace the missing ones by their default value.
// Optional arguments can be missing from the provided arguments.
// We replace the missing ones by their default value.
val optionalPolyglotArguments = funType.os.map { arg =>
optionalArgs.get(arg.i) match {
// if the argument is provided, use it
Expand All @@ -283,18 +283,18 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
case None => f.invokeMember("default_" + arg.i)
}
}
// all arguments are there. Call .execute.
// All arguments are there. Call .execute.
val result = f.execute(mandatoryPolyglotArguments ++ optionalPolyglotArguments: _*)
val tipe = funType.r
// return the result and its type
// Return the result and its type.
(result, tipe)
case None =>
val truffleSource = Source
.newBuilder("rql", source, "unnamed")
.cached(false) // Disable code caching because of the inferrer.
.build()
val result = ctx.eval(truffleSource)
// the value type is found in polyglot bindings after calling eval().
// The value type is found in polyglot bindings after calling eval().
val rawType = ctx.getPolyglotBindings.getMember("@type").asString()
val ParseTypeSuccess(tipe) = parseType(rawType, environment.uid, internal = true)
(result, tipe)
Expand Down Expand Up @@ -483,12 +483,6 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
}

override def hover(source: String, environment: ProgramEnvironment, position: Pos): HoverResponse = {
/*
withLspTree(source, lspService => lspService.hover(source, environment, position)) match {
case Right(value) => value
case Left((err, pos)) => HoverResponse(None, parseError(err, pos))
}
*/
withTruffleContext(
environment,
_ => {
Expand Down
1 change: 1 addition & 0 deletions snapi-frontend/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
requires jul.to.slf4j;
requires org.graalvm.polyglot;
requires raw.utils.core;
requires raw.protocol.raw;
requires raw.protocol.compiler;
requires raw.compiler;
requires raw.utils.sources;
Expand Down
1 change: 1 addition & 0 deletions snapi-truffle/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
requires scala.library;
requires com.ctc.wstx;
requires raw.utils.core;
requires raw.protocol.raw;
requires raw.protocol.compiler;
requires raw.compiler;
requires raw.utils.sources;
Expand Down
1 change: 1 addition & 0 deletions sql-compiler/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
requires com.fasterxml.jackson.dataformat.csv;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires raw.protocol.raw;
requires raw.protocol.compiler;
requires raw.compiler;
requires raw.sql.parser;
Expand Down
Loading

0 comments on commit 8cf78b2

Please sign in to comment.