@hew-lang/tree-sitter-hew 1.2.2 → 1.2.4

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/grammar.js CHANGED
@@ -221,8 +221,7 @@ export default grammar({
221
221
  ';',
222
222
  ),
223
223
 
224
- // TypeDecl (grammar.ebnf:47, 65): `type Name { ... }` whose body may hold
225
- // struct fields, variants, AND fn declarations (TypeBody). The alias form
224
+ // A type body holds fields; methods belong in a sibling impl block. The alias form
226
225
  // `type Name = Type;` is handled separately by `type_alias`.
227
226
  struct_declaration: $ => seq(
228
227
  'type',
@@ -235,7 +234,6 @@ export default grammar({
235
234
  struct_body: $ => seq('{', repeat(choice(
236
235
  $.struct_field,
237
236
  $.reserved_declaration,
238
- seq(optional($.visibility), $.function_declaration),
239
237
  )), '}'),
240
238
 
241
239
  // StructFieldDecl / WireStructFieldDecl (grammar.ebnf:68, 76):
@@ -276,7 +274,7 @@ export default grammar({
276
274
  field('body', $.enum_body),
277
275
  ),
278
276
 
279
- enum_body: $ => seq('{', repeat($.variant), '}'),
277
+ enum_body: $ => seq('{', repeat(choice($.variant, $.reserved_declaration)), '}'),
280
278
 
281
279
  // A `#[wire]` / `#[serial]` enum tags each variant with `@N` after its
282
280
  // payload: `Pending @0;`, `Push(i64) @1;`, `Move { x: i32; } @2;`.
@@ -299,7 +297,7 @@ export default grammar({
299
297
  // both struct-shaped and enum-shaped wire types use the generic `#[wire]`
300
298
  // attribute on ordinary `type` / `enum` declarations.
301
299
 
302
- // `reserved @N, @M;` inside a `#[wire] type` body reserves wire field
300
+ // `reserved @N, @M;` inside a `#[wire] type` or enum body reserves wire tag
303
301
  // numbers (hew-parser wire.rs:222-248 expects `@` markers, comma-separated,
304
302
  // terminated by `;`). The old parenthesised `reserved(N, M);` form is not
305
303
  // accepted by the compiler.
@@ -600,6 +598,7 @@ export default grammar({
600
598
  optional(field('emits_header', $.machine_emits_header)),
601
599
  repeat(choice(
602
600
  $.machine_state,
601
+ $.machine_parallel_state,
603
602
  $.machine_transition,
604
603
  $.machine_default,
605
604
  )),
@@ -629,19 +628,24 @@ export default grammar({
629
628
  '}',
630
629
  ),
631
630
 
632
- // States may contain fields, hooks, substates and transition rules.
631
+ // Hierarchy is authored here; the compiler checks initial-child and
632
+ // final-state constraints after parsing.
633
633
  machine_state: $ => seq(
634
+ optional('final'),
634
635
  'state',
635
636
  field('name', $.identifier),
636
637
  choice(
637
638
  ';',
638
639
  seq(
639
640
  '{',
640
- repeat($.struct_field),
641
- optional(seq('entry', field('entry_body', $.block))),
642
- optional(seq('exit', field('exit_body', $.block))),
643
- repeat($.machine_composite_member),
644
- repeat($.machine_transition),
641
+ repeat(choice(
642
+ $.struct_field,
643
+ seq('entry', field('entry_body', $.block)),
644
+ seq('exit', field('exit_body', $.block)),
645
+ $.machine_composite_member,
646
+ $.machine_initial,
647
+ $.machine_transition,
648
+ )),
645
649
  '}',
646
650
  ),
647
651
  ),
@@ -650,11 +654,38 @@ export default grammar({
650
654
  // [ "initial" ] StateDecl — direct leaf or compound child
651
655
  machine_composite_member: $ => seq(
652
656
  optional('initial'),
653
- $.machine_state,
657
+ choice($.machine_state, $.machine_parallel_state),
658
+ ),
659
+
660
+ machine_parallel_state: $ => seq(
661
+ 'parallel', 'state', field('name', $.identifier), '{',
662
+ repeat(choice(
663
+ $.struct_field,
664
+ seq('entry', field('entry_body', $.block)),
665
+ seq('exit', field('exit_body', $.block)),
666
+ $.machine_region,
667
+ $.machine_transition,
668
+ )),
669
+ '}',
670
+ ),
671
+
672
+ machine_region: $ => seq(
673
+ 'region', field('name', $.identifier), '{',
674
+ repeat(choice($.machine_composite_member, $.machine_initial, $.machine_transition)),
675
+ '}',
676
+ ),
677
+
678
+ machine_initial: $ => seq(
679
+ 'initial',
680
+ field('value', choice(
681
+ $.identifier, $.struct_init, $.generic_struct_init,
682
+ $.contextual_variant_expression, $.contextual_variant_record_init,
683
+ )),
684
+ ';',
654
685
  ),
655
686
 
656
687
  // on EventIdent [ "{" Ident { "," Ident } "}" ] : Source => Target
657
- // [ "reenter" ] [ "when" Expr ] TransitionBody
688
+ // [ "reenter" | "history" ] [ "when" Expr ] TransitionBody
658
689
  // Source = Ident ( "." Ident )* | "_" (hew-parser/src/parser/actor_machine_supervisor.rs
659
690
  // parse_state_pattern: a leading "." is rejected on the source; a
660
691
  // qualified ancestry is retained and checked)
@@ -665,14 +696,18 @@ export default grammar({
665
696
  // The `{ FieldInitList }` form supplies the target state's payload, e.g.
666
697
  // `=> Holding { handle: handle }` or `=> .Holding { handle: handle }`.
667
698
  machine_transition: $ => seq(
668
- 'on',
669
- field('event', $.identifier),
670
- optional(seq('{', field('payload_bindings', sep1($.identifier, ',')), optional(','), '}')),
699
+ choice(
700
+ seq('on', choice(
701
+ seq(field('event', $.identifier), optional(seq('{', field('payload_bindings', sep1($.identifier, ',')), optional(','), '}'))),
702
+ field('trigger', 'completion'),
703
+ )),
704
+ field('trigger', 'always'),
705
+ ),
671
706
  ':',
672
707
  field('source', choice(seq($.identifier, repeat(seq('.', $.identifier))), '_')),
673
708
  '=>',
674
709
  field('target', choice(seq($.identifier, repeat(seq('.', $.identifier))), $.contextual_variant_expression, '_')),
675
- optional('reenter'),
710
+ optional(choice(seq('reenter', optional('history')), seq('history', optional('reenter')))),
676
711
  optional(seq('when', field('guard', $.expression))),
677
712
  // A bodyless transition needs a semicolon; a body ends at `}`.
678
713
  choice(
@@ -801,6 +836,7 @@ export default grammar({
801
836
  primitive_type: $ => choice(
802
837
  'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'usize',
803
838
  'f32', 'f64', 'bool', 'char', 'string', 'bytes', 'duration', 'instant',
839
+ 'timestamp',
804
840
  ),
805
841
 
806
842
  generic_type: $ => prec(1, seq($.identifier, $.type_arguments)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hew-lang/tree-sitter-hew",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Hew grammar for tree-sitter",
5
5
  "type": "module",
6
6
  "repository": {
@@ -50,6 +50,11 @@
50
50
  "mailbox" "overflow" "strategy" "intensity" "within"
51
51
  ] @keyword
52
52
 
53
+ (machine_state "final" @keyword)
54
+ (machine_parallel_state "parallel" @keyword)
55
+ (machine_region "region" @keyword)
56
+ (machine_transition ["history" "completion" "always"] @keyword)
57
+
53
58
  [
54
59
  "block" "drop_new" "drop_old" "fail" "coalesce" "fallback"
55
60
  ] @constant.builtin