Skip to content

Commit 65b4288

Browse files
authored
Merge pull request #191 from aspeddro/decorated-take-3
Support decorators (take 3)
2 parents d24fbeb + 1d80be6 commit 65b4288

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ wild_github_repos := rescript-lang/rescript-react \
99
rescript-association/rescript-lang.org \
1010
tinymce/rescript-webapi \
1111
cca-io/rescript-material-ui \
12-
rescript-association/reanalyze
12+
rescript-association/reanalyze \
13+
TheSpyder/rescript-nodejs.git
1314

1415
wild_sandboxes := $(patsubst %,test_wild/%,$(wild_github_repos))
1516

grammar.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ module.exports = grammar({
106106
[$.variant_declaration],
107107
[$.unit, $._function_type_parameter_list],
108108
[$.functor_parameter, $.module_primary_expression, $.module_identifier_path],
109-
[$._reserved_identifier, $.function]
109+
[$._reserved_identifier, $.function],
110+
[$.polyvar_type]
110111
],
111112

112113
rules: {
@@ -364,6 +365,7 @@ module.exports = grammar({
364365
),
365366

366367
polyvar_type: $ => prec.left(seq(
368+
repeat($.decorator),
367369
choice('[', '[>', '[<',),
368370
optional('|'),
369371
barSep1($.polyvar_declaration),
@@ -374,7 +376,7 @@ module.exports = grammar({
374376
polyvar_declaration: $ => prec.right(
375377
choice(
376378
seq(
377-
optional($.decorator),
379+
repeat($.decorator),
378380
$.polyvar_identifier,
379381
optional($.polyvar_parameters),
380382
),
@@ -629,19 +631,27 @@ module.exports = grammar({
629631

630632
tuple: $ => seq(
631633
'(',
632-
commaSep2t($.expression),
634+
commaSep2t(
635+
seq(repeat($.decorator), $.expression)
636+
),
633637
')',
634638
),
635639

636640
array: $ => seq(
637641
'[',
638-
commaSept($.expression),
642+
commaSept(
643+
seq(repeat($.decorator), $.expression)
644+
),
639645
']'
640646
),
641647

642648
list: $ => seq(
643649
'list{',
644-
optional(commaSep1t($._list_element)),
650+
optional(
651+
commaSep1t(
652+
seq(repeat($.decorator), $._list_element)
653+
)
654+
),
645655
'}'
646656
),
647657

@@ -799,6 +809,7 @@ module.exports = grammar({
799809
seq(
800810
'=',
801811
optional('?'),
812+
repeat($.decorator),
802813
field('value', $.expression),
803814
optional(field('type', $.type_annotation)),
804815
),
@@ -931,19 +942,28 @@ module.exports = grammar({
931942

932943
tuple_pattern: $ => seq(
933944
'(',
934-
commaSep2t(alias($._pattern, $.tuple_item_pattern)),
945+
commaSep2t(
946+
alias(
947+
seq(repeat($.decorator), $._pattern),
948+
$.tuple_item_pattern
949+
)
950+
),
935951
')',
936952
),
937953

938954
array_pattern: $ => seq(
939955
'[',
940-
optional(commaSep1t($._collection_element_pattern)),
956+
optional(commaSep1t(
957+
seq(repeat($.decorator), $._collection_element_pattern)
958+
)),
941959
']',
942960
),
943961

944962
list_pattern: $ => seq(
945963
'list{',
946-
optional(commaSep1t($._collection_element_pattern)),
964+
optional(commaSep1t(
965+
seq(repeat($.decorator), $._collection_element_pattern)
966+
)),
947967
'}',
948968
),
949969

test/corpus/expressions.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ blocky(
101101
~third={3},
102102
)
103103
f(raise)
104+
call(~a=@decorator 1)
104105

105106
---
106107

@@ -172,7 +173,16 @@ f(raise)
172173
(call_expression
173174
function: (value_identifier)
174175
arguments: (arguments
175-
(value_identifier)))))
176+
(value_identifier))))
177+
178+
(expression_statement
179+
(call_expression
180+
function: (value_identifier)
181+
arguments: (arguments
182+
(labeled_argument
183+
label: (value_identifier)
184+
(decorator (decorator_identifier))
185+
value: (number))))))
176186

177187
===========================================
178188
Pipe

test/corpus/let_bindings.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Array destructuring
8888

8989
let [bar, baz] = foo
9090
let [bar, baz, _] = foo
91+
let [@decorator bar, _] = foo
9192

9293
---
9394

@@ -103,13 +104,21 @@ let [bar, baz, _] = foo
103104
(value_identifier)
104105
(value_identifier)
105106
(value_identifier))
107+
(value_identifier))
108+
109+
(let_binding
110+
(array_pattern
111+
(decorator (decorator_identifier))
112+
(value_identifier)
113+
(value_identifier))
106114
(value_identifier)))
107115

108116
============================================
109117
List destructuring
110118
============================================
111119

112120
let list{head, ...tail} = foo
121+
let list{@decorator head, ..._} = foo
113122

114123
---
115124

@@ -118,6 +127,13 @@ let list{head, ...tail} = foo
118127
(list_pattern
119128
(value_identifier)
120129
(spread_pattern (value_identifier)))
130+
(value_identifier))
131+
132+
(let_binding
133+
(list_pattern
134+
(decorator (decorator_identifier))
135+
(value_identifier)
136+
(spread_pattern (value_identifier)))
121137
(value_identifier)))
122138

123139

test/corpus/type_declarations.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ type t = [>
227227
]
228228

229229

230-
type foo<'a> = [> #Blue | #DeepBlue | #LightBlue ] as 'a
230+
type foo<'a> = @decorator [> #Blue | #DeepBlue | #LightBlue ] as 'a
231231
type t<'w> = [M.t<'w>]
232232

233233
---
@@ -250,6 +250,7 @@ type t<'w> = [M.t<'w>]
250250
(type_identifier)
251251
(type_parameters (type_identifier))
252252
(polyvar_type
253+
(decorator (decorator_identifier))
253254
(polyvar_declaration (polyvar_identifier))
254255
(polyvar_declaration (polyvar_identifier))
255256
(polyvar_declaration (polyvar_identifier))

0 commit comments

Comments
 (0)