Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
36 changes: 28 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -364,6 +365,7 @@ module.exports = grammar({
),

polyvar_type: $ => prec.left(seq(
repeat($.decorator),
choice('[', '[>', '[<',),
optional('|'),
barSep1($.polyvar_declaration),
Expand All @@ -374,7 +376,7 @@ module.exports = grammar({
polyvar_declaration: $ => prec.right(
choice(
seq(
optional($.decorator),
repeat($.decorator),
$.polyvar_identifier,
optional($.polyvar_parameters),
),
Expand Down Expand Up @@ -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)
)
),
'}'
),

Expand Down Expand Up @@ -799,6 +809,7 @@ module.exports = grammar({
seq(
'=',
optional('?'),
repeat($.decorator),
field('value', $.expression),
optional(field('type', $.type_annotation)),
),
Expand Down Expand Up @@ -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)
)),
'}',
),

Expand Down
12 changes: 11 additions & 1 deletion test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ blocky(
~third={3},
)
f(raise)
call(~a=@decorator 1)

---

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/corpus/let_bindings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Array destructuring

let [bar, baz] = foo
let [bar, baz, _] = foo
let [@decorator bar, _] = foo

---

Expand All @@ -103,13 +104,21 @@ 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)))

============================================
List destructuring
============================================

let list{head, ...tail} = foo
let list{@decorator head, ..._} = foo

---

Expand All @@ -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)))


Expand Down
3 changes: 2 additions & 1 deletion test/corpus/type_declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>]

---
Expand All @@ -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))
Expand Down