diff --git a/Makefile b/Makefile index bf88d8f..4f491b6 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,8 @@ wild_github_repos := rescript-lang/rescript-react \ rescript-association/rescript-lang.org \ tinymce/rescript-webapi \ cca-io/rescript-material-ui \ - rescript-association/reanalyze + rescript-association/reanalyze \ + TheSpyder/rescript-nodejs.git wild_sandboxes := $(patsubst %,test_wild/%,$(wild_github_repos)) diff --git a/grammar.js b/grammar.js index ea7bcb1..17f6be2 100644 --- a/grammar.js +++ b/grammar.js @@ -106,7 +106,8 @@ module.exports = grammar({ [$.variant_declaration], [$.unit, $._function_type_parameter_list], [$.functor_parameter, $.module_primary_expression, $.module_identifier_path], - [$._reserved_identifier, $.function] + [$._reserved_identifier, $.function], + [$.polyvar_type] ], rules: { @@ -364,6 +365,7 @@ module.exports = grammar({ ), polyvar_type: $ => prec.left(seq( + repeat($.decorator), choice('[', '[>', '[<',), optional('|'), barSep1($.polyvar_declaration), @@ -374,7 +376,7 @@ module.exports = grammar({ polyvar_declaration: $ => prec.right( choice( seq( - optional($.decorator), + repeat($.decorator), $.polyvar_identifier, optional($.polyvar_parameters), ), @@ -629,19 +631,27 @@ module.exports = grammar({ tuple: $ => seq( '(', - commaSep2t($.expression), + commaSep2t( + seq(repeat($.decorator), $.expression) + ), ')', ), array: $ => seq( '[', - commaSept($.expression), + commaSept( + seq(repeat($.decorator), $.expression) + ), ']' ), list: $ => seq( 'list{', - optional(commaSep1t($._list_element)), + optional( + commaSep1t( + seq(repeat($.decorator), $._list_element) + ) + ), '}' ), @@ -799,6 +809,7 @@ module.exports = grammar({ seq( '=', optional('?'), + repeat($.decorator), field('value', $.expression), optional(field('type', $.type_annotation)), ), @@ -931,19 +942,28 @@ module.exports = grammar({ tuple_pattern: $ => seq( '(', - commaSep2t(alias($._pattern, $.tuple_item_pattern)), + commaSep2t( + alias( + seq(repeat($.decorator), $._pattern), + $.tuple_item_pattern + ) + ), ')', ), array_pattern: $ => seq( '[', - optional(commaSep1t($._collection_element_pattern)), + optional(commaSep1t( + seq(repeat($.decorator), $._collection_element_pattern) + )), ']', ), list_pattern: $ => seq( 'list{', - optional(commaSep1t($._collection_element_pattern)), + optional(commaSep1t( + seq(repeat($.decorator), $._collection_element_pattern) + )), '}', ), diff --git a/test/corpus/expressions.txt b/test/corpus/expressions.txt index ac62c6f..9ff0818 100644 --- a/test/corpus/expressions.txt +++ b/test/corpus/expressions.txt @@ -101,6 +101,7 @@ blocky( ~third={3}, ) f(raise) +call(~a=@decorator 1) --- @@ -172,7 +173,16 @@ f(raise) (call_expression function: (value_identifier) arguments: (arguments - (value_identifier))))) + (value_identifier)))) + + (expression_statement + (call_expression + function: (value_identifier) + arguments: (arguments + (labeled_argument + label: (value_identifier) + (decorator (decorator_identifier)) + value: (number)))))) =========================================== Pipe diff --git a/test/corpus/let_bindings.txt b/test/corpus/let_bindings.txt index cc15c77..9dc9627 100644 --- a/test/corpus/let_bindings.txt +++ b/test/corpus/let_bindings.txt @@ -88,6 +88,7 @@ Array destructuring let [bar, baz] = foo let [bar, baz, _] = foo +let [@decorator bar, _] = foo --- @@ -103,6 +104,13 @@ let [bar, baz, _] = foo (value_identifier) (value_identifier) (value_identifier)) + (value_identifier)) + + (let_binding + (array_pattern + (decorator (decorator_identifier)) + (value_identifier) + (value_identifier)) (value_identifier))) ============================================ @@ -110,6 +118,7 @@ List destructuring ============================================ let list{head, ...tail} = foo +let list{@decorator head, ..._} = foo --- @@ -118,6 +127,13 @@ let list{head, ...tail} = foo (list_pattern (value_identifier) (spread_pattern (value_identifier))) + (value_identifier)) + + (let_binding + (list_pattern + (decorator (decorator_identifier)) + (value_identifier) + (spread_pattern (value_identifier))) (value_identifier))) diff --git a/test/corpus/type_declarations.txt b/test/corpus/type_declarations.txt index 50470f0..12265ad 100644 --- a/test/corpus/type_declarations.txt +++ b/test/corpus/type_declarations.txt @@ -227,7 +227,7 @@ type t = [> ] -type foo<'a> = [> #Blue | #DeepBlue | #LightBlue ] as 'a +type foo<'a> = @decorator [> #Blue | #DeepBlue | #LightBlue ] as 'a type t<'w> = [M.t<'w>] --- @@ -250,6 +250,7 @@ type t<'w> = [M.t<'w>] (type_identifier) (type_parameters (type_identifier)) (polyvar_type + (decorator (decorator_identifier)) (polyvar_declaration (polyvar_identifier)) (polyvar_declaration (polyvar_identifier)) (polyvar_declaration (polyvar_identifier))