@hew-lang/tree-sitter-hew 1.2.3 → 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
@@ -274,7 +274,7 @@ export default grammar({
274
274
  field('body', $.enum_body),
275
275
  ),
276
276
 
277
- enum_body: $ => seq('{', repeat($.variant), '}'),
277
+ enum_body: $ => seq('{', repeat(choice($.variant, $.reserved_declaration)), '}'),
278
278
 
279
279
  // A `#[wire]` / `#[serial]` enum tags each variant with `@N` after its
280
280
  // payload: `Pending @0;`, `Push(i64) @1;`, `Move { x: i32; } @2;`.
@@ -297,7 +297,7 @@ export default grammar({
297
297
  // both struct-shaped and enum-shaped wire types use the generic `#[wire]`
298
298
  // attribute on ordinary `type` / `enum` declarations.
299
299
 
300
- // `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
301
301
  // numbers (hew-parser wire.rs:222-248 expects `@` markers, comma-separated,
302
302
  // terminated by `;`). The old parenthesised `reserved(N, M);` form is not
303
303
  // accepted by the compiler.
@@ -598,6 +598,7 @@ export default grammar({
598
598
  optional(field('emits_header', $.machine_emits_header)),
599
599
  repeat(choice(
600
600
  $.machine_state,
601
+ $.machine_parallel_state,
601
602
  $.machine_transition,
602
603
  $.machine_default,
603
604
  )),
@@ -627,19 +628,24 @@ export default grammar({
627
628
  '}',
628
629
  ),
629
630
 
630
- // 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.
631
633
  machine_state: $ => seq(
634
+ optional('final'),
632
635
  'state',
633
636
  field('name', $.identifier),
634
637
  choice(
635
638
  ';',
636
639
  seq(
637
640
  '{',
638
- repeat($.struct_field),
639
- optional(seq('entry', field('entry_body', $.block))),
640
- optional(seq('exit', field('exit_body', $.block))),
641
- repeat($.machine_composite_member),
642
- 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
+ )),
643
649
  '}',
644
650
  ),
645
651
  ),
@@ -648,11 +654,38 @@ export default grammar({
648
654
  // [ "initial" ] StateDecl — direct leaf or compound child
649
655
  machine_composite_member: $ => seq(
650
656
  optional('initial'),
651
- $.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
+ ';',
652
685
  ),
653
686
 
654
687
  // on EventIdent [ "{" Ident { "," Ident } "}" ] : Source => Target
655
- // [ "reenter" ] [ "when" Expr ] TransitionBody
688
+ // [ "reenter" | "history" ] [ "when" Expr ] TransitionBody
656
689
  // Source = Ident ( "." Ident )* | "_" (hew-parser/src/parser/actor_machine_supervisor.rs
657
690
  // parse_state_pattern: a leading "." is rejected on the source; a
658
691
  // qualified ancestry is retained and checked)
@@ -663,14 +696,18 @@ export default grammar({
663
696
  // The `{ FieldInitList }` form supplies the target state's payload, e.g.
664
697
  // `=> Holding { handle: handle }` or `=> .Holding { handle: handle }`.
665
698
  machine_transition: $ => seq(
666
- 'on',
667
- field('event', $.identifier),
668
- 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
+ ),
669
706
  ':',
670
707
  field('source', choice(seq($.identifier, repeat(seq('.', $.identifier))), '_')),
671
708
  '=>',
672
709
  field('target', choice(seq($.identifier, repeat(seq('.', $.identifier))), $.contextual_variant_expression, '_')),
673
- optional('reenter'),
710
+ optional(choice(seq('reenter', optional('history')), seq('history', optional('reenter')))),
674
711
  optional(seq('when', field('guard', $.expression))),
675
712
  // A bodyless transition needs a semicolon; a body ends at `}`.
676
713
  choice(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hew-lang/tree-sitter-hew",
3
- "version": "1.2.3",
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