@hew-lang/tree-sitter-hew 1.0.0 → 1.0.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 CHANGED
@@ -17,12 +17,12 @@ require('nvim-treesitter.configs').setup {
17
17
  ### Node.js
18
18
 
19
19
  ```bash
20
- npm install tree-sitter-hew
20
+ npm install @hew-lang/tree-sitter-hew
21
21
  ```
22
22
 
23
23
  ```javascript
24
24
  const Parser = require('tree-sitter');
25
- const Hew = require('tree-sitter-hew');
25
+ const Hew = require('@hew-lang/tree-sitter-hew');
26
26
 
27
27
  const parser = new Parser();
28
28
  parser.setLanguage(Hew);
@@ -35,7 +35,7 @@ console.log(tree.rootNode.toString());
35
35
 
36
36
  ```toml
37
37
  [dependencies]
38
- tree-sitter-hew = "0.1"
38
+ tree-sitter-hew = "1"
39
39
  ```
40
40
 
41
41
  ## Development
package/grammar.js CHANGED
@@ -38,6 +38,7 @@ export default grammar({
38
38
  [$.if_statement, $.expression],
39
39
  [$.match_statement, $.expression],
40
40
  [$.expression, $.struct_init],
41
+ [$.actor_spawn],
41
42
  ],
42
43
 
43
44
  rules: {
@@ -62,6 +63,7 @@ export default grammar({
62
63
  $.extern_block,
63
64
  $.actor_declaration,
64
65
  $.supervisor_declaration,
66
+ $.machine_declaration,
65
67
  $.type_alias,
66
68
  ),
67
69
  ),
@@ -147,7 +149,7 @@ export default grammar({
147
149
 
148
150
  wire_declaration: $ => seq(
149
151
  'wire',
150
- choice('struct', 'enum'),
152
+ choice('struct', 'enum', 'type'),
151
153
  field('name', $.identifier),
152
154
  field('body', $.wire_body),
153
155
  ),
@@ -163,11 +165,10 @@ export default grammar({
163
165
  optional(choice(',', ';')),
164
166
  )),
165
167
 
168
+ // @sync:wire_types
166
169
  wire_type: $ => choice(
167
- 'u8', 'u16', 'u32', 'u64',
168
- 'i8', 'i16', 'i32', 'i64',
169
- 'f32', 'f64',
170
- 'bool', 'bytes', 'string',
170
+ 'u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'f32', 'f64', 'bool',
171
+ 'bytes', 'string',
171
172
  $.identifier,
172
173
  seq('list', '[', $.wire_type, ']'),
173
174
  ),
@@ -176,9 +177,9 @@ export default grammar({
176
177
  'reserved', '(', sep1($.integer_literal, ','), ')', ';',
177
178
  ),
178
179
 
180
+ // @sync:wire_attributes
179
181
  wire_attribute: $ => choice(
180
- 'optional',
181
- 'deprecated',
182
+ 'optional', 'deprecated',
182
183
  seq('default', '(', $.expression, ')'),
183
184
  seq('reserved', '(', sep1($.integer_literal, ','), ')'),
184
185
  ),
@@ -348,11 +349,9 @@ export default grammar({
348
349
  $.overflow_kind,
349
350
  ),
350
351
 
352
+ // @sync:overflow_kinds
351
353
  overflow_kind: $ => choice(
352
- 'block',
353
- 'drop_new',
354
- 'drop_old',
355
- 'fail',
354
+ 'block', 'drop_new', 'drop_old', 'fail',
356
355
  seq('coalesce', '(', $.identifier, ')', optional(seq('fallback', $.overflow_kind))),
357
356
  ),
358
357
 
@@ -424,14 +423,69 @@ export default grammar({
424
423
  restart_spec: $ => seq(
425
424
  'restart',
426
425
  '(',
426
+ // @sync:restart_permanence
427
427
  choice('permanent', 'transient', 'temporary'),
428
428
  ')',
429
429
  optional(seq('budget', '(', $.integer_literal, ',', $.duration_literal, ')')),
430
+ // @sync:restart_strategies
430
431
  optional(seq('strategy', '(', choice('one_for_one', 'one_for_all', 'rest_for_one'), ')')),
431
432
  ),
432
433
 
434
+ // @sync:duration_suffixes
433
435
  duration_literal: $ => seq($.integer_literal, choice('ns', 'us', 'ms', 's', 'm', 'h')),
434
436
 
437
+ // ---- Machines ----
438
+
439
+ machine_declaration: $ => seq(
440
+ optional($.visibility),
441
+ 'machine',
442
+ field('name', $.identifier),
443
+ '{',
444
+ repeat(choice(
445
+ $.machine_state,
446
+ $.machine_event,
447
+ $.machine_transition,
448
+ $.machine_default,
449
+ )),
450
+ '}',
451
+ ),
452
+
453
+ machine_state: $ => seq(
454
+ 'state',
455
+ field('name', $.identifier),
456
+ optional(seq('{', repeat($.struct_field), '}')),
457
+ optional(';'),
458
+ ),
459
+
460
+ machine_event: $ => seq(
461
+ 'event',
462
+ field('name', $.identifier),
463
+ optional(seq('{', repeat($.struct_field), '}')),
464
+ optional(';'),
465
+ ),
466
+
467
+ machine_transition: $ => seq(
468
+ 'on',
469
+ field('event', $.identifier),
470
+ ':',
471
+ field('source', $.identifier),
472
+ '->',
473
+ field('target', $.identifier),
474
+ optional(seq('when', field('guard', $.expression))),
475
+ choice(
476
+ ';',
477
+ seq('{', repeat(choice($.field_initializer, $._statement)), '}'),
478
+ ),
479
+ ),
480
+
481
+ machine_default: $ => seq(
482
+ 'default',
483
+ choice(
484
+ seq('{', repeat($._statement), '}'),
485
+ ';',
486
+ ),
487
+ ),
488
+
435
489
  // ---- Extern ----
436
490
 
437
491
  extern_block: $ => seq(
@@ -488,12 +542,10 @@ export default grammar({
488
542
  $.unit_type,
489
543
  ),
490
544
 
545
+ // @sync:primitive_types
491
546
  primitive_type: $ => choice(
492
- 'i8', 'i16', 'i32', 'i64',
493
- 'u8', 'u16', 'u32', 'u64',
494
- 'f32', 'f64',
495
- 'isize', 'usize',
496
- 'bool', 'char', 'string', 'bytes', 'void', 'duration',
547
+ 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'usize',
548
+ 'f32', 'f64', 'bool', 'char', 'string', 'bytes', 'void', 'duration',
497
549
  ),
498
550
 
499
551
  generic_type: $ => prec(1, seq($.identifier, $.type_arguments)),
@@ -557,6 +609,7 @@ export default grammar({
557
609
 
558
610
  assignment_statement: $ => seq(
559
611
  field('left', $.expression),
612
+ // @sync:assignment_operators
560
613
  field('operator', choice('=', '+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '<<=', '>>=')),
561
614
  field('right', $.expression),
562
615
  ';',
@@ -609,6 +662,7 @@ export default grammar({
609
662
  $.struct_init,
610
663
  $.array_expression,
611
664
  $.array_repeat,
665
+ $.map_literal,
612
666
  $.tuple_expression,
613
667
  $.parenthesized_expression,
614
668
  $.if_expression,
@@ -712,6 +766,19 @@ export default grammar({
712
766
 
713
767
  array_repeat: $ => seq('[', $.expression, ';', $.expression, ']'),
714
768
 
769
+ map_literal: $ => seq(
770
+ '{',
771
+ sep1($.map_entry, ','),
772
+ optional(','),
773
+ '}',
774
+ ),
775
+
776
+ map_entry: $ => seq(
777
+ field('key', $.expression),
778
+ ':',
779
+ field('value', $.expression),
780
+ ),
781
+
715
782
  tuple_expression: $ => seq('(', $.expression, ',', optional(sep1($.expression, ',')), ')'),
716
783
 
717
784
  parenthesized_expression: $ => seq('(', $.expression, ')'),
@@ -759,9 +826,11 @@ export default grammar({
759
826
  actor_spawn: $ => seq(
760
827
  field('actor', $.identifier),
761
828
  optional($.type_arguments),
762
- '(',
763
- optional(sep1($.call_argument, ',')),
764
- ')',
829
+ optional(seq(
830
+ '(',
831
+ optional(sep1($.call_argument, ',')),
832
+ ')',
833
+ )),
765
834
  ),
766
835
 
767
836
  lambda_actor: $ => prec(2, seq(
@@ -875,6 +944,7 @@ export default grammar({
875
944
  $.float_literal,
876
945
  $.string_literal,
877
946
  $.raw_string_literal,
947
+ $.byte_string_literal,
878
948
  $.regex_literal,
879
949
  $.boolean_literal,
880
950
  $.none_literal,
@@ -936,12 +1006,19 @@ export default grammar({
936
1006
  '"',
937
1007
  )),
938
1008
 
1009
+ byte_string_literal: $ => token(seq(
1010
+ 'b"',
1011
+ /([^"\\]|\\.)*/,
1012
+ '"',
1013
+ )),
1014
+
939
1015
  regex_literal: $ => token(seq(
940
1016
  're"',
941
1017
  /[^"]*/,
942
1018
  '"',
943
1019
  )),
944
1020
 
1021
+ // @sync:boolean_literals
945
1022
  boolean_literal: $ => choice('true', 'false'),
946
1023
 
947
1024
  none_literal: $ => 'None',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hew-lang/tree-sitter-hew",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Hew grammar for tree-sitter",
5
5
  "type": "module",
6
6
  "repository": {
@@ -16,9 +16,13 @@
16
16
  (cooperate_expression) @keyword
17
17
 
18
18
  [
19
- "enum" "trait" "impl" "actor" "supervisor" "wire"
19
+ "enum" "trait" "impl" "actor" "supervisor" "wire" "machine"
20
20
  ] @keyword.type
21
21
 
22
+ [
23
+ "state" "event" "on" "when"
24
+ ] @keyword
25
+
22
26
  "pure" @keyword
23
27
 
24
28
  [
@@ -39,6 +43,7 @@
39
43
 
40
44
  (string_literal) @string
41
45
  (raw_string_literal) @string
46
+ (byte_string_literal) @string
42
47
  (regex_literal) @string.regexp
43
48
  (interpolated_string) @string
44
49
  (fstring_start) @string.special
@@ -137,6 +142,21 @@
137
142
  (wire_declaration
138
143
  name: (identifier) @type)
139
144
 
145
+ (machine_declaration
146
+ name: (identifier) @type)
147
+
148
+ (machine_state
149
+ name: (identifier) @constant)
150
+
151
+ (machine_event
152
+ name: (identifier) @constant)
153
+
154
+ (machine_transition
155
+ event: (identifier) @constant)
156
+
157
+ (map_entry
158
+ key: (expression) @property)
159
+
140
160
  (type_alias
141
161
  name: (identifier) @type)
142
162