jaclang 0.0.6__py3-none-any.whl → 0.0.8__py3-none-any.whl

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.

Potentially problematic release.


This version of jaclang might be problematic. Click here for more details.

Files changed (82) hide show
  1. jaclang/__init__.py +2 -1
  2. jaclang/cli/__jac_gen__/__init__.py +0 -0
  3. jaclang/cli/__jac_gen__/cli.py +175 -0
  4. jaclang/cli/__jac_gen__/cmds.py +132 -0
  5. jaclang/cli/cmds.jac +3 -0
  6. jaclang/cli/impl/__jac_gen__/__init__.py +0 -0
  7. jaclang/cli/impl/__jac_gen__/cli_impl.py +16 -0
  8. jaclang/cli/impl/__jac_gen__/cmds_impl.py +26 -0
  9. jaclang/cli/impl/cmds_impl.jac +17 -3
  10. jaclang/core/__jac_gen__/__init__.py +0 -0
  11. jaclang/core/__jac_gen__/primitives.py +567 -0
  12. jaclang/core/impl/__jac_gen__/__init__.py +0 -0
  13. jaclang/core/impl/__jac_gen__/arch_impl.py +24 -0
  14. jaclang/core/impl/__jac_gen__/element_impl.py +26 -0
  15. jaclang/core/impl/__jac_gen__/exec_ctx_impl.py +12 -0
  16. jaclang/core/impl/__jac_gen__/memory_impl.py +14 -0
  17. jaclang/core/impl/element_impl.jac +2 -2
  18. jaclang/core/primitives.jac +1 -0
  19. jaclang/jac/absyntree.py +65 -42
  20. jaclang/jac/constant.py +4 -0
  21. jaclang/jac/importer.py +18 -60
  22. jaclang/jac/langserve.py +26 -0
  23. jaclang/jac/lexer.py +9 -1
  24. jaclang/jac/parser.py +135 -123
  25. jaclang/jac/passes/blue/ast_build_pass.py +410 -353
  26. jaclang/jac/passes/blue/blue_pygen_pass.py +15 -0
  27. jaclang/jac/passes/blue/decl_def_match_pass.py +33 -21
  28. jaclang/jac/passes/blue/import_pass.py +1 -1
  29. jaclang/jac/passes/blue/pyout_pass.py +47 -12
  30. jaclang/jac/passes/blue/sym_tab_build_pass.py +38 -127
  31. jaclang/jac/passes/blue/tests/test_ast_build_pass.py +2 -2
  32. jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +9 -30
  33. jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +13 -13
  34. jaclang/jac/passes/blue/tests/test_sym_tab_build_pass.py +6 -4
  35. jaclang/jac/passes/ir_pass.py +1 -1
  36. jaclang/jac/passes/purple/__jac_gen__/__init__.py +0 -0
  37. jaclang/jac/passes/purple/__jac_gen__/analyze_pass.py +37 -0
  38. jaclang/jac/passes/purple/__jac_gen__/purple_pygen_pass.py +305 -0
  39. jaclang/jac/passes/purple/impl/__jac_gen__/__init__.py +0 -0
  40. jaclang/jac/passes/purple/impl/__jac_gen__/purple_pygen_pass_impl.py +23 -0
  41. jaclang/jac/symtable.py +12 -4
  42. jaclang/jac/tests/fixtures/__jac_gen__/__init__.py +0 -0
  43. jaclang/jac/tests/fixtures/__jac_gen__/hello_world.py +16 -0
  44. jaclang/jac/tests/fixtures/fam.jac +7 -8
  45. jaclang/jac/transform.py +4 -3
  46. jaclang/jac/transpiler.py +13 -9
  47. jaclang/utils/fstring_parser.py +2 -2
  48. jaclang/utils/helpers.py +41 -0
  49. jaclang/utils/test.py +30 -0
  50. jaclang/vendor/__init__.py +1 -0
  51. jaclang/vendor/pygls/__init__.py +25 -0
  52. jaclang/vendor/pygls/capabilities.py +502 -0
  53. jaclang/vendor/pygls/client.py +176 -0
  54. jaclang/vendor/pygls/constants.py +26 -0
  55. jaclang/vendor/pygls/exceptions.py +220 -0
  56. jaclang/vendor/pygls/feature_manager.py +241 -0
  57. jaclang/vendor/pygls/lsp/__init__.py +139 -0
  58. jaclang/vendor/pygls/lsp/client.py +2224 -0
  59. jaclang/vendor/pygls/lsprotocol/__init__.py +2 -0
  60. jaclang/vendor/pygls/lsprotocol/_hooks.py +1233 -0
  61. jaclang/vendor/pygls/lsprotocol/converters.py +17 -0
  62. jaclang/vendor/pygls/lsprotocol/types.py +12820 -0
  63. jaclang/vendor/pygls/lsprotocol/validators.py +47 -0
  64. jaclang/vendor/pygls/progress.py +79 -0
  65. jaclang/vendor/pygls/protocol.py +1184 -0
  66. jaclang/vendor/pygls/server.py +620 -0
  67. jaclang/vendor/pygls/uris.py +184 -0
  68. jaclang/vendor/pygls/workspace/__init__.py +81 -0
  69. jaclang/vendor/pygls/workspace/position.py +204 -0
  70. jaclang/vendor/pygls/workspace/text_document.py +234 -0
  71. jaclang/vendor/pygls/workspace/workspace.py +311 -0
  72. {jaclang-0.0.6.dist-info → jaclang-0.0.8.dist-info}/METADATA +1 -1
  73. jaclang-0.0.8.dist-info/RECORD +118 -0
  74. jaclang/core/jaclang.jac +0 -62
  75. jaclang-0.0.6.dist-info/RECORD +0 -76
  76. /jaclang/{utils → vendor}/sly/__init__.py +0 -0
  77. /jaclang/{utils → vendor}/sly/docparse.py +0 -0
  78. /jaclang/{utils → vendor}/sly/lex.py +0 -0
  79. /jaclang/{utils → vendor}/sly/yacc.py +0 -0
  80. {jaclang-0.0.6.dist-info → jaclang-0.0.8.dist-info}/WHEEL +0 -0
  81. {jaclang-0.0.6.dist-info → jaclang-0.0.8.dist-info}/entry_points.txt +0 -0
  82. {jaclang-0.0.6.dist-info → jaclang-0.0.8.dist-info}/top_level.txt +0 -0
@@ -2,7 +2,7 @@
2
2
  from os import path
3
3
 
4
4
  import jaclang.jac.absyntree as ast
5
- from jaclang.jac.absyntree import replace_node
5
+ from jaclang.jac.absyntree import append_node, replace_node
6
6
  from jaclang.jac.constant import EdgeDir
7
7
  from jaclang.jac.constant import Tokens as Tok
8
8
  from jaclang.jac.passes import Pass
@@ -68,31 +68,40 @@ class AstBuildPass(Pass):
68
68
  def exit_element(self, node: ast.AstNode) -> None:
69
69
  """Grammar rule.
70
70
 
71
- element -> enum
72
- element -> ability
73
- element -> architype
74
- element -> include_stmt
75
- element -> import_stmt
76
- element -> mod_code
77
- element -> test
78
- element -> global_var
71
+ Rule 5 element -> python_code_block
72
+ Rule 6 element -> doc_tag ability
73
+ Rule 7 element -> doc_tag architype
74
+ Rule 8 element -> include_stmt
75
+ Rule 9 element -> import_stmt
76
+ Rule 10 element -> doc_tag mod_code
77
+ Rule 11 element -> doc_tag test
78
+ Rule 12 element -> doc_tag global_var
79
79
  """
80
- replace_node(node, node.kid[0])
80
+ if len(node.kid) == 2:
81
+ doc = node.kid[0]
82
+ new_node = replace_node(node, node.kid[1])
83
+ if new_node and hasattr(new_node, "doc"):
84
+ new_node.doc = doc # type: ignore
85
+ append_node(new_node, doc, front=True)
86
+ else:
87
+ self.ice("Expected node to have doc attribute!")
88
+ else:
89
+ replace_node(node, node.kid[0])
81
90
 
82
91
  def exit_global_var(self, node: ast.AstNode) -> None:
83
92
  """Grammar rule.
84
93
 
85
- global_var -> doc_tag KW_FREEZE access_tag assignment_list SEMI
86
- global_var -> doc_tag KW_GLOBAL access_tag assignment_list SEMI
94
+ global_var -> KW_FREEZE access_tag assignment_list SEMI
95
+ global_var -> KW_GLOBAL access_tag assignment_list SEMI
87
96
  """
88
- is_frozen = node.kid[1].name == Tok.KW_FREEZE
89
- node.kid = [node.kid[0], node.kid[2], node.kid[3]]
97
+ is_frozen = node.kid[0].name == Tok.KW_FREEZE
98
+ node.kid = [node.kid[1], node.kid[2]]
90
99
  replace_node(
91
100
  node,
92
101
  ast.GlobalVars(
93
- doc=node.kid[0],
94
- access=node.kid[1],
95
- assignments=node.kid[2],
102
+ doc=None,
103
+ access=node.kid[0],
104
+ assignments=node.kid[1],
96
105
  is_frozen=is_frozen,
97
106
  parent=node.parent,
98
107
  mod_link=self.mod_link,
@@ -121,17 +130,17 @@ class AstBuildPass(Pass):
121
130
  def exit_test(self, node: ast.AstNode) -> None:
122
131
  """Grammar rule.
123
132
 
124
- test -> doc_tag KW_TEST code_block
125
- test -> doc_tag KW_TEST NAME code_block
133
+ test -> KW_TEST code_block
134
+ test -> KW_TEST NAME code_block
126
135
  """
127
- if len(node.kid) == 4:
128
- del node.kid[1]
136
+ if len(node.kid) == 3:
137
+ del node.kid[0]
129
138
  replace_node(
130
139
  node,
131
140
  ast.Test(
132
- doc=node.kid[0],
133
- name=node.kid[1],
134
- body=node.kid[2],
141
+ doc=None,
142
+ name=node.kid[0],
143
+ body=node.kid[1],
135
144
  parent=node.parent,
136
145
  mod_link=self.mod_link,
137
146
  kid=node.kid,
@@ -142,9 +151,9 @@ class AstBuildPass(Pass):
142
151
  replace_node(
143
152
  node,
144
153
  ast.Test(
145
- doc=node.kid[0],
146
- name=node.kid[1],
147
- body=node.kid[2],
154
+ doc=None,
155
+ name=node.kid[0],
156
+ body=node.kid[1],
148
157
  parent=node.parent,
149
158
  mod_link=self.mod_link,
150
159
  kid=node.kid,
@@ -155,17 +164,17 @@ class AstBuildPass(Pass):
155
164
  def exit_mod_code(self, node: ast.AstNode) -> None:
156
165
  """Grammar rule.
157
166
 
158
- mod_code -> doc_tag KW_WITH KW_ENTRY sub_name code_block
159
- mod_code -> doc_tag KW_WITH KW_ENTRY code_block
167
+ mod_code -> KW_WITH KW_ENTRY sub_name code_block
168
+ mod_code -> KW_WITH KW_ENTRY code_block
160
169
  """
161
- if len(node.kid) == 5:
162
- node.kid = [node.kid[0], node.kid[-2], node.kid[-1]]
170
+ if len(node.kid) == 4:
171
+ node.kid = [node.kid[-2], node.kid[-1]]
163
172
  replace_node(
164
173
  node,
165
174
  ast.ModuleCode(
166
- doc=node.kid[0],
167
- name=node.kid[1],
168
- body=node.kid[2],
175
+ doc=None,
176
+ name=node.kid[0],
177
+ body=node.kid[1],
169
178
  parent=node.parent,
170
179
  mod_link=self.mod_link,
171
180
  kid=node.kid,
@@ -173,13 +182,13 @@ class AstBuildPass(Pass):
173
182
  ),
174
183
  )
175
184
  else:
176
- node.kid = [node.kid[0], node.kid[-1]]
185
+ node.kid = [node.kid[-1]]
177
186
  replace_node(
178
187
  node,
179
188
  ast.ModuleCode(
180
- doc=node.kid[0],
189
+ doc=None,
181
190
  name=None,
182
- body=node.kid[1],
191
+ body=node.kid[0],
183
192
  parent=node.parent,
184
193
  mod_link=self.mod_link,
185
194
  kid=node.kid,
@@ -195,6 +204,22 @@ class AstBuildPass(Pass):
195
204
  """
196
205
  replace_node(node, node.kid[0])
197
206
 
207
+ def exit_python_code_block(self, node: ast.AstNode) -> None:
208
+ """Grammar rule.
209
+
210
+ python_code_block -> PYNLINE
211
+ """
212
+ replace_node(
213
+ node,
214
+ ast.PyInlineCode(
215
+ code=node.kid[0],
216
+ kid=node.kid,
217
+ parent=node.parent,
218
+ mod_link=self.mod_link,
219
+ line=node.line,
220
+ ),
221
+ )
222
+
198
223
  def exit_import_stmt(self, node: ast.AstNode) -> None:
199
224
  """Grammar rule.
200
225
 
@@ -346,29 +371,46 @@ class AstBuildPass(Pass):
346
371
  def exit_architype(self, node: ast.AstNode) -> None:
347
372
  """Grammar rule.
348
373
 
349
- architype -> architype_def
350
- architype -> architype_decl
351
- architype -> architype_inline_spec
374
+ Rule 41 architype -> decorator architype
375
+ Rule 42 architype -> enum
376
+ Rule 43 architype -> architype_def
377
+ Rule 44 architype -> architype_decl
352
378
  """
353
- replace_node(node, node.kid[0])
379
+ if len(node.kid) == 1:
380
+ replace_node(node, node.kid[0])
381
+ else:
382
+ dec = node.kid[0]
383
+ new_node = replace_node(node, node.kid[1])
384
+ if isinstance(new_node, ast.Architype) and new_node.decorators:
385
+ new_node.decorators.calls.insert(0, dec)
386
+ append_node(new_node.decorators, dec, front=True)
387
+ elif isinstance(new_node, ast.Architype):
388
+ new_node.decorators = ast.Decorators(
389
+ calls=[dec],
390
+ parent=new_node,
391
+ mod_link=self.mod_link,
392
+ kid=[dec],
393
+ line=node.line,
394
+ )
395
+ append_node(new_node, new_node.decorators, front=True)
396
+ else:
397
+ self.ice("Expected node to be architype!")
354
398
 
355
399
  def exit_architype_decl(self, node: ast.AstNode) -> None:
356
400
  """Grammar rule.
357
401
 
358
- architype_decl -> doc_tag decorators arch_type access_tag NAME inherited_archs member_block
359
- architype_decl -> doc_tag arch_type access_tag NAME inherited_archs member_block
360
- architype_decl -> doc_tag decorators arch_type access_tag NAME inherited_archs SEMI
361
- architype_decl -> doc_tag arch_type access_tag NAME inherited_archs SEMI
402
+ Rule 45 architype_decl -> arch_type access_tag NAME inherited_archs member_block
403
+ Rule 46 architype_decl -> arch_type access_tag NAME inherited_archs SEMI
362
404
  """
363
405
  replace_node(
364
406
  node,
365
407
  ast.Architype(
366
- doc=node.kid[0],
367
- decorators=node.kid[1] if len(node.kid) == 7 else None,
368
- arch_type=node.kid[2] if len(node.kid) == 7 else node.kid[1],
369
- access=node.kid[3] if len(node.kid) == 7 else node.kid[2],
370
- name=node.kid[4] if len(node.kid) == 7 else node.kid[3],
371
- base_classes=node.kid[5] if len(node.kid) == 7 else node.kid[4],
408
+ doc=None,
409
+ decorators=None,
410
+ arch_type=node.kid[0],
411
+ access=node.kid[1],
412
+ name=node.kid[2],
413
+ base_classes=node.kid[3],
372
414
  body=node.kid[-1] if isinstance(node.kid[-1], ast.ArchBlock) else None,
373
415
  parent=node.parent,
374
416
  mod_link=self.mod_link,
@@ -382,19 +424,17 @@ class AstBuildPass(Pass):
382
424
  def exit_architype_def(self, node: ast.AstNode) -> None:
383
425
  """Grammar rule.
384
426
 
385
- architype_def -> doc_tag dotted_name strict_arch_ref member_block
386
- architype_def -> doc_tag strict_arch_ref member_block
427
+ architype_def -> abil_to_arch_chain member_block
387
428
  """
388
429
  replace_node(
389
430
  node,
390
431
  ast.ArchDef(
391
- doc=node.kid[0],
392
- mod=node.kid[1] if len(node.kid) == 4 else None,
393
- arch=node.kid[2] if len(node.kid) == 4 else node.kid[1],
394
- body=node.kid[-1],
432
+ doc=None,
433
+ target=node.kid[0],
434
+ body=node.kid[1],
395
435
  parent=node.parent,
396
436
  mod_link=self.mod_link,
397
- kid=node.kid,
437
+ kid=[node.kid[1]],
398
438
  line=node.line,
399
439
  ),
400
440
  )
@@ -409,26 +449,12 @@ class AstBuildPass(Pass):
409
449
  """
410
450
  replace_node(node, node.kid[0])
411
451
 
412
- def exit_decorators(self, node: ast.AstNode) -> None:
452
+ def exit_decorator(self, node: ast.AstNode) -> None:
413
453
  """Grammar rule.
414
454
 
415
- decorators -> decorators DECOR_OP atom
416
- decorators -> DECOR_OP atom
455
+ decorator -> DECOR_OP atom
417
456
  """
418
- if len(node.kid) == 3:
419
- node.kid = node.kid[0].kid + [node.kid[2]]
420
- else:
421
- node.kid = [node.kid[1]]
422
- replace_node(
423
- node,
424
- ast.Decorators(
425
- calls=node.kid,
426
- parent=node.parent,
427
- mod_link=self.mod_link,
428
- kid=node.kid,
429
- line=node.line,
430
- ),
431
- )
457
+ replace_node(node, node.kid[1])
432
458
 
433
459
  def exit_inherited_archs(self, node: ast.AstNode) -> None:
434
460
  """Grammar rule.
@@ -503,8 +529,8 @@ class AstBuildPass(Pass):
503
529
  def exit_named_refs(self, node: ast.AstNode) -> None:
504
530
  """Grammar rule.
505
531
 
506
- named_refs -> NAME
507
- named_refs -> arch_ref
532
+ Rule 63 named_refs -> global_ref
533
+ Rule 64 named_refs -> esc_name
508
534
  """
509
535
  replace_node(node, node.kid[0])
510
536
 
@@ -528,46 +554,30 @@ class AstBuildPass(Pass):
528
554
  ),
529
555
  )
530
556
 
531
- def exit_ability(self, node: ast.AstNode) -> None:
557
+ def exit_enum(self, node: ast.AstNode) -> None:
532
558
  """Grammar rule.
533
559
 
534
- ability -> ability_def
535
- ability -> KW_ASYNC ability_decl
536
- ability -> ability_decl
560
+ enum -> enum_def
561
+ enum -> enum_decl
537
562
  """
538
- if len(node.kid) == 2:
539
- new_node = replace_node(node, node.kid[1])
540
- if isinstance(new_node, ast.Ability):
541
- new_node.is_async = True
542
- else:
543
- replace_node(node, node.kid[0])
563
+ replace_node(node, node.kid[0])
544
564
 
545
- def exit_ability_decl(self, node: ast.AstNode) -> None:
565
+ def exit_enum_decl(self, node: ast.AstNode) -> None:
546
566
  """Grammar rule.
547
567
 
548
- ability_decl -> ability_decl_decor
549
- ability_decl -> doc_tag static_tag KW_CAN access_tag all_refs func_decl code_block
550
- ability_decl -> doc_tag static_tag KW_CAN access_tag all_refs event_clause code_block
551
- ability_decl -> doc_tag static_tag KW_CAN access_tag all_refs func_decl SEMI
552
- ability_decl -> doc_tag static_tag KW_CAN access_tag all_refs event_clause SEMI
568
+ Rule 72 enum_decl -> KW_ENUM access_tag NAME inherited_archs enum_block
569
+ Rule 73 enum_decl -> KW_ENUM access_tag NAME inherited_archs SEMI
553
570
  """
554
- if len(node.kid) == 1:
555
- replace_node(node, node.kid[0])
556
- return
557
- del node.kid[2]
571
+ del node.kid[0]
558
572
  replace_node(
559
573
  node,
560
- ast.Ability(
561
- doc=node.kid[0],
562
- access=node.kid[2],
563
- is_static=node.kid[1],
564
- is_abstract=False,
565
- name_ref=node.kid[3],
566
- body=node.kid[-1] if isinstance(node.kid[-1], ast.CodeBlock) else None,
567
- signature=node.kid[-2],
568
- is_func=isinstance(node.kid[-2], ast.FuncSignature),
569
- is_async=False,
574
+ ast.Enum(
575
+ doc=None,
570
576
  decorators=None,
577
+ access=node.kid[0],
578
+ name=node.kid[1],
579
+ base_classes=node.kid[2],
580
+ body=node.kid[-1] if isinstance(node.kid[-1], ast.EnumBlock) else None,
571
581
  parent=node.parent,
572
582
  mod_link=self.mod_link,
573
583
  kid=node.kid,
@@ -577,28 +587,131 @@ class AstBuildPass(Pass):
577
587
  if isinstance(node.kid[-1], ast.Token):
578
588
  del node.kid[-1]
579
589
 
580
- def exit_ability_decl_decor(self, node: ast.AstNode) -> None:
590
+ def exit_enum_def(self, node: ast.AstNode) -> None:
581
591
  """Grammar rule.
582
592
 
583
- ability_decl_decor -> doc_tag decorators static_tag KW_CAN access_tag all_refs func_decl code_block
584
- ability_decl_decor -> doc_tag decorators static_tag KW_CAN access_tag all_refs event_clause code_block
585
- ability_decl_decor -> doc_tag decorators static_tag KW_CAN access_tag all_refs func_decl SEMI
586
- ability_decl_decor -> doc_tag decorators static_tag KW_CAN access_tag all_refs event_clause SEMI
593
+ Rule 74 enum_def -> arch_to_enum_chain enum_block
587
594
  """
588
- del node.kid[3]
595
+ replace_node(
596
+ node,
597
+ ast.EnumDef(
598
+ doc=None,
599
+ target=node.kid[0],
600
+ body=node.kid[-1],
601
+ parent=node.parent,
602
+ mod_link=self.mod_link,
603
+ kid=node.kid,
604
+ line=node.line,
605
+ ),
606
+ )
607
+
608
+ def exit_enum_block(self, node: ast.AstNode) -> None:
609
+ """Grammar rule.
610
+
611
+ enum_block -> LBRACE enum_stmt_list RBRACE
612
+ enum_block -> LBRACE RBRACE
613
+ """
614
+ if len(node.kid) == 3:
615
+ ret = replace_node(node, node.kid[1])
616
+ node = ret if ret else node
617
+ else:
618
+ node.kid = []
619
+ replace_node(
620
+ node,
621
+ ast.EnumBlock(
622
+ stmts=node.kid,
623
+ parent=node.parent,
624
+ mod_link=self.mod_link,
625
+ kid=node.kid,
626
+ line=node.line,
627
+ ),
628
+ )
629
+
630
+ def exit_enum_stmt_list(self, node: ast.AstNode) -> None:
631
+ """Grammar rule.
632
+
633
+ enum_stmt_list -> enum_stmt_list COMMA enum_op_assign
634
+ enum_stmt_list -> enum_stmt_list COMMA NAME
635
+ enum_stmt_list -> enum_op_assign
636
+ enum_stmt_list -> NAME
637
+ """
638
+ if len(node.kid) == 3:
639
+ node.kid = node.kid[0].kid + [node.kid[2]]
640
+
641
+ def exit_enum_op_assign(self, node: ast.AstNode) -> None:
642
+ """Grammar rule.
643
+
644
+ enum_op_assign -> NAME EQ expression
645
+ """
646
+ del node.kid[1]
647
+ replace_node(
648
+ node,
649
+ ast.Assignment(
650
+ target=node.kid[0],
651
+ value=node.kid[1],
652
+ mutable=False,
653
+ is_static=False,
654
+ parent=node.parent,
655
+ mod_link=self.mod_link,
656
+ kid=node.kid,
657
+ line=node.line,
658
+ ),
659
+ )
660
+
661
+ def exit_ability(self, node: ast.AstNode) -> None:
662
+ """Grammar rule.
663
+
664
+ Rule 82 ability -> decorator ability
665
+ Rule 83 ability -> ability_def
666
+ Rule 84 ability -> KW_ASYNC ability_decl
667
+ Rule 85 ability -> ability_decl
668
+ """
669
+ if len(node.kid) == 2 and isinstance(node.kid[0], ast.Token):
670
+ new_node = replace_node(node, node.kid[1])
671
+ if isinstance(new_node, ast.Ability):
672
+ new_node.is_async = True
673
+ elif len(node.kid) == 2:
674
+ dec = node.kid[0]
675
+ new_node = replace_node(node, node.kid[1])
676
+ if isinstance(new_node, ast.Ability) and new_node.decorators:
677
+ new_node.decorators.calls.insert(0, dec)
678
+ append_node(new_node.decorators, dec, front=True)
679
+ elif isinstance(new_node, ast.Ability):
680
+ new_node.decorators = ast.Decorators(
681
+ calls=[dec],
682
+ parent=new_node,
683
+ mod_link=self.mod_link,
684
+ kid=[dec],
685
+ line=node.line,
686
+ )
687
+ append_node(new_node, new_node.decorators, front=True)
688
+ else:
689
+ self.ice("Expected node to be ability!")
690
+ else:
691
+ replace_node(node, node.kid[0])
692
+
693
+ def exit_ability_decl(self, node: ast.AstNode) -> None:
694
+ """Grammar rule.
695
+
696
+ Rule 86 ability_decl -> static_tag KW_CAN access_tag all_refs func_decl code_block
697
+ Rule 87 ability_decl -> static_tag KW_CAN access_tag all_refs event_clause code_block
698
+ Rule 88 ability_decl -> static_tag KW_CAN access_tag all_refs func_decl SEMI
699
+ Rule 89 ability_decl -> static_tag KW_CAN access_tag all_refs event_clause SEMI
700
+ """
701
+ del node.kid[1]
589
702
  replace_node(
590
703
  node,
591
704
  ast.Ability(
592
- doc=node.kid[0],
593
- decorators=node.kid[1],
594
- is_static=node.kid[2],
705
+ doc=None,
706
+ access=node.kid[1],
707
+ is_static=node.kid[0],
595
708
  is_abstract=False,
596
- access=node.kid[3],
597
- name_ref=node.kid[4],
709
+ name_ref=node.kid[2],
598
710
  body=node.kid[-1] if isinstance(node.kid[-1], ast.CodeBlock) else None,
599
711
  signature=node.kid[-2],
600
712
  is_func=isinstance(node.kid[-2], ast.FuncSignature),
601
713
  is_async=False,
714
+ decorators=None,
602
715
  parent=node.parent,
603
716
  mod_link=self.mod_link,
604
717
  kid=node.kid,
@@ -611,17 +724,14 @@ class AstBuildPass(Pass):
611
724
  def exit_ability_def(self, node: ast.AstNode) -> None:
612
725
  """Grammar rule.
613
726
 
614
- ability_def -> doc_tag dotted_name ability_ref func_decl code_block
615
- ability_def -> doc_tag ability_ref func_decl code_block
616
- ability_def -> doc_tag dotted_name ability_ref event_clause code_block
617
- ability_def -> doc_tag ability_ref event_clause code_block
727
+ Rule 90 ability_def -> arch_to_abil_chain func_decl code_block
728
+ Rule 91 ability_def -> arch_to_abil_chain event_clause code_block
618
729
  """
619
730
  replace_node(
620
731
  node,
621
732
  ast.AbilityDef(
622
- doc=node.kid[0],
623
- target=node.kid[1] if len(node.kid) == 5 else None,
624
- ability=node.kid[2] if len(node.kid) == 5 else node.kid[1],
733
+ doc=None,
734
+ target=node.kid[0],
625
735
  signature=node.kid[-2],
626
736
  body=node.kid[-1],
627
737
  parent=node.parent,
@@ -634,61 +744,30 @@ class AstBuildPass(Pass):
634
744
  def exit_abstract_ability(self, node: ast.AstNode) -> None:
635
745
  """Grammar rule.
636
746
 
637
- abstract_ability -> doc_tag decorators static_tag KW_CAN access_tag all_refs func_decl KW_ABSTRACT SEMI
638
- abstract_ability -> doc_tag decorators static_tag KW_CAN access_tag all_refs event_clause KW_ABSTRACT SEMI
639
- abstract_ability -> doc_tag static_tag KW_CAN access_tag all_refs func_decl KW_ABSTRACT SEMI
640
- abstract_ability -> doc_tag static_tag KW_CAN access_tag all_refs event_clause KW_ABSTRACT SEMI
747
+ Rule 92 abstract_ability -> static_tag KW_CAN access_tag all_refs func_decl KW_ABSTRACT SEMI
748
+ Rule 93 abstract_ability -> static_tag KW_CAN access_tag all_refs event_clause KW_ABSTRACT SEMI
641
749
  """
642
- if isinstance(node.kid[1], ast.Decorators):
643
- del node.kid[3]
644
- replace_node(
645
- node,
646
- ast.Ability(
647
- doc=node.kid[0],
648
- decorators=node.kid[1],
649
- is_static=node.kid[2],
650
- is_abstract=True,
651
- access=node.kid[3],
652
- name_ref=node.kid[4],
653
- body=node.kid[-1]
654
- if isinstance(node.kid[-1], ast.CodeBlock)
655
- else None,
656
- signature=node.kid[-2],
657
- is_func=isinstance(node.kid[-2], ast.FuncSignature),
658
- is_async=False,
659
- parent=node.parent,
660
- mod_link=self.mod_link,
661
- kid=node.kid,
662
- line=node.line,
663
- ),
664
- )
665
- if isinstance(node.kid[-1], ast.Token):
666
- del node.kid[-1]
667
- else:
668
- del node.kid[2]
669
- replace_node(
670
- node,
671
- ast.Ability(
672
- doc=node.kid[0],
673
- access=node.kid[2],
674
- is_static=node.kid[1],
675
- is_abstract=True,
676
- name_ref=node.kid[3],
677
- body=node.kid[-1]
678
- if isinstance(node.kid[-1], ast.CodeBlock)
679
- else None,
680
- signature=node.kid[-2],
681
- is_func=isinstance(node.kid[-2], ast.FuncSignature),
682
- is_async=False,
683
- decorators=None,
684
- parent=node.parent,
685
- mod_link=self.mod_link,
686
- kid=node.kid,
687
- line=node.line,
688
- ),
689
- )
690
- if isinstance(node.kid[-1], ast.Token):
691
- del node.kid[-1]
750
+ del node.kid[1]
751
+ del node.kid[-2:]
752
+ replace_node(
753
+ node,
754
+ ast.Ability(
755
+ doc=None,
756
+ access=node.kid[1],
757
+ is_static=node.kid[0],
758
+ is_abstract=True,
759
+ name_ref=node.kid[2],
760
+ body=None,
761
+ signature=node.kid[-1],
762
+ is_func=isinstance(node.kid[-1], ast.FuncSignature),
763
+ is_async=False,
764
+ decorators=None,
765
+ parent=node.parent,
766
+ mod_link=self.mod_link,
767
+ kid=node.kid,
768
+ line=node.line,
769
+ ),
770
+ )
692
771
 
693
772
  def exit_event_clause(self, node: ast.AstNode) -> None:
694
773
  """Grammar rule.
@@ -815,135 +894,6 @@ class AstBuildPass(Pass):
815
894
  ),
816
895
  )
817
896
 
818
- def exit_enum(self, node: ast.AstNode) -> None:
819
- """Grammar rule.
820
-
821
- enum -> enum_def
822
- enum -> enum_decl
823
- """
824
- replace_node(node, node.kid[0])
825
-
826
- def exit_enum_decl(self, node: ast.AstNode) -> None:
827
- """Grammar rule.
828
-
829
- enum_decl -> doc_tag decorators KW_ENUM access_tag NAME inherited_archs enum_block
830
- enum_decl -> doc_tag decorators KW_ENUM access_tag NAME inherited_archs SEMI
831
- enum_decl -> doc_tag KW_ENUM access_tag NAME inherited_archs enum_block
832
- enum_decl -> doc_tag KW_ENUM access_tag NAME inherited_archs SEMI
833
- """
834
- if isinstance(node.kid[1], ast.Token):
835
- del node.kid[1]
836
- replace_node(
837
- node,
838
- ast.Enum(
839
- doc=node.kid[0],
840
- decorators=None,
841
- access=node.kid[1],
842
- name=node.kid[2],
843
- base_classes=node.kid[3],
844
- body=node.kid[-1]
845
- if isinstance(node.kid[-1], ast.EnumBlock)
846
- else None,
847
- parent=node.parent,
848
- mod_link=self.mod_link,
849
- kid=node.kid,
850
- line=node.line,
851
- ),
852
- )
853
- else:
854
- replace_node(
855
- node,
856
- ast.Enum(
857
- doc=node.kid[0],
858
- decorators=node.kid[1],
859
- access=node.kid[2],
860
- name=node.kid[3],
861
- base_classes=node.kid[4],
862
- body=node.kid[-1]
863
- if isinstance(node.kid[-1], ast.EnumBlock)
864
- else None,
865
- parent=node.parent,
866
- mod_link=self.mod_link,
867
- kid=node.kid,
868
- line=node.line,
869
- ),
870
- )
871
- if isinstance(node.kid[-1], ast.Token):
872
- del node.kid[-1]
873
-
874
- def exit_enum_def(self, node: ast.AstNode) -> None:
875
- """Grammar rule.
876
-
877
- enum_def -> doc_tag dotted_name enum_ref enum_block
878
- enum_def -> doc_tag enum_ref enum_block
879
- """
880
- replace_node(
881
- node,
882
- ast.EnumDef(
883
- doc=node.kid[0],
884
- enum=node.kid[-2],
885
- mod=node.kid[1] if len(node.kid) == 4 else None,
886
- body=node.kid[-1],
887
- parent=node.parent,
888
- mod_link=self.mod_link,
889
- kid=node.kid,
890
- line=node.line,
891
- ),
892
- )
893
-
894
- def exit_enum_block(self, node: ast.AstNode) -> None:
895
- """Grammar rule.
896
-
897
- enum_block -> LBRACE enum_stmt_list RBRACE
898
- enum_block -> LBRACE RBRACE
899
- """
900
- if len(node.kid) == 3:
901
- ret = replace_node(node, node.kid[1])
902
- node = ret if ret else node
903
- else:
904
- node.kid = []
905
- replace_node(
906
- node,
907
- ast.EnumBlock(
908
- stmts=node.kid,
909
- parent=node.parent,
910
- mod_link=self.mod_link,
911
- kid=node.kid,
912
- line=node.line,
913
- ),
914
- )
915
-
916
- def exit_enum_stmt_list(self, node: ast.AstNode) -> None:
917
- """Grammar rule.
918
-
919
- enum_stmt_list -> enum_stmt_list COMMA enum_op_assign
920
- enum_stmt_list -> enum_stmt_list COMMA NAME
921
- enum_stmt_list -> enum_op_assign
922
- enum_stmt_list -> NAME
923
- """
924
- if len(node.kid) == 3:
925
- node.kid = node.kid[0].kid + [node.kid[2]]
926
-
927
- def exit_enum_op_assign(self, node: ast.AstNode) -> None:
928
- """Grammar rule.
929
-
930
- enum_op_assign -> NAME EQ expression
931
- """
932
- del node.kid[1]
933
- replace_node(
934
- node,
935
- ast.Assignment(
936
- target=node.kid[0],
937
- value=node.kid[1],
938
- mutable=False,
939
- is_static=False,
940
- parent=node.parent,
941
- mod_link=self.mod_link,
942
- kid=node.kid,
943
- line=node.line,
944
- ),
945
- )
946
-
947
897
  def exit_member_block(self, node: ast.AstNode) -> None:
948
898
  """Grammar rule.
949
899
 
@@ -978,26 +928,38 @@ class AstBuildPass(Pass):
978
928
  def exit_member_stmt(self, node: ast.AstNode) -> None:
979
929
  """Grammar rule.
980
930
 
981
- member_stmt -> ability
982
- member_stmt -> has_stmt
931
+ Rule 113 member_stmt -> python_code_block
932
+ Rule 114 member_stmt -> doc_tag abstract_ability
933
+ Rule 115 member_stmt -> doc_tag ability
934
+ Rule 116 member_stmt -> doc_tag architype
935
+ Rule 117 member_stmt -> doc_tag has_stmt
983
936
  """
984
- replace_node(node, node.kid[0])
937
+ if len(node.kid) == 2:
938
+ doc = node.kid[0]
939
+ new_node = replace_node(node, node.kid[-1])
940
+ if new_node and hasattr(new_node, "doc"):
941
+ new_node.doc = doc # type: ignore
942
+ append_node(new_node, doc, front=True)
943
+ else:
944
+ self.ice("Expected node to have doc attribute!")
945
+ else:
946
+ replace_node(node, node.kid[0])
985
947
 
986
948
  def exit_has_stmt(self, node: ast.AstNode) -> None:
987
949
  """Grammar rule.
988
950
 
989
- has_stmt -> doc_tag static_tag KW_FREEZE access_tag has_assign_clause SEMI
990
- has_stmt -> doc_tag static_tag KW_HAS access_tag has_assign_clause SEMI
951
+ Rule 119 has_stmt -> static_tag KW_FREEZE access_tag has_assign_clause SEMI
952
+ Rule 120 has_stmt -> static_tag KW_HAS access_tag has_assign_clause SEMI
991
953
  """
992
- is_frozen = node.kid[2].name == Tok.KW_FREEZE
993
- node.kid = [node.kid[0], node.kid[1], node.kid[3], node.kid[4]]
954
+ is_frozen = node.kid[1].name == Tok.KW_FREEZE
955
+ node.kid = [node.kid[0], node.kid[2], node.kid[3]]
994
956
  replace_node(
995
957
  node,
996
958
  ast.ArchHas(
997
- doc=node.kid[0],
998
- is_static=node.kid[1],
999
- access=node.kid[2],
1000
- vars=node.kid[3],
959
+ doc=None,
960
+ is_static=node.kid[0],
961
+ access=node.kid[1],
962
+ vars=node.kid[2],
1001
963
  is_frozen=is_frozen,
1002
964
  parent=node.parent,
1003
965
  mod_link=self.mod_link,
@@ -1187,27 +1149,57 @@ class AstBuildPass(Pass):
1187
1149
  def exit_statement(self, node: ast.AstNode) -> None:
1188
1150
  """Grammar rule.
1189
1151
 
1190
- statement -> walker_stmt
1191
- statement -> await_stmt SEMI
1192
- statement -> yield_stmt SEMI
1193
- statement -> return_stmt SEMI
1194
- statement -> report_stmt SEMI
1195
- statement -> delete_stmt SEMI
1196
- statement -> ctrl_stmt SEMI
1197
- statement -> assert_stmt SEMI
1198
- statement -> raise_stmt SEMI
1199
- statement -> with_ctx_stmt
1200
- statement -> while_stmt
1201
- statement -> for_stmt
1202
- statement -> try_stmt
1203
- statement -> if_stmt
1204
- statement -> expression SEMI
1205
- statement -> static_assignment
1206
- statement -> assignment SEMI
1207
- statement -> ability_decl
1208
- statement -> architype_decl
1209
- """
1210
- replace_node(node, node.kid[0])
1152
+ Rule 155 statement -> python_code_block
1153
+ Rule 156 statement -> walker_stmt
1154
+ Rule 157 statement -> await_stmt SEMI
1155
+ Rule 158 statement -> yield_stmt SEMI
1156
+ Rule 159 statement -> return_stmt SEMI
1157
+ Rule 160 statement -> report_stmt SEMI
1158
+ Rule 161 statement -> delete_stmt SEMI
1159
+ Rule 162 statement -> ctrl_stmt SEMI
1160
+ Rule 163 statement -> assert_stmt SEMI
1161
+ Rule 164 statement -> raise_stmt SEMI
1162
+ Rule 165 statement -> with_stmt
1163
+ Rule 166 statement -> while_stmt
1164
+ Rule 167 statement -> for_stmt
1165
+ Rule 168 statement -> try_stmt
1166
+ Rule 169 statement -> if_stmt
1167
+ Rule 170 statement -> expression SEMI
1168
+ Rule 171 statement -> static_assignment
1169
+ Rule 172 statement -> assignment SEMI
1170
+ Rule 173 statement -> typed_ctx_block
1171
+ Rule 174 statement -> doc_tag ability
1172
+ Rule 175 statement -> doc_tag architype
1173
+ Rule 176 statement -> import_stmt
1174
+ """
1175
+ if isinstance(
1176
+ node.kid[-1],
1177
+ (
1178
+ ast.Architype,
1179
+ ast.ArchDef,
1180
+ ast.Enum,
1181
+ ast.EnumDef,
1182
+ ast.Ability,
1183
+ ast.AbilityDef,
1184
+ ),
1185
+ ):
1186
+ doc = node.kid[0]
1187
+ new_node = replace_node(node, node.kid[-1])
1188
+ if isinstance(
1189
+ new_node,
1190
+ (
1191
+ ast.Architype,
1192
+ ast.ArchDef,
1193
+ ast.Enum,
1194
+ ast.EnumDef,
1195
+ ast.Ability,
1196
+ ast.AbilityDef,
1197
+ ),
1198
+ ):
1199
+ new_node.doc = doc
1200
+ append_node(new_node, doc, front=True)
1201
+ else:
1202
+ replace_node(node, node.kid[0])
1211
1203
 
1212
1204
  def exit_typed_ctx_block(self, node: ast.AstNode) -> None:
1213
1205
  """Grammar rule.
@@ -2638,7 +2630,6 @@ class AstBuildPass(Pass):
2638
2630
  """Grammar rule.
2639
2631
 
2640
2632
  atomic_chain_unsafe -> atom filter_compr
2641
- atomic_chain_unsafe -> atom arch_ref
2642
2633
  atomic_chain_unsafe -> atom index_slice
2643
2634
  atomic_chain_unsafe -> atom DOT NAME
2644
2635
  atomic_chain_unsafe -> atom DOT_FWD NAME
@@ -2668,7 +2659,6 @@ class AstBuildPass(Pass):
2668
2659
  """Grammar rule.
2669
2660
 
2670
2661
  atomic_chain_safe -> atom NULL_OK filter_compr
2671
- atomic_chain_safe -> atom NULL_OK arch_ref
2672
2662
  atomic_chain_safe -> atom NULL_OK index_slice
2673
2663
  atomic_chain_safe -> atom NULL_OK DOT NAME
2674
2664
  atomic_chain_safe -> atom NULL_OK DOT_FWD NAME
@@ -2879,23 +2869,90 @@ class AstBuildPass(Pass):
2879
2869
  def exit_arch_ref(self, node: ast.AstNode) -> None:
2880
2870
  """Grammar rule.
2881
2871
 
2882
- arch_ref -> ability_ref
2883
- arch_ref -> object_ref
2884
- arch_ref -> walker_ref
2885
- arch_ref -> edge_ref
2886
- arch_ref -> node_ref
2872
+ Rule 392 arch_ref -> object_ref
2873
+ Rule 393 arch_ref -> walker_ref
2874
+ Rule 394 arch_ref -> edge_ref
2875
+ Rule 395 arch_ref -> node_ref
2887
2876
  """
2888
2877
  replace_node(node, node.kid[0])
2889
2878
 
2890
- def exit_strict_arch_ref(self, node: ast.AstNode) -> None:
2879
+ def exit_arch_or_ability_chain(self, node: ast.AstNode) -> None:
2891
2880
  """Grammar rule.
2892
2881
 
2893
- strict_arch_ref -> object_ref
2894
- strict_arch_ref -> walker_ref
2895
- strict_arch_ref -> edge_ref
2896
- strict_arch_ref -> node_ref
2882
+ Rule 396 arch_or_ability_chain -> arch_or_ability_chain ability_ref
2883
+ Rule 397 arch_or_ability_chain -> arch_or_ability_chain arch_ref
2884
+ Rule 398 arch_or_ability_chain -> ability_ref
2885
+ Rule 399 arch_or_ability_chain -> arch_ref
2897
2886
  """
2898
- replace_node(node, node.kid[0])
2887
+ if len(node.kid) == 2:
2888
+ node.kid = node.kid[0].kid + [node.kid[1]]
2889
+ replace_node(
2890
+ node,
2891
+ ast.ArchRefChain(
2892
+ archs=node.kid,
2893
+ parent=node.parent,
2894
+ mod_link=self.mod_link,
2895
+ kid=node.kid,
2896
+ line=node.line,
2897
+ ),
2898
+ )
2899
+
2900
+ def exit_abil_to_arch_chain(self, node: ast.AstNode) -> None:
2901
+ """Grammar rule.
2902
+
2903
+ Rule 400 abil_to_arch_chain -> arch_or_ability_chain arch_ref
2904
+ Rule 401 abil_to_arch_chain -> arch_ref
2905
+ """
2906
+ if len(node.kid) == 2:
2907
+ node.kid = node.kid[0].kid + [node.kid[1]]
2908
+ replace_node(
2909
+ node,
2910
+ ast.ArchRefChain(
2911
+ archs=node.kid,
2912
+ parent=node.parent,
2913
+ mod_link=self.mod_link,
2914
+ kid=node.kid,
2915
+ line=node.line,
2916
+ ),
2917
+ )
2918
+
2919
+ def exit_arch_to_abil_chain(self, node: ast.AstNode) -> None:
2920
+ """Grammar rule.
2921
+
2922
+ Rule 402 arch_to_abil_chain -> arch_or_ability_chain ability_ref
2923
+ Rule 403 arch_to_abil_chain -> ability_ref
2924
+ """
2925
+ if len(node.kid) == 2:
2926
+ node.kid = node.kid[0].kid + [node.kid[1]]
2927
+ replace_node(
2928
+ node,
2929
+ ast.ArchRefChain(
2930
+ archs=node.kid,
2931
+ parent=node.parent,
2932
+ mod_link=self.mod_link,
2933
+ kid=node.kid,
2934
+ line=node.line,
2935
+ ),
2936
+ )
2937
+
2938
+ def exit_arch_to_enum_chain(self, node: ast.AstNode) -> None:
2939
+ """Grammar rule.
2940
+
2941
+ Rule 404 arch_to_enum_chain -> arch_or_ability_chain enum_ref
2942
+ Rule 405 arch_to_enum_chain -> enum_ref
2943
+ """
2944
+ if len(node.kid) == 2:
2945
+ node.kid = node.kid[0].kid + [node.kid[1]]
2946
+ replace_node(
2947
+ node,
2948
+ ast.ArchRefChain(
2949
+ archs=node.kid,
2950
+ parent=node.parent,
2951
+ mod_link=self.mod_link,
2952
+ kid=node.kid,
2953
+ line=node.line,
2954
+ ),
2955
+ )
2899
2956
 
2900
2957
  def exit_node_ref(self, node: ast.AstNode) -> None:
2901
2958
  """Grammar rule.