Skip to content

Commit c9aacd0

Browse files
committed
Merge branch 'main' into fix-fcm
2 parents e174d23 + 0ad57c4 commit c9aacd0

File tree

5 files changed

+137
-27
lines changed

5 files changed

+137
-27
lines changed

grammar.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module.exports = grammar({
7171
[$.record_field, $.record_pattern],
7272
[$.expression_statement, $.ternary_expression],
7373
[$._type_declaration],
74+
[$._let_binding],
7475
[$.let_binding, $.ternary_expression],
7576
[$.variant_identifier, $.module_identifier],
7677
[$.variant],
@@ -91,7 +92,8 @@ module.exports = grammar({
9192
[$.parameter, $._pattern],
9293
[$.parameter, $._parenthesized_pattern],
9394
[$._switch_value_pattern, $._parenthesized_pattern],
94-
[$.variant_declaration]
95+
[$.variant_declaration],
96+
[$.unit, $._function_type_parameter_list]
9597
],
9698

9799
rules: {
@@ -245,16 +247,27 @@ module.exports = grammar({
245247
choice('=', '+='),
246248
optional('private'),
247249
$._type,
248-
optional(seq(
249-
'and',
250-
$._type_declaration
251-
)),
250+
repeat(alias($._type_declaration_and, $.type_declaration)),
252251
)),
253252
),
254253

254+
_type_declaration_and: $ => seq(
255+
// New line here not necessary terminates the statement,
256+
// show this doubt to the parser
257+
repeat($._newline),
258+
repeat($.decorator),
259+
'and',
260+
$._type_declaration
261+
),
262+
255263
type_parameters: $ => seq(
256264
'<',
257-
commaSep1t($.type_identifier),
265+
commaSep1t(
266+
seq(
267+
optional(choice('+', '-')),
268+
$.type_identifier
269+
)
270+
),
258271
'>',
259272
),
260273

@@ -283,6 +296,7 @@ module.exports = grammar({
283296
$.generic_type,
284297
$.unit_type,
285298
$.module_pack,
299+
$.unit,
286300
),
287301

288302
tuple_type: $ => prec.dynamic(-1, seq(
@@ -422,13 +436,19 @@ module.exports = grammar({
422436
'=',
423437
repeat($.decorator),
424438
$.expression,
425-
optional(seq(
426-
'and',
427-
$._let_binding,
428-
)),
439+
repeat(alias($._let_binding_and, $.let_binding)),
429440
)),
430441
),
431442

443+
_let_binding_and: $ => seq(
444+
// New line here not necessary terminates the statement,
445+
// show this doubt to the parser
446+
repeat($._newline),
447+
repeat($.decorator),
448+
'and',
449+
$._let_binding,
450+
),
451+
432452
_binding_pattern: $ => choice(
433453
$.value_identifier,
434454
$.tuple_pattern,

queries/highlights.scm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@
6868
; Functions
6969
;----------
7070

71+
; parameter(s) in parens
7172
[
72-
(formal_parameters (value_identifier))
73+
(parameter (value_identifier))
7374
(labeled_parameter (value_identifier))
7475
] @parameter
7576

77+
; single parameter with no parens
7678
(function parameter: (value_identifier) @parameter)
7779

7880
; Meta

test/corpus/decorators.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,34 @@ let onResult = () => @doesNotRaise Belt.Array.getExn([], 0)
7777
(array)
7878
(number))))))
7979

80+
============================================
81+
Decorator before type `and`
82+
============================================
83+
84+
@deriving
85+
type foo = {
86+
foo: string
87+
}
88+
@deriving
89+
and bar = {bar: int}
90+
91+
92+
@deriving @hello and baz = {baz: float}
93+
94+
---
95+
96+
(source_file
97+
(decorated
98+
(decorator (decorator_identifier))
99+
(type_declaration
100+
(type_identifier)
101+
(record_type (record_type_field (property_identifier) (type_annotation (type_identifier))))
102+
(type_declaration
103+
(decorator (decorator_identifier))
104+
(type_identifier)
105+
(record_type (record_type_field (property_identifier) (type_annotation (type_identifier)))))
106+
(type_declaration
107+
(decorator (decorator_identifier))
108+
(decorator (decorator_identifier))
109+
(type_identifier)
110+
(record_type (record_type_field (property_identifier) (type_annotation (type_identifier))))))))

test/corpus/let_bindings.txt

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,12 @@ let a = 5 and b = 4
202202
(let_binding
203203
(value_identifier)
204204
(number)
205-
(value_identifier)
206-
(number)))
205+
(let_binding
206+
(value_identifier)
207+
(number))))
207208

208209
============================================
209-
And (Fuctions)
210+
And (Functions)
210211
============================================
211212

212213
let rec a = x => x + b(x) and b = y => y - 1
@@ -224,10 +225,40 @@ let rec a = x => x + b(x) and b = y => y - 1
224225
(value_identifier)
225226
(arguments
226227
(value_identifier)))))
227-
(value_identifier)
228-
(function
228+
(let_binding
229229
(value_identifier)
230-
(binary_expression
230+
(function
231+
(value_identifier)
232+
(binary_expression
233+
(value_identifier)
234+
(number))))))
235+
236+
============================================
237+
And (decorated)
238+
============================================
239+
240+
@one
241+
let rec a = b
242+
@two @three
243+
and b = c
244+
245+
@four and c = 42
246+
247+
---
248+
249+
(source_file
250+
(decorated
251+
(decorator (decorator_identifier))
252+
(let_binding
253+
(value_identifier)
254+
(value_identifier)
255+
(let_binding
256+
(decorator (decorator_identifier))
257+
(decorator (decorator_identifier))
258+
(value_identifier)
259+
(value_identifier))
260+
(let_binding
261+
(decorator (decorator_identifier))
231262
(value_identifier)
232263
(number)))))
233264

test/corpus/type_declarations.txt

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ Generic
313313
===========================================
314314

315315
type t<'a, 'b> = (array<'a>, array<'b>)
316+
type t = result<(), string>
316317

317318
---
318319

@@ -322,7 +323,14 @@ type t<'a, 'b> = (array<'a>, array<'b>)
322323
(type_parameters (type_identifier) (type_identifier))
323324
(tuple_type
324325
(generic_type (type_identifier) (type_arguments (type_identifier)))
325-
(generic_type (type_identifier) (type_arguments (type_identifier))))))
326+
(generic_type (type_identifier) (type_arguments (type_identifier)))))
327+
(type_declaration
328+
(type_identifier)
329+
(generic_type
330+
(type_identifier)
331+
(type_arguments
332+
(unit)
333+
(type_identifier)))))
326334

327335
===========================================
328336
Recursive
@@ -391,15 +399,16 @@ and teacher = {
391399
(property_identifier)
392400
(type_annotation
393401
(type_identifier))))
394-
(type_identifier)
395-
(record_type
396-
(record_type_field
397-
(property_identifier)
398-
(type_annotation
399-
(generic_type
400-
(type_identifier)
401-
(type_arguments
402-
(type_identifier))))))))
402+
(type_declaration
403+
(type_identifier)
404+
(record_type
405+
(record_type_field
406+
(property_identifier)
407+
(type_annotation
408+
(generic_type
409+
(type_identifier)
410+
(type_arguments
411+
(type_identifier)))))))))
403412

404413

405414
===========================================
@@ -422,3 +431,20 @@ type test = (. ~attr: string) => unit
422431
(type_annotation
423432
(type_identifier)))))
424433
(unit_type))))
434+
435+
===========================================
436+
Variance annotations
437+
===========================================
438+
439+
type t<+'a>
440+
type t<-'a>
441+
442+
---
443+
444+
(source_file
445+
(type_declaration
446+
(type_identifier)
447+
(type_parameters (type_identifier)))
448+
(type_declaration
449+
(type_identifier)
450+
(type_parameters (type_identifier))))

0 commit comments

Comments
 (0)