@hew-lang/tree-sitter-hew 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/grammar.js +181 -86
- package/package.json +1 -1
- package/queries/folds.scm +2 -0
- package/queries/highlights.scm +15 -3
- package/queries/indents.scm +3 -0
- package/src/grammar.json +1296 -409
- package/src/node-types.json +594 -67
- package/src/parser.c +159962 -106357
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
[Tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for the [Hew](https://hew.sh) programming language.
|
|
4
4
|
|
|
5
|
+
The grammar includes Hew v0.6.1 generic closures and callable types:
|
|
6
|
+
`|<T: Eq> left: T, right: T| -> bool { left == right }` and
|
|
7
|
+
`fn<T: Eq>(T, T) -> bool`. Use the
|
|
8
|
+
[released SDK](https://github.com/hew-lang/hew/releases/tag/v0.6.1) for type
|
|
9
|
+
checking and execution; an editor parse is not a compiler acceptance check.
|
|
10
|
+
|
|
5
11
|
## Usage
|
|
6
12
|
|
|
7
13
|
### Neovim (nvim-treesitter)
|
package/grammar.js
CHANGED
|
@@ -22,9 +22,11 @@ const PREC = {
|
|
|
22
22
|
SHIFT: 12, // << >>
|
|
23
23
|
ADD: 13, // + - &+ &-
|
|
24
24
|
MUL: 15, // * / % &*
|
|
25
|
-
UNARY: 17, // ! - ~
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
UNARY: 17, // ! - ~ clone
|
|
26
|
+
TRY: 18, // ?
|
|
27
|
+
TASK: 19, // await fork
|
|
28
|
+
POSTFIX: 20, // . () []
|
|
29
|
+
FIELD: 20, // field access (same left-associative postfix tier)
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
export default grammar({
|
|
@@ -38,19 +40,19 @@ export default grammar({
|
|
|
38
40
|
inline: $ => [$._binary_operand],
|
|
39
41
|
|
|
40
42
|
conflicts: $ => [
|
|
41
|
-
[$._block_arm_value, $.
|
|
43
|
+
[$._block_arm_value, $._callable_expression],
|
|
42
44
|
[$._block_arm_value, $.fork_expression],
|
|
43
|
-
[$.if_statement, $.
|
|
44
|
-
[$.match_statement, $.
|
|
45
|
-
[$.block_like_statement, $.
|
|
45
|
+
[$.if_statement, $._callable_expression],
|
|
46
|
+
[$.match_statement, $._callable_expression],
|
|
47
|
+
[$.block_like_statement, $._callable_expression],
|
|
46
48
|
[$.block_like_statement, $.fork_expression],
|
|
47
|
-
[$.
|
|
49
|
+
[$._callable_expression, $.struct_init],
|
|
48
50
|
[$.block, $.map_literal],
|
|
49
|
-
[$.
|
|
50
|
-
[$.
|
|
51
|
+
[$._callable_expression, $._member_object, $.path_expression],
|
|
52
|
+
[$._callable_expression, $._member_object],
|
|
51
53
|
[$.qualified_expression, $.field_expression],
|
|
52
54
|
[$.generic_apply_expression, $.bare_generic_call_expression],
|
|
53
|
-
[$.
|
|
55
|
+
[$._callable_expression, $.private_capture_list],
|
|
54
56
|
[$.actor_spawn],
|
|
55
57
|
[$.trait_bound],
|
|
56
58
|
// `-> fn() fails E` — the short `fails E` may belong to the inner callable
|
|
@@ -63,7 +65,7 @@ export default grammar({
|
|
|
63
65
|
[$.where_clause],
|
|
64
66
|
// `return error` — a failure return or a binding named `error`; the next
|
|
65
67
|
// token decides, and a payload that fits both reads as the failure return.
|
|
66
|
-
[$.return_error_expression, $.
|
|
68
|
+
[$.return_error_expression, $._callable_expression],
|
|
67
69
|
// `import a.b.c` — at each `.` the parser cannot tell (within LR(1))
|
|
68
70
|
// whether another path segment or the import selection follows; GLR explores
|
|
69
71
|
// both and only the valid continuation survives.
|
|
@@ -103,24 +105,69 @@ export default grammar({
|
|
|
103
105
|
$.supervisor_declaration,
|
|
104
106
|
$.machine_declaration,
|
|
105
107
|
$.type_alias,
|
|
108
|
+
$.macro_declaration,
|
|
109
|
+
$.macro_invocation,
|
|
106
110
|
),
|
|
107
111
|
),
|
|
108
112
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
attribute: $ => seq(
|
|
114
|
+
'#', '[', field('name', $.identifier),
|
|
115
|
+
repeat(seq('.', field('name', $.identifier))),
|
|
116
|
+
optional(seq('(', repeat($._macro_token), ')')), ']',
|
|
117
|
+
),
|
|
114
118
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
macro_declaration: $ => seq(
|
|
120
|
+
'macro', field('name', $.identifier), '{', repeat1($.macro_rule), '}',
|
|
121
|
+
),
|
|
122
|
+
|
|
123
|
+
macro_rule: $ => seq(
|
|
124
|
+
choice(
|
|
125
|
+
field('pattern', $.macro_pattern),
|
|
126
|
+
seq('#', '[', field('pattern', $.macro_pattern), ']', $.macro_function_capture),
|
|
127
|
+
),
|
|
128
|
+
'=>', field('category', choice('expr', 'items')),
|
|
129
|
+
field('template', $.macro_template),
|
|
130
|
+
),
|
|
131
|
+
|
|
132
|
+
macro_pattern: $ => seq('(', repeat($._macro_token), ')'),
|
|
133
|
+
macro_template: $ => seq('{', repeat($._macro_token), '}'),
|
|
134
|
+
|
|
135
|
+
macro_function_capture: $ => seq(
|
|
136
|
+
$.macro_variable, ':', choice('fn', 'method'), optional('fails'),
|
|
122
137
|
),
|
|
123
138
|
|
|
139
|
+
macro_variable: $ => prec(1, seq('$', $.identifier)),
|
|
140
|
+
|
|
141
|
+
token_tree: $ => choice(
|
|
142
|
+
seq('(', repeat($._macro_token), ')'),
|
|
143
|
+
seq('[', repeat($._macro_token), ']'),
|
|
144
|
+
seq('{', repeat($._macro_token), '}'),
|
|
145
|
+
),
|
|
146
|
+
|
|
147
|
+
// Expansion owns fragment and repetition checks; these remain balanced tokens.
|
|
148
|
+
_macro_token: $ => choice(
|
|
149
|
+
$.token_tree, $.macro_variable, $.identifier, $._literal,
|
|
150
|
+
alias($.macro_interpolated_string, $.interpolated_string),
|
|
151
|
+
',', ';', ':', '.', '@', '#', '$',
|
|
152
|
+
'+', '-', '*', '/', '%', '!', '~', '&', '|', '^',
|
|
153
|
+
'=', '<', '>', '?', '??', '?.', '=>', '->', '..', '..=',
|
|
154
|
+
'==', '!=', '<=', '>=', '&&', '||', '<<', '>>',
|
|
155
|
+
'+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '<<=', '>>=',
|
|
156
|
+
'&+', '&-', '&*',
|
|
157
|
+
),
|
|
158
|
+
|
|
159
|
+
macro_interpolated_string: $ => seq(
|
|
160
|
+
$.fstring_start,
|
|
161
|
+
repeat(choice(
|
|
162
|
+
alias($.interpolated_string_content, $.string_content),
|
|
163
|
+
$.escape_sequence,
|
|
164
|
+
alias($.macro_interpolation, $.interpolation),
|
|
165
|
+
)),
|
|
166
|
+
'"',
|
|
167
|
+
),
|
|
168
|
+
|
|
169
|
+
macro_interpolation: $ => seq(token.immediate('{'), repeat($._macro_token), '}'),
|
|
170
|
+
|
|
124
171
|
// Import (hew-parser: import item):
|
|
125
172
|
// Import = "import" ( StringLit | ModulePath ( "." ImportSelection )? ) ";"
|
|
126
173
|
// ModulePath = Ident { "." Ident }
|
|
@@ -293,6 +340,7 @@ export default grammar({
|
|
|
293
340
|
|
|
294
341
|
trait_function_signature: $ => seq(
|
|
295
342
|
'fn',
|
|
343
|
+
optional($.trait_method_effect),
|
|
296
344
|
field('name', $.identifier),
|
|
297
345
|
optional($.type_parameters),
|
|
298
346
|
'(',
|
|
@@ -303,6 +351,8 @@ export default grammar({
|
|
|
303
351
|
choice(';', field('body', $.block)),
|
|
304
352
|
),
|
|
305
353
|
|
|
354
|
+
trait_method_effect: $ => seq('[', 'suspends', ']'),
|
|
355
|
+
|
|
306
356
|
associated_type: $ => seq(
|
|
307
357
|
'type',
|
|
308
358
|
field('name', $.identifier),
|
|
@@ -523,7 +573,7 @@ export default grammar({
|
|
|
523
573
|
field('name', $.identifier),
|
|
524
574
|
':',
|
|
525
575
|
field('actor', $._type),
|
|
526
|
-
optional(
|
|
576
|
+
optional($.spawn_keys),
|
|
527
577
|
repeat($.child_clause),
|
|
528
578
|
';',
|
|
529
579
|
),
|
|
@@ -597,18 +647,18 @@ export default grammar({
|
|
|
597
647
|
),
|
|
598
648
|
),
|
|
599
649
|
|
|
600
|
-
// [ "initial" ] StateDecl
|
|
650
|
+
// [ "initial" ] StateDecl — direct leaf or compound child
|
|
601
651
|
machine_composite_member: $ => seq(
|
|
602
652
|
optional('initial'),
|
|
603
653
|
$.machine_state,
|
|
604
654
|
),
|
|
605
655
|
|
|
606
|
-
// on EventIdent [ "
|
|
656
|
+
// on EventIdent [ "{" Ident { "," Ident } "}" ] : Source => Target
|
|
607
657
|
// [ "reenter" ] [ "when" Expr ] TransitionBody
|
|
608
658
|
// Source = Ident ( "." Ident )* | "_" (hew-parser/src/parser/actor_machine_supervisor.rs
|
|
609
659
|
// parse_state_pattern: a leading "." is rejected on the source; a
|
|
610
|
-
//
|
|
611
|
-
// Target = Ident
|
|
660
|
+
// qualified ancestry is retained and checked)
|
|
661
|
+
// Target = Ident ( "." Ident )* | "." Ident | "_" (the contextual
|
|
612
662
|
// form is the bare-variant target the checker's fix-it steers authors
|
|
613
663
|
// towards; "._" is rejected, so the wildcard stays plain "_")
|
|
614
664
|
// TransitionBody = ";" | "{" FieldInitList "}" | Block
|
|
@@ -617,20 +667,33 @@ export default grammar({
|
|
|
617
667
|
machine_transition: $ => seq(
|
|
618
668
|
'on',
|
|
619
669
|
field('event', $.identifier),
|
|
620
|
-
optional(seq('
|
|
670
|
+
optional(seq('{', field('payload_bindings', sep1($.identifier, ',')), optional(','), '}')),
|
|
621
671
|
':',
|
|
622
672
|
field('source', choice(seq($.identifier, repeat(seq('.', $.identifier))), '_')),
|
|
623
673
|
'=>',
|
|
624
|
-
field('target', choice($.identifier, $.contextual_variant_expression, '_')),
|
|
674
|
+
field('target', choice(seq($.identifier, repeat(seq('.', $.identifier))), $.contextual_variant_expression, '_')),
|
|
625
675
|
optional('reenter'),
|
|
626
676
|
optional(seq('when', field('guard', $.expression))),
|
|
627
677
|
// A bodyless transition needs a semicolon; a body ends at `}`.
|
|
628
678
|
choice(
|
|
629
679
|
';',
|
|
680
|
+
// A lone shorthand `{ name }` is the block yielding `name`, so a
|
|
681
|
+
// payload opens with a written field or with a shorthand field and
|
|
682
|
+
// `,` (hew-parser `is_struct_init_body`).
|
|
630
683
|
field('payload', seq(
|
|
631
684
|
'{',
|
|
632
|
-
|
|
633
|
-
|
|
685
|
+
choice(
|
|
686
|
+
seq(
|
|
687
|
+
alias($._written_field_initializer, $.field_initializer),
|
|
688
|
+
repeat(seq(',', $.field_initializer)),
|
|
689
|
+
optional(','),
|
|
690
|
+
),
|
|
691
|
+
seq(
|
|
692
|
+
alias($._shorthand_field_initializer, $.field_initializer),
|
|
693
|
+
',',
|
|
694
|
+
optional(seq(sep1($.field_initializer, ','), optional(','))),
|
|
695
|
+
),
|
|
696
|
+
),
|
|
634
697
|
'}',
|
|
635
698
|
)),
|
|
636
699
|
field('body', $.block),
|
|
@@ -745,8 +808,9 @@ export default grammar({
|
|
|
745
808
|
// Qualified type name: `mod.Type` or `a.b.C`, with an optional trailing
|
|
746
809
|
// type-arg list (e.g. `mod.Worker<T>`). Dotted paths are used throughout
|
|
747
810
|
// the current surface for cross-module types (`net.NetError`, `fs.IoError`).
|
|
811
|
+
// A module can share a primitive spelling, as in `string.NumberError`.
|
|
748
812
|
scoped_type: $ => seq(
|
|
749
|
-
$.identifier,
|
|
813
|
+
choice($.identifier, alias($.primitive_type, $.identifier)),
|
|
750
814
|
repeat1(seq('.', $.identifier)),
|
|
751
815
|
optional($.type_arguments),
|
|
752
816
|
),
|
|
@@ -763,6 +827,7 @@ export default grammar({
|
|
|
763
827
|
|
|
764
828
|
function_type: $ => prec(1, seq(
|
|
765
829
|
'fn', optional($.callable_capabilities),
|
|
830
|
+
optional($.type_parameters),
|
|
766
831
|
'(', optional(sep1($._type, ',')), ')', optional($.return_type),
|
|
767
832
|
)),
|
|
768
833
|
|
|
@@ -793,7 +858,9 @@ export default grammar({
|
|
|
793
858
|
|
|
794
859
|
// ---- Statements ----
|
|
795
860
|
|
|
796
|
-
block: $ => seq('{', repeat($._statement), '}'),
|
|
861
|
+
block: $ => seq('{', repeat($._statement), optional(alias($._tail_expression, $.expression_statement)), '}'),
|
|
862
|
+
|
|
863
|
+
_tail_expression: $ => $.expression,
|
|
797
864
|
|
|
798
865
|
_statement: $ => choice(
|
|
799
866
|
// A stray `;` after a statement is accepted by the compiler with an
|
|
@@ -818,9 +885,6 @@ export default grammar({
|
|
|
818
885
|
$.block_like_statement,
|
|
819
886
|
),
|
|
820
887
|
|
|
821
|
-
// LetStmt (grammar.ebnf): the initializer is optional — `let x: i64;` is a
|
|
822
|
-
// bare declaration whose definite-assignment is checked later by the move
|
|
823
|
-
// checker (examples/v05/checked-mir/reject/init_before_use.hew).
|
|
824
888
|
let_statement: $ => seq(
|
|
825
889
|
'let',
|
|
826
890
|
field('pattern', $.pattern),
|
|
@@ -837,9 +901,10 @@ export default grammar({
|
|
|
837
901
|
var_statement: $ => seq(
|
|
838
902
|
'var',
|
|
839
903
|
field('name', $.identifier),
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
904
|
+
choice(
|
|
905
|
+
seq(':', field('type', $._type), optional(seq('=', field('value', $.expression)))),
|
|
906
|
+
seq('=', field('value', $.expression)),
|
|
907
|
+
),
|
|
843
908
|
';',
|
|
844
909
|
),
|
|
845
910
|
|
|
@@ -874,7 +939,7 @@ export default grammar({
|
|
|
874
939
|
$.scope_expression,
|
|
875
940
|
$.unsafe_expression,
|
|
876
941
|
$.select_expression,
|
|
877
|
-
seq('fork', $.block),
|
|
942
|
+
prec(PREC.TASK, seq('fork', $.block)),
|
|
878
943
|
),
|
|
879
944
|
|
|
880
945
|
|
|
@@ -887,7 +952,7 @@ export default grammar({
|
|
|
887
952
|
// it is valid in tail position without `;` and inside larger expressions
|
|
888
953
|
// (`b || return 0`, `g(if c { 1 } else { return 0 })`). See hew commit
|
|
889
954
|
// 480456ec5 (return-as-expression) and hew-parser expressions.rs:1125-1150.
|
|
890
|
-
// Statement position is handled by `expression_statement
|
|
955
|
+
// Statement position is handled by `expression_statement`; a tail omits `;`.
|
|
891
956
|
return_expression: $ => prec.right(seq('return', optional($.expression))),
|
|
892
957
|
|
|
893
958
|
// `return error <expr>` returns the failure of a `fails E` function. After
|
|
@@ -901,7 +966,7 @@ export default grammar({
|
|
|
901
966
|
// Deferred cleanup may be an expression statement or a scoped block.
|
|
902
967
|
// `defer <expr>;` or `defer { … }` — a block body needs no `;`
|
|
903
968
|
// (hew-parser statements.rs `Token::Defer`).
|
|
904
|
-
defer_statement: $ => seq('defer', choice(seq($.expression, ';'), $.block)),
|
|
969
|
+
defer_statement: $ => seq('defer', optional('err'), choice(seq($.expression, ';'), $.block)),
|
|
905
970
|
|
|
906
971
|
// emit EventName { field: value, … } ; — Mealy output inside a transition body
|
|
907
972
|
emit_statement: $ => seq(
|
|
@@ -911,9 +976,8 @@ export default grammar({
|
|
|
911
976
|
';',
|
|
912
977
|
),
|
|
913
978
|
|
|
914
|
-
//
|
|
915
|
-
|
|
916
|
-
expression_statement: $ => prec.right(seq($.expression, optional(';'))),
|
|
979
|
+
// Ordinary expressions omit their semicolon only at the end of a block.
|
|
980
|
+
expression_statement: $ => seq($.expression, ';'),
|
|
917
981
|
|
|
918
982
|
empty_statement: $ => ';',
|
|
919
983
|
|
|
@@ -927,8 +991,7 @@ export default grammar({
|
|
|
927
991
|
$.unsafe_expression,
|
|
928
992
|
$.scope_expression,
|
|
929
993
|
$.select_expression,
|
|
930
|
-
$.
|
|
931
|
-
alias(seq('fork', $.block), $.fork_expression),
|
|
994
|
+
alias(prec(PREC.TASK, seq('fork', $.block)), $.fork_expression),
|
|
932
995
|
$.gen_block_expression,
|
|
933
996
|
)),
|
|
934
997
|
|
|
@@ -941,21 +1004,36 @@ export default grammar({
|
|
|
941
1004
|
// ---- Expressions ----
|
|
942
1005
|
|
|
943
1006
|
expression: $ => choice(
|
|
1007
|
+
$._callable_expression,
|
|
1008
|
+
$.spawn_expression,
|
|
1009
|
+
$.unary_expression,
|
|
1010
|
+
$.binary_expression,
|
|
1011
|
+
$.await_expression,
|
|
1012
|
+
$.clone_expression,
|
|
1013
|
+
$.lambda,
|
|
1014
|
+
$.fork_expression,
|
|
1015
|
+
$.handle_expression,
|
|
1016
|
+
$.yield_expression,
|
|
1017
|
+
$.return_expression,
|
|
1018
|
+
$.return_error_expression,
|
|
1019
|
+
),
|
|
1020
|
+
|
|
1021
|
+
// Postfix calls bind inside prefix and infix operands. In particular,
|
|
1022
|
+
// `return spawn Worker()` cannot become a call on `return spawn Worker`.
|
|
1023
|
+
// A bare spawn ends after its actor and optional brace-delimited keys.
|
|
1024
|
+
_callable_expression: $ => choice(
|
|
944
1025
|
$.identifier,
|
|
945
1026
|
alias('capture', $.identifier),
|
|
946
1027
|
$.self,
|
|
947
1028
|
$._literal,
|
|
948
1029
|
$.interpolated_string,
|
|
949
|
-
$.unary_expression,
|
|
950
|
-
$.binary_expression,
|
|
951
1030
|
$.call_expression,
|
|
1031
|
+
$.macro_invocation,
|
|
952
1032
|
$.method_call_expression,
|
|
953
1033
|
$.field_expression,
|
|
954
1034
|
$.index_expression,
|
|
955
1035
|
$.try_expression,
|
|
956
1036
|
$.cast_expression,
|
|
957
|
-
$.await_expression,
|
|
958
|
-
$.clone_expression,
|
|
959
1037
|
$.struct_init,
|
|
960
1038
|
$.generic_struct_init,
|
|
961
1039
|
$.contextual_variant_expression,
|
|
@@ -969,17 +1047,10 @@ export default grammar({
|
|
|
969
1047
|
$.parenthesized_expression,
|
|
970
1048
|
$.if_expression,
|
|
971
1049
|
$.match_expression,
|
|
972
|
-
$.lambda,
|
|
973
1050
|
$.actor_expression,
|
|
974
|
-
$.spawn_expression,
|
|
975
1051
|
$.select_expression,
|
|
976
1052
|
$.race_expression,
|
|
977
|
-
$.fork_expression,
|
|
978
|
-
$.handle_expression,
|
|
979
1053
|
$.scope_expression,
|
|
980
|
-
$.yield_expression,
|
|
981
|
-
$.return_expression,
|
|
982
|
-
$.return_error_expression,
|
|
983
1054
|
alias('error', $.identifier),
|
|
984
1055
|
$.gen_block_expression,
|
|
985
1056
|
$.qualified_expression,
|
|
@@ -1029,13 +1100,18 @@ export default grammar({
|
|
|
1029
1100
|
// Left associativity keeps postfix calls composable after a completed
|
|
1030
1101
|
// field/call chain (`value.slice(...).to_lower()`).
|
|
1031
1102
|
call_expression: $ => prec.left(PREC.FIELD + 1, seq(
|
|
1032
|
-
field('function', $.expression),
|
|
1103
|
+
field('function', alias($._callable_expression, $.expression)),
|
|
1033
1104
|
'(',
|
|
1034
1105
|
optional(sep1($.call_argument, ',')),
|
|
1035
1106
|
optional(','),
|
|
1036
1107
|
')',
|
|
1037
1108
|
)),
|
|
1038
1109
|
|
|
1110
|
+
macro_invocation: $ => prec(PREC.POSTFIX, seq(
|
|
1111
|
+
field('name', choice($.identifier, alias('capture', $.identifier), $.path_expression)), '!',
|
|
1112
|
+
field('arguments', alias($.macro_pattern, $.token_tree)),
|
|
1113
|
+
)),
|
|
1114
|
+
|
|
1039
1115
|
// A member call must remain a single postfix expression even where `(`
|
|
1040
1116
|
// could begin the following match pattern. Its function is structurally a
|
|
1041
1117
|
// field expression, so this does not overlap plain calls or grouping.
|
|
@@ -1111,14 +1187,23 @@ export default grammar({
|
|
|
1111
1187
|
// general expression set so a statement-level `{` still opens a block
|
|
1112
1188
|
// statement.
|
|
1113
1189
|
call_argument: $ => choice(
|
|
1114
|
-
seq(field('name', $.identifier), ':', field('value', choice($.expression, $.block))),
|
|
1190
|
+
seq(field('name', $.identifier), ':', field('value', choice($.expression, $.block, $.range_argument))),
|
|
1115
1191
|
$.expression,
|
|
1116
1192
|
$.block,
|
|
1193
|
+
$.range_argument,
|
|
1194
|
+
),
|
|
1195
|
+
|
|
1196
|
+
// Closed ranges remain ordinary binary expressions. Open bounds are
|
|
1197
|
+
// accepted as arguments; an inclusive range still requires its end.
|
|
1198
|
+
range_argument: $ => choice(
|
|
1199
|
+
seq('..', optional(field('end', $.expression))),
|
|
1200
|
+
seq('..=', field('end', $.expression)),
|
|
1201
|
+
seq(field('start', $.expression), '..'),
|
|
1117
1202
|
),
|
|
1118
1203
|
|
|
1119
1204
|
field_expression: $ => prec(PREC.FIELD, seq(
|
|
1120
1205
|
field('object', $.expression),
|
|
1121
|
-
'.',
|
|
1206
|
+
choice('.', '?.'),
|
|
1122
1207
|
field('field', choice($.identifier, $.integer_literal)),
|
|
1123
1208
|
)),
|
|
1124
1209
|
|
|
@@ -1134,7 +1219,7 @@ export default grammar({
|
|
|
1134
1219
|
']',
|
|
1135
1220
|
)),
|
|
1136
1221
|
|
|
1137
|
-
try_expression: $ => prec(PREC.
|
|
1222
|
+
try_expression: $ => prec(PREC.TRY, seq(
|
|
1138
1223
|
$.expression,
|
|
1139
1224
|
'?',
|
|
1140
1225
|
)),
|
|
@@ -1145,7 +1230,7 @@ export default grammar({
|
|
|
1145
1230
|
field('type', $._type),
|
|
1146
1231
|
)),
|
|
1147
1232
|
|
|
1148
|
-
await_expression: $ => prec(PREC.
|
|
1233
|
+
await_expression: $ => prec(PREC.TASK, seq(
|
|
1149
1234
|
'await',
|
|
1150
1235
|
choice($.expression, $.block),
|
|
1151
1236
|
)),
|
|
@@ -1193,16 +1278,22 @@ export default grammar({
|
|
|
1193
1278
|
'}',
|
|
1194
1279
|
)),
|
|
1195
1280
|
|
|
1196
|
-
field_initializer: $ =>
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1281
|
+
field_initializer: $ => choice(
|
|
1282
|
+
$._written_field_initializer,
|
|
1283
|
+
$._shorthand_field_initializer,
|
|
1284
|
+
),
|
|
1285
|
+
|
|
1286
|
+
// `error` lexes as a keyword where a statement could start (`return
|
|
1287
|
+
// error`, bare `error` expression); alias it so `{ error: v }` and
|
|
1288
|
+
// `{ error }` still read as field initializers.
|
|
1289
|
+
_written_field_initializer: $ => choice(
|
|
1290
|
+
seq(field('name', choice($.identifier, alias('error', $.identifier))), ':', field('value', $.expression)),
|
|
1291
|
+
seq('..', field('spread', $.expression)),
|
|
1204
1292
|
),
|
|
1205
1293
|
|
|
1294
|
+
// Shorthand `name` stands for `name: name`.
|
|
1295
|
+
_shorthand_field_initializer: $ => field('name', choice($.identifier, alias('error', $.identifier))),
|
|
1296
|
+
|
|
1206
1297
|
array_expression: $ => seq(
|
|
1207
1298
|
'[',
|
|
1208
1299
|
optional(seq(sep1($._array_element, ','), optional(','))),
|
|
@@ -1279,7 +1370,7 @@ export default grammar({
|
|
|
1279
1370
|
// Closures are PIPE-style (spec grammar.ebnf:288-295):
|
|
1280
1371
|
// Lambda = "move"? "|" LambdaParams? "|" Expr
|
|
1281
1372
|
// | "move"? "||" Expr
|
|
1282
|
-
// | "move"? "|" LambdaParams? "|" RetType Block ;
|
|
1373
|
+
// | "move"? "|" TypeParams? LambdaParams? "|" RetType Block ;
|
|
1283
1374
|
// The paren-arrow `(params) => body` form was removed in v0.5
|
|
1284
1375
|
// (compiler emits E_CLOSURE_PIPE_SYNTAX). An empty parameter list is the
|
|
1285
1376
|
// single `||` token because the lexer fuses adjacent pipes; the bracketed
|
|
@@ -1290,7 +1381,7 @@ export default grammar({
|
|
|
1290
1381
|
optional($.private_capture_list),
|
|
1291
1382
|
field('parameters', choice(
|
|
1292
1383
|
'||',
|
|
1293
|
-
seq('|', optional(sep1($.lambda_parameter, ',')), '|'),
|
|
1384
|
+
seq('|', optional($.type_parameters), optional(sep1($.lambda_parameter, ',')), '|'),
|
|
1294
1385
|
)),
|
|
1295
1386
|
choice(
|
|
1296
1387
|
seq($.return_type, field('body', $.block)),
|
|
@@ -1300,7 +1391,7 @@ export default grammar({
|
|
|
1300
1391
|
)),
|
|
1301
1392
|
|
|
1302
1393
|
private_capture_list: $ => seq(
|
|
1303
|
-
'capture', '(', sep1($.private_capture, ','), ')',
|
|
1394
|
+
'capture', '(', sep1($.private_capture, ','), optional(','), ')',
|
|
1304
1395
|
),
|
|
1305
1396
|
|
|
1306
1397
|
private_capture: $ => seq('var', field('name', $.identifier)),
|
|
@@ -1310,11 +1401,11 @@ export default grammar({
|
|
|
1310
1401
|
optional(seq(':', field('type', $._type))),
|
|
1311
1402
|
),
|
|
1312
1403
|
|
|
1313
|
-
//
|
|
1314
|
-
// Replaces the removed `spawn (...) => ...` lambda-actor form.
|
|
1404
|
+
// Actor literals share the closure prefix for private mutable captures.
|
|
1315
1405
|
actor_expression: $ => prec(2, seq(
|
|
1316
1406
|
'actor',
|
|
1317
1407
|
optional('move'),
|
|
1408
|
+
optional($.private_capture_list),
|
|
1318
1409
|
'|',
|
|
1319
1410
|
optional(sep1($.lambda_parameter, ',')),
|
|
1320
1411
|
'|',
|
|
@@ -1330,12 +1421,16 @@ export default grammar({
|
|
|
1330
1421
|
actor_spawn: $ => seq(
|
|
1331
1422
|
field('actor', $._type),
|
|
1332
1423
|
optional($.type_arguments),
|
|
1333
|
-
optional(
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1424
|
+
optional($.spawn_keys),
|
|
1425
|
+
),
|
|
1426
|
+
|
|
1427
|
+
// Keys of a spawn or supervisor child, keyed like a record literal:
|
|
1428
|
+
// `{ key: value, key }`. An empty list is written without braces.
|
|
1429
|
+
spawn_keys: $ => seq(
|
|
1430
|
+
'{',
|
|
1431
|
+
sep1($.field_initializer, ','),
|
|
1432
|
+
optional(','),
|
|
1433
|
+
'}',
|
|
1339
1434
|
),
|
|
1340
1435
|
|
|
1341
1436
|
select_expression: $ => seq(
|
|
@@ -1392,10 +1487,10 @@ export default grammar({
|
|
|
1392
1487
|
),
|
|
1393
1488
|
|
|
1394
1489
|
race_expression: $ => seq(
|
|
1395
|
-
'race', '
|
|
1490
|
+
'race', '[', optional(seq(sep1($.expression, ','), optional(','))), ']',
|
|
1396
1491
|
),
|
|
1397
1492
|
|
|
1398
|
-
fork_expression: $ => prec.right(seq('fork', choice($.expression, $.block))),
|
|
1493
|
+
fork_expression: $ => prec.right(PREC.TASK, seq('fork', choice($.expression, $.block))),
|
|
1399
1494
|
|
|
1400
1495
|
handle_expression: $ => prec.left(1, seq(
|
|
1401
1496
|
field('operand', $.expression), 'handle', field('error', $.identifier),
|
package/package.json
CHANGED
package/queries/folds.scm
CHANGED
package/queries/highlights.scm
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"fn" "let" "var" "const" "mut" "pub" "return" "if" "else" "match" "for" "while"
|
|
6
6
|
"loop" "break" "continue" "in" "spawn" "await" "select" "race"
|
|
7
7
|
"import" "extern" "gen" "yield" "scope" "move" "fork"
|
|
8
|
-
"type" "where" "dyn" "unsafe" "defer"
|
|
8
|
+
"type" "where" "dyn" "unsafe" "defer" "macro"
|
|
9
9
|
"init" "child" "pool" "restart" "wired_to"
|
|
10
10
|
"package" "after"
|
|
11
11
|
"reserved" "optional" "deprecated" "default"
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
; where `clone` stays an ordinary identifier.
|
|
21
21
|
(clone_expression "clone" @keyword.operator)
|
|
22
22
|
(callable_capabilities ["var" "once" "clone" "suspends"] @keyword)
|
|
23
|
+
(trait_method_effect "suspends" @keyword)
|
|
23
24
|
(private_capture_list "capture" @keyword)
|
|
24
25
|
(private_capture (identifier) @variable)
|
|
25
26
|
(failure_return "fails" @keyword)
|
|
26
27
|
(return_error_expression "error" @keyword)
|
|
28
|
+
(defer_statement "err" @keyword)
|
|
27
29
|
(child_clause ["count" "stop"] @keyword)
|
|
28
30
|
|
|
29
31
|
"receive" @keyword
|
|
@@ -60,7 +62,13 @@
|
|
|
60
62
|
(attribute "#" @punctuation.special)
|
|
61
63
|
(attribute "[" @punctuation.special)
|
|
62
64
|
(attribute "]" @punctuation.special)
|
|
63
|
-
(attribute (identifier) @attribute)
|
|
65
|
+
(attribute name: (identifier) @attribute)
|
|
66
|
+
|
|
67
|
+
(macro_declaration name: (identifier) @function.macro)
|
|
68
|
+
(macro_rule category: ["expr" "items"] @keyword)
|
|
69
|
+
(macro_function_capture ["fn" "method" "fails"] @keyword)
|
|
70
|
+
(macro_variable (identifier) @variable.parameter)
|
|
71
|
+
"$" @punctuation.special
|
|
64
72
|
|
|
65
73
|
; ---- Literals ----
|
|
66
74
|
(integer_literal) @number
|
|
@@ -93,6 +101,7 @@
|
|
|
93
101
|
|
|
94
102
|
(type_parameters "<" @punctuation.bracket)
|
|
95
103
|
(type_parameters ">" @punctuation.bracket)
|
|
104
|
+
(type_parameter (identifier) @type)
|
|
96
105
|
(machine_type_parameters "<" @punctuation.bracket)
|
|
97
106
|
(machine_type_parameters ">" @punctuation.bracket)
|
|
98
107
|
(const_parameter name: (identifier) @constant)
|
|
@@ -137,6 +146,9 @@
|
|
|
137
146
|
|
|
138
147
|
(self) @variable.builtin
|
|
139
148
|
|
|
149
|
+
(macro_invocation name: (identifier) @function.macro)
|
|
150
|
+
(macro_invocation name: (path_expression (identifier) @function.macro))
|
|
151
|
+
|
|
140
152
|
(field_expression
|
|
141
153
|
field: (identifier) @property)
|
|
142
154
|
|
|
@@ -231,7 +243,7 @@
|
|
|
231
243
|
; ---- Operators ----
|
|
232
244
|
[
|
|
233
245
|
"+" "-" "*" "/" "%" "!" "=" "==" "!=" "<" "<=" ">" ">=" "&&" "||"
|
|
234
|
-
"+=" "-=" "*=" "/=" "%=" ".." "..=" "=>" "->" "?" "??"
|
|
246
|
+
"+=" "-=" "*=" "/=" "%=" ".." "..=" "=>" "->" "?" "?." "??"
|
|
235
247
|
"<<" ">>" "&=" "|=" "^=" "<<=" ">>="
|
|
236
248
|
"&" "|" "^" "~" "is" "&+" "&-" "&*"
|
|
237
249
|
] @operator
|