Repository navigation
Support ReScript 13 control flow and spread syntax #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dfdc1e1
ca32c1d
3182a39
b15a6d1
10ca344
4f963f0
7250ba1
74b76f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ export default grammar({ | |
| $._dict_constructor, | ||
| $._decorator, | ||
| $._decorator_inline, | ||
| $._finally_clause_start, | ||
| ], | ||
|
|
||
| extras: ($) => [ | ||
|
|
@@ -66,7 +67,7 @@ export default grammar({ | |
| $.module_primary_expression, | ||
| ], | ||
|
|
||
| inline: ($) => [$._module_definition, $._semicolon], | ||
| inline: ($) => [$._module_definition, $._semicolon, $._record_pattern_field], | ||
|
|
||
| precedences: ($) => [ | ||
| // + - Operators -> precendence | ||
|
|
@@ -111,6 +112,8 @@ export default grammar({ | |
| ], | ||
|
|
||
| conflicts: ($) => [ | ||
| [$.primary_expression, $.record_rest_pattern], | ||
| [$.record_pattern], | ||
| [$.unit, $.formal_parameters], | ||
| [$.primary_expression, $._pattern], | ||
| [$.primary_expression, $.record_pattern], | ||
|
|
@@ -673,7 +676,7 @@ export default grammar({ | |
| seq( | ||
| alias($._dict_constructor, 'dict'), | ||
| '{', | ||
| commaSept($.dict_entry), | ||
| commaSept(choice($.dict_entry, $.spread_element)), | ||
| '}', | ||
| ), | ||
|
|
||
|
|
@@ -723,15 +726,28 @@ export default grammar({ | |
| seq($.variant_type_pattern, optional($.as_aliasing)), | ||
|
|
||
| try_expression: ($) => | ||
| prec.right( | ||
| seq( | ||
| 'try', | ||
| $.expression, | ||
| choice( | ||
| seq($._catch_clause, optional($.finally_clause)), | ||
| $.finally_clause, | ||
| ), | ||
| ), | ||
| ), | ||
|
|
||
| _catch_clause: ($) => | ||
| seq( | ||
| 'try', | ||
| $.expression, | ||
| 'catch', | ||
| '{', | ||
| repeat(seq($.switch_match, optional($._semicolon))), | ||
| '}', | ||
| ), | ||
|
|
||
| finally_clause: ($) => | ||
| seq($._finally_clause_start, alias($._identifier, 'finally'), $.block), | ||
|
|
||
| as_aliasing: ($) => | ||
| prec.left(seq('as', $._pattern, optional($.type_annotation))), | ||
|
|
||
|
|
@@ -933,16 +949,32 @@ export default grammar({ | |
| record_pattern: ($) => | ||
| seq( | ||
| '{', | ||
| commaSep1t( | ||
| choice( | ||
| commaSep1t($._record_pattern_field), | ||
| seq( | ||
| optional('?'), | ||
| choice($.value_identifier, $.value_identifier_path), | ||
| optional(seq(':', $._pattern)), | ||
| repeat(seq($._record_pattern_field, ',')), | ||
| $.record_rest_pattern, | ||
| repeat(seq(',', $._record_pattern_field)), | ||
| optional(','), | ||
| ), | ||
| ), | ||
| '}', | ||
| ), | ||
|
|
||
| _record_pattern_field: ($) => | ||
| seq( | ||
| optional('?'), | ||
| choice($.value_identifier, $.value_identifier_path), | ||
| optional(seq(':', $._pattern)), | ||
| ), | ||
|
|
||
| record_rest_pattern: ($) => | ||
| seq( | ||
| '...', | ||
| optional(seq($._non_function_inline_type, 'as')), | ||
| field('name', $.value_identifier), | ||
| ), | ||
|
|
||
| tuple_item_pattern: ($) => seq($._pattern, optional($.type_annotation)), | ||
|
|
||
| tuple_pattern: ($) => seq('(', commaSep2t($.tuple_item_pattern), ')'), | ||
|
|
@@ -1136,16 +1168,26 @@ export default grammar({ | |
| ), | ||
|
|
||
| for_expression: ($) => | ||
| seq( | ||
| 'for', | ||
| $.value_identifier, | ||
| 'in', | ||
| $.expression, | ||
| choice('to', 'downto'), | ||
| $.expression, | ||
| $.block, | ||
| choice( | ||
| seq( | ||
| 'for', | ||
| optional('await'), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For an existing numeric loop such as Useful? React with 👍 / 👎. |
||
| choice($._for_of_header, parenthesize($._for_of_header)), | ||
| $.block, | ||
| ), | ||
| seq( | ||
| 'for', | ||
| $.value_identifier, | ||
| 'in', | ||
| $.expression, | ||
| choice('to', 'downto'), | ||
| $.expression, | ||
| $.block, | ||
| ), | ||
| ), | ||
|
|
||
| _for_of_header: ($) => seq($.value_identifier, 'of', $.expression), | ||
|
|
||
| while_expression: ($) => seq('while', $.expression, $.block), | ||
|
|
||
| lazy_expression: ($) => seq('lazy', $.expression), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unitas an inferred record-rest bindingFor
let {a, ...unit} = value, the optional_non_function_inline_typeprefix makesunittokenize asunit_typeinstead of the non-reservedvalue_identifier. The parser then requiresasand rejects the closing}, so the new inferred-rest syntax fails for a binding name that works in ordinary record patterns and let bindings. Retain the identifier interpretation when there is no followingas.Useful? React with 👍 / 👎.