Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): bring local wing files #252

Merged
merged 45 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c9422ef
wip: Import JSII types to get `bring cloud` working.
yoav-steinberg Sep 22, 2022
e84ce2f
Removed `Nothing` from out type system.
yoav-steinberg Sep 22, 2022
fd76050
Merge branch 'main' into yoav/jsii_import
yoav-steinberg Sep 27, 2022
d7348fb
No need to double check jsii_reflection api following #159.
yoav-steinberg Sep 27, 2022
9cf1d49
WIP: JSII imports:
yoav-steinberg Sep 28, 2022
fd039f5
wip: Import JSII "datatype" interfaces as wing structs.
yoav-steinberg Sep 29, 2022
e614ca0
Handle non primitive type references in JSII imports:
yoav-steinberg Oct 4, 2022
6916688
Treat wingsdk `cloud.Inflight` as `~(any):any` inflight function.
yoav-steinberg Oct 4, 2022
7e23309
Struct literals (currently with a grammar hack `@TypeName`)
yoav-steinberg Oct 6, 2022
2b33b9a
fix: removed Yoav's @ in struct literals
3p3r Oct 6, 2022
8f53968
wingsdk cloud JSII import
yoav-steinberg Oct 9, 2022
0c2e469
oops
yoav-steinberg Oct 9, 2022
55b5433
Merge branch 'main' into yoav/jsii_import
MarkMcCulloh Oct 9, 2022
d1b2eb0
Apply suggestions from code review
yoav-steinberg Oct 10, 2022
424902f
feat(wingc): bring local wing files
3p3r Oct 11, 2022
cbe71e7
Added support for namespace aliases on JSII brings.
yoav-steinberg Oct 12, 2022
08ff9ac
jisify: Remoce hack to always add scope and id to anything objects.
yoav-steinberg Oct 12, 2022
e1271e5
cr fix
yoav-steinberg Oct 12, 2022
3dbae32
cr fix
yoav-steinberg Oct 12, 2022
2f3c6af
cr fix
yoav-steinberg Oct 12, 2022
798f1fc
CR: Fix constructor name.
yoav-steinberg Oct 12, 2022
e04275b
CR fix
yoav-steinberg Oct 12, 2022
e4388e5
cr fix
yoav-steinberg Oct 12, 2022
2842678
Merge branch 'main' into yoav/jsii_import
yoav-steinberg Oct 12, 2022
0c83f75
Update libs/wingc/src/type_check/jsii_importer.rs
yoav-steinberg Oct 12, 2022
c4c3575
Support inheriting from from wingsdk.
yoav-steinberg Oct 12, 2022
4185d9b
fix grammar test
yoav-steinberg Oct 12, 2022
cfc50fd
feat: hacked together a jsii-ify to experiment with the idea of compi…
3p3r Oct 13, 2022
9c597fe
cr
yoav-steinberg Oct 13, 2022
77e6b52
Merge branch 'main' into yoav/jsii_import
yoav-steinberg Oct 13, 2022
ba7cc09
Merge branch 'main' into yoav/jsii_import
yoav-steinberg Oct 13, 2022
b7ba6e5
feat(wingc): bring local wing files
3p3r Oct 11, 2022
feb6579
feat: hacked together a jsii-ify to experiment with the idea of compi…
3p3r Oct 13, 2022
f8518c7
Merge branch 'sep/wing_import' of github.com:monadahq/winglang into s…
3p3r Oct 13, 2022
abdb66b
PR feedback addressed
3p3r Oct 13, 2022
96a0a04
fixed builds
3p3r Oct 13, 2022
3636cb8
Merge branch 'main' into sep/wing_import
3p3r Oct 20, 2022
a9b5e12
Merge branch 'main' into sep/wing_import
3p3r Oct 26, 2022
fe60b71
Merge branch 'main' into sep/wing_import
3p3r Oct 27, 2022
d0c5fdf
Merge branch 'main' into sep/wing_import
3p3r Oct 27, 2022
5c69e88
Merge branch 'main' into sep/wing_import
3p3r Oct 28, 2022
59991af
Merge branch 'main' into sep/wing_import
3p3r Oct 28, 2022
2d648e3
Merge branch 'main' into sep/wing_import
3p3r Oct 31, 2022
10023c5
Merge branch 'main' into sep/wing_import
3p3r Oct 31, 2022
085c4a1
fix lang server's build error with the new imports on parser instances
3p3r Oct 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/invalid/circular-bring.w
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bring "./circular/mod.w";
1 change: 1 addition & 0 deletions examples/invalid/circular/mod.w
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bring "../circular-bring.w";
2 changes: 2 additions & 0 deletions examples/simple/bring.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bring "./modules/mod1.w";
bring "./modules/mod2.w";
2 changes: 2 additions & 0 deletions examples/simple/modules/mod1.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let x = 1;
let y = 2;
4 changes: 4 additions & 0 deletions examples/simple/modules/mod2.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bring "./sub/mod.w";

let z = 3;
let q = 4;
1 change: 1 addition & 0 deletions examples/simple/modules/sub/mod.w
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let w = "what";
3p3r marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 14 additions & 5 deletions examples/simple/sdk_capture_test.w
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
bring cloud;

let bucket = new cloud.Bucket();
let p = cloud.BucketProps {
public: false
};

inflight handler() {
bucket.upload("file.txt", "data");
bucket.delete("file.txt");
let bucket = new cloud.Bucket(p);

inflight handler(event: str):str {
bucket.put("file.txt", "data");
bucket.get("file.txt");
}

new cloud.Function(handler);
new cloud.Function(
handler,
cloud.FunctionProps {
env: Map<str> {}
}
);
87 changes: 55 additions & 32 deletions libs/tree-sitter-wing/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ module.exports = grammar({
word: ($) => $.identifier,

precedences: ($) => [
[$.builtin_type, $.identifier],
[$.custom_type, $.nested_identifier, $.reference],
// Handle ambiguity in case of empty literal: `a = {}`
// In this case tree-sitter doesn't know if it's a set or a map literal so just assume its a map
[$.map_literal, $.set_literal],
[$.new_expression, $.function_call],
[$.nested_identifier, $.method_call, $.reference],
],

supertypes: ($) => [$.expression, $._literal],

conflicts: $ => [
[$.reference, $.custom_type],
],

rules: {
// Basics
source: ($) => repeat($._statement),
Expand All @@ -41,15 +43,16 @@ module.exports = grammar({

// Identifiers
reference: ($) =>
// prec.right(choice($.identifier, $.nested_identifier)),
choice($.identifier, $.nested_identifier),

identifier: ($) => /([A-Za-z_$][A-Za-z_$0-9]*|[A-Z][A-Z0-9_]*)/,

custom_type: ($) =>
prec.right(seq(
custom_type: ($) =>
seq(
field("object", $.identifier),
repeat(seq(".", field("fields", $.identifier)))
)),
),

nested_identifier: ($) =>
seq(
Expand Down Expand Up @@ -200,17 +203,18 @@ module.exports = grammar({
$.new_expression,
$._literal,
$.reference,
$.function_call,
$.method_call,
$.call,
$.preflight_closure,
$.inflight_closure,
$.pure_closure,
$.await_expression,
$._collection_literal,
$.parenthesized_expression,
$.structured_access_expression
$.structured_access_expression,
$.struct_literal,
),


// Primitives
_literal: ($) => choice($.string, $.number, $.bool, $.duration),

Expand Down Expand Up @@ -253,15 +257,9 @@ module.exports = grammar({
)
),

function_call: ($) =>
call: ($) =>
seq(field("call_name", $.reference), field("args", $.argument_list)),

method_call: ($) =>
seq(
field("call_name", $.nested_identifier),
field("args", $.argument_list)
),

argument_list: ($) =>
seq(
"(",
Expand Down Expand Up @@ -292,7 +290,7 @@ module.exports = grammar({
new_expression: ($) =>
seq(
"new",
field("class", choice($.custom_type, $.builtin_container_type)),
field("class", choice($.custom_type, $.mutable_container_type)),
field("args", $.argument_list),
field("id", optional($.new_object_id)),
field("scope", optional($.new_object_scope))
Expand All @@ -306,7 +304,7 @@ module.exports = grammar({
choice(
seq($.custom_type, optional("?")),
seq($.builtin_type, optional("?")),
seq($.builtin_container_type, optional("?")),
seq($._builtin_container_type, optional("?")),
$.function_type
),

Expand All @@ -315,7 +313,7 @@ module.exports = grammar({
seq(
optional(field("inflight", $._inflight_specifier)),
field("parameter_types", $.parameter_type_list),
optional(seq("->", field("return_type", $._type)))
optional(seq(":", field("return_type", $._type)))
)
),

Expand Down Expand Up @@ -347,6 +345,7 @@ module.exports = grammar({
optional("async"),
field("name", $.identifier),
field("parameter_list", $.parameter_list),
optional(field("return_type", $._type_annotation)),
field("block", $.block)
),

Expand All @@ -357,25 +356,39 @@ module.exports = grammar({

parameter_list: ($) => seq("(", commaSep($.parameter_definition), ")"),

builtin_container_type: ($) =>
immutable_container_type: ($) =>
seq(
field(
"collection_type",
choice(
"Array",
"Set",
"Map",
"Array",
"MutSet",
"MutMap",
"MutArray",
"Promise"
)
),
),
$._container_value_type
),

mutable_container_type: ($) =>
choice(
seq(
field(
"collection_type",
choice(
"MutSet",
"MutMap",
"MutArray",
"Promise"
)
),
$._container_value_type
),
"<",
field("type_parameter", $._type),
">"
),

_builtin_container_type: ($) => choice($.immutable_container_type, $.mutable_container_type),

_container_value_type: ($) => seq("<", field("type_parameter", $._type), ">"),

unary_expression: ($) =>
choice(
...[
Expand Down Expand Up @@ -439,11 +452,21 @@ module.exports = grammar({
_collection_literal: ($) =>
choice($.array_literal, $.set_literal, $.map_literal),
array_literal: ($) => seq("[", commaSep($.expression), "]"),
set_literal: ($) => seq("{", commaSep($.expression), "}"),
map_literal: ($) => seq("{", commaSep($.map_literal_member), "}"),
set_literal: ($) => seq(
optional(field("type", $.immutable_container_type)),
"{", commaSep($.expression), "}"
),
map_literal: ($) => seq(
optional(field("type", $.immutable_container_type)),
"{", commaSep($.map_literal_member), "}"
),
struct_literal: ($) => seq(field("type", $.custom_type), "{", field("fields", commaSep($.struct_literal_member)), "}"),

map_literal_member: ($) =>
// TODO: make sure $.string here conforms to valid keys in a map
seq(choice($.identifier, $.string), ":", $.expression),
struct_literal_member: ($) =>
seq($.identifier, ":", $.expression),
structured_access_expression: ($) =>
prec.right(seq($.expression, "[", $.expression, "]")),
},
Expand Down
Loading