@hew-lang/tree-sitter-hew 1.2.3 → 1.3.1

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
@@ -52,7 +52,6 @@ export default grammar({
52
52
  [$._callable_expression, $._member_object],
53
53
  [$.qualified_expression, $.field_expression],
54
54
  [$.generic_apply_expression, $.bare_generic_call_expression],
55
- [$._callable_expression, $.private_capture_list],
56
55
  [$.actor_spawn],
57
56
  [$.trait_bound],
58
57
  // `-> fn() fails E` — the short `fails E` may belong to the inner callable
@@ -274,7 +273,7 @@ export default grammar({
274
273
  field('body', $.enum_body),
275
274
  ),
276
275
 
277
- enum_body: $ => seq('{', repeat($.variant), '}'),
276
+ enum_body: $ => seq('{', repeat(choice($.variant, $.reserved_declaration)), '}'),
278
277
 
279
278
  // A `#[wire]` / `#[serial]` enum tags each variant with `@N` after its
280
279
  // payload: `Pending @0;`, `Push(i64) @1;`, `Move { x: i32; } @2;`.
@@ -297,7 +296,7 @@ export default grammar({
297
296
  // both struct-shaped and enum-shaped wire types use the generic `#[wire]`
298
297
  // attribute on ordinary `type` / `enum` declarations.
299
298
 
300
- // `reserved @N, @M;` inside a `#[wire] type` body reserves wire field
299
+ // `reserved @N, @M;` inside a `#[wire] type` or enum body reserves wire tag
301
300
  // numbers (hew-parser wire.rs:222-248 expects `@` markers, comma-separated,
302
301
  // terminated by `;`). The old parenthesised `reserved(N, M);` form is not
303
302
  // accepted by the compiler.
@@ -430,6 +429,7 @@ export default grammar({
430
429
  field('name', $.identifier),
431
430
  ':',
432
431
  field('type', $._type),
432
+ optional(seq('=', field('default', $.expression))),
433
433
  ),
434
434
  ),
435
435
 
@@ -584,7 +584,7 @@ export default grammar({
584
584
  ),
585
585
 
586
586
  // @sync:duration_suffixes
587
- duration_literal: $ => seq($.integer_literal, choice('ns', 'us', 'ms', 's', 'm', 'h')),
587
+ duration_literal: $ => token(seq(/[0-9][0-9_]*(\.[0-9][0-9_]*)?/, choice('ns', 'us', 'ms', 's', 'm', 'h'))),
588
588
 
589
589
  // ---- Machines ----
590
590
 
@@ -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(
@@ -1022,7 +1059,6 @@ export default grammar({
1022
1059
  // A bare spawn ends after its actor and optional brace-delimited keys.
1023
1060
  _callable_expression: $ => choice(
1024
1061
  $.identifier,
1025
- alias('capture', $.identifier),
1026
1062
  $.self,
1027
1063
  $._literal,
1028
1064
  $.interpolated_string,
@@ -1107,7 +1143,7 @@ export default grammar({
1107
1143
  )),
1108
1144
 
1109
1145
  macro_invocation: $ => prec(PREC.POSTFIX, seq(
1110
- field('name', choice($.identifier, alias('capture', $.identifier), $.path_expression)), '!',
1146
+ field('name', choice($.identifier, $.path_expression)), '!',
1111
1147
  field('arguments', alias($.macro_pattern, $.token_tree)),
1112
1148
  )),
1113
1149
 
@@ -1377,7 +1413,6 @@ export default grammar({
1377
1413
  // braced body (hew-parser/src/parser.rs:7691 parse_pipe_lambda).
1378
1414
  lambda: $ => prec.right(2, seq(
1379
1415
  optional('move'),
1380
- optional($.private_capture_list),
1381
1416
  field('parameters', choice(
1382
1417
  '||',
1383
1418
  seq('|', optional($.type_parameters), optional(sep1($.lambda_parameter, ',')), '|'),
@@ -1389,22 +1424,15 @@ export default grammar({
1389
1424
  ),
1390
1425
  )),
1391
1426
 
1392
- private_capture_list: $ => seq(
1393
- 'capture', '(', sep1($.private_capture, ','), optional(','), ')',
1394
- ),
1395
-
1396
- private_capture: $ => seq('var', field('name', $.identifier)),
1397
-
1398
1427
  lambda_parameter: $ => seq(
1399
1428
  field('name', $.identifier),
1400
1429
  optional(seq(':', field('type', $._type))),
1401
1430
  ),
1402
1431
 
1403
- // Actor literals share the closure prefix for private mutable captures.
1432
+ // Actor literals infer captured state from their bodies, like closures.
1404
1433
  actor_expression: $ => prec(2, seq(
1405
1434
  'actor',
1406
1435
  optional('move'),
1407
- optional($.private_capture_list),
1408
1436
  '|',
1409
1437
  optional(sep1($.lambda_parameter, ',')),
1410
1438
  '|',
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.3.1",
4
4
  "description": "Hew grammar for tree-sitter",
5
5
  "type": "module",
6
6
  "repository": {
@@ -40,7 +40,7 @@
40
40
  "devDependencies": {
41
41
  "prebuildify": "^6.0.1",
42
42
  "tree-sitter": "^0.25.0",
43
- "tree-sitter-cli": "0.25.10"
43
+ "tree-sitter-cli": "0.26.5"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "tree-sitter": "^0.25.0"
@@ -21,8 +21,6 @@
21
21
  (clone_expression "clone" @keyword.operator)
22
22
  (callable_capabilities ["var" "once" "clone" "suspends"] @keyword)
23
23
  (trait_method_effect "suspends" @keyword)
24
- (private_capture_list "capture" @keyword)
25
- (private_capture (identifier) @variable)
26
24
  (failure_return "fails" @keyword)
27
25
  (return_error_expression "error" @keyword)
28
26
  (defer_statement "err" @keyword)
@@ -50,6 +48,11 @@
50
48
  "mailbox" "overflow" "strategy" "intensity" "within"
51
49
  ] @keyword
52
50
 
51
+ (machine_state "final" @keyword)
52
+ (machine_parallel_state "parallel" @keyword)
53
+ (machine_region "region" @keyword)
54
+ (machine_transition ["history" "completion" "always"] @keyword)
55
+
53
56
  [
54
57
  "block" "drop_new" "drop_old" "fail" "coalesce" "fallback"
55
58
  ] @constant.builtin