Skip to content

Commit 389c409

Browse files
committed
Merge branch 'main' into refactor-list-constructor
2 parents a18eda7 + 65b4288 commit 389c409

File tree

7 files changed

+106
-23
lines changed

7 files changed

+106
-23
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: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ module.exports = grammar({
107107
[$.variant_declaration],
108108
[$.unit, $._function_type_parameter_list],
109109
[$.functor_parameter, $.module_primary_expression, $.module_identifier_path],
110-
[$._reserved_identifier, $.function]
110+
[$._reserved_identifier, $.function],
111+
[$.polyvar_type]
111112
],
112113

113114
rules: {
@@ -260,20 +261,22 @@ module.exports = grammar({
260261
optional('export'),
261262
'type',
262263
optional('rec'),
263-
$._type_declaration,
264+
$._type_declaration
264265
),
265266

266267
_type_declaration: $ => seq(
267268
choice($.type_identifier, $.type_identifier_path),
268269
optional($.type_parameters),
269270
optional(seq(
270-
choice('=', '+='),
271-
optional('private'),
272-
$._type,
273-
repeat($.type_constraint),
274271
optional(seq('=', $._type)),
275-
optional(alias($._type_declaration_and, $.type_declaration)),
272+
optional(seq(
273+
choice('=', '+='),
274+
optional('private'),
275+
$._type,
276+
)),
277+
repeat($.type_constraint),
276278
)),
279+
optional(alias($._type_declaration_and, $.type_declaration))
277280
),
278281

279282
_type_declaration_and: $ => seq(
@@ -363,6 +366,7 @@ module.exports = grammar({
363366
),
364367

365368
polyvar_type: $ => prec.left(seq(
369+
repeat($.decorator),
366370
choice('[', '[>', '[<',),
367371
optional('|'),
368372
barSep1($.polyvar_declaration),
@@ -373,7 +377,7 @@ module.exports = grammar({
373377
polyvar_declaration: $ => prec.right(
374378
choice(
375379
seq(
376-
optional($.decorator),
380+
repeat($.decorator),
377381
$.polyvar_identifier,
378382
optional($.polyvar_parameters),
379383
),
@@ -425,10 +429,11 @@ module.exports = grammar({
425429

426430
),
427431

428-
generic_type: $ => seq(
432+
generic_type: $ => prec.left(seq(
429433
$._type_identifier,
430-
$.type_arguments
431-
),
434+
$.type_arguments,
435+
optional($.as_aliasing_type)
436+
)),
432437

433438
type_arguments: $ => seq(
434439
'<',
@@ -627,20 +632,28 @@ module.exports = grammar({
627632

628633
tuple: $ => seq(
629634
'(',
630-
commaSep2t($.expression),
635+
commaSep2t(
636+
seq(repeat($.decorator), $.expression)
637+
),
631638
')',
632639
),
633640

634641
array: $ => seq(
635642
'[',
636-
commaSept($.expression),
643+
commaSept(
644+
seq(repeat($.decorator), $.expression)
645+
),
637646
']'
638647
),
639648

640649
list: $ => seq(
641650
$._list_constructor,
642651
'{',
643-
optional(commaSep1t($._list_element)),
652+
optional(
653+
commaSep1t(
654+
seq(repeat($.decorator), $._list_element)
655+
)
656+
),
644657
'}'
645658
),
646659

@@ -798,6 +811,7 @@ module.exports = grammar({
798811
seq(
799812
'=',
800813
optional('?'),
814+
repeat($.decorator),
801815
field('value', $.expression),
802816
optional(field('type', $.type_annotation)),
803817
),
@@ -930,20 +944,29 @@ module.exports = grammar({
930944

931945
tuple_pattern: $ => seq(
932946
'(',
933-
commaSep2t(alias($._pattern, $.tuple_item_pattern)),
947+
commaSep2t(
948+
alias(
949+
seq(repeat($.decorator), $._pattern),
950+
$.tuple_item_pattern
951+
)
952+
),
934953
')',
935954
),
936955

937956
array_pattern: $ => seq(
938957
'[',
939-
optional(commaSep1t($._collection_element_pattern)),
958+
optional(commaSep1t(
959+
seq(repeat($.decorator), $._collection_element_pattern)
960+
)),
940961
']',
941962
),
942963

943964
list_pattern: $ => seq(
944965
$._list_constructor,
945966
'{',
946-
optional(commaSep1t($._collection_element_pattern)),
967+
optional(commaSep1t(
968+
seq(repeat($.decorator), $._collection_element_pattern)
969+
)),
947970
'}',
948971
),
949972

queries/highlights.scm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
; single parameter with no parens
7272
(function parameter: (value_identifier) @parameter)
7373

74+
; first-level descructuring (required for nvim-tree-sitter as it only matches direct
75+
; children and the above patterns do not match destructuring patterns in NeoVim)
76+
(parameter (tuple_pattern (tuple_item_pattern (value_identifier) @parameter)))
77+
(parameter (array_pattern (value_identifier) @parameter))
78+
(parameter (record_pattern (value_identifier) @parameter))
79+
7480
; Meta
7581
;-----
7682

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: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ Opaque
55
type t
66
type t'
77
type \"type"
8+
type t and b
89

910
---
1011

1112
(source_file
1213
(type_declaration (type_identifier))
1314
(type_declaration (type_identifier))
14-
(type_declaration (type_identifier)))
15+
(type_declaration (type_identifier))
16+
(type_declaration (type_identifier)
17+
(type_declaration (type_identifier))))
1518

1619
===========================================
1720
Export
@@ -224,7 +227,7 @@ type t = [>
224227
]
225228

226229

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

230233
---
@@ -247,6 +250,7 @@ type t<'w> = [M.t<'w>]
247250
(type_identifier)
248251
(type_parameters (type_identifier))
249252
(polyvar_type
253+
(decorator (decorator_identifier))
250254
(polyvar_declaration (polyvar_identifier))
251255
(polyvar_declaration (polyvar_identifier))
252256
(polyvar_declaration (polyvar_identifier))
@@ -349,6 +353,7 @@ Generic
349353

350354
type t<'a, 'b> = (array<'a>, array<'b>)
351355
type t = result<(), string>
356+
type t<'a> = generic<'a> as 's
352357

353358
---
354359

@@ -365,7 +370,15 @@ type t = result<(), string>
365370
(type_identifier)
366371
(type_arguments
367372
(unit)
368-
(type_identifier)))))
373+
(type_identifier))))
374+
375+
(type_declaration
376+
(type_identifier)
377+
(type_parameters (type_identifier))
378+
(generic_type
379+
(type_identifier)
380+
(type_arguments (type_identifier))
381+
(as_aliasing_type (type_identifier)))))
369382

370383
===========================================
371384
Recursive
@@ -530,6 +543,7 @@ Type constraint
530543

531544
type t<'a> = 'a constraint 'a = int
532545
type decorator<'a, 'b> = 'a => 'b constraint 'a = int constraint 'b = _ => _
546+
type t<'a> constraint 'a = t
533547

534548
---
535549

@@ -553,4 +567,11 @@ type decorator<'a, 'b> = 'a => 'b constraint 'a = int constraint 'b = _ => _
553567
(type_identifier)
554568
(function_type
555569
(function_type_parameters (type_identifier))
556-
(type_identifier)))))
570+
(type_identifier))))
571+
572+
(type_declaration
573+
(type_identifier)
574+
(type_parameters (type_identifier))
575+
(type_constraint
576+
(type_identifier)
577+
(type_identifier))))

test/highlight/functions.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ let inc = n => n + 1
22
// ^ parameter
33
// ^ punctuation.special
44

5+
let fn = (a, (b, c), {d, e}, [f, g]) => a + b + c + d + e + f + g
6+
// ^ parameter
7+
// ^ parameter
8+
// ^ parameter
9+
// ^ parameter
10+
511
let uncurry = (. u, .x) => (u, x)
612
// ^ operator
713
// ^ operator

0 commit comments

Comments
 (0)