jaclang 0.0.5__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 (94) 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/cli.jac +2 -2
  6. jaclang/cli/cmds.jac +8 -2
  7. jaclang/cli/impl/__jac_gen__/__init__.py +0 -0
  8. jaclang/cli/impl/__jac_gen__/cli_impl.py +16 -0
  9. jaclang/cli/impl/__jac_gen__/cmds_impl.py +26 -0
  10. jaclang/cli/impl/cli_impl.jac +25 -8
  11. jaclang/cli/impl/cmds_impl.jac +35 -6
  12. jaclang/core/__jac_gen__/__init__.py +0 -0
  13. jaclang/core/__jac_gen__/primitives.py +567 -0
  14. jaclang/core/impl/__jac_gen__/__init__.py +0 -0
  15. jaclang/core/impl/__jac_gen__/arch_impl.py +24 -0
  16. jaclang/core/impl/__jac_gen__/element_impl.py +26 -0
  17. jaclang/core/impl/__jac_gen__/exec_ctx_impl.py +12 -0
  18. jaclang/core/impl/__jac_gen__/memory_impl.py +14 -0
  19. jaclang/core/impl/element_impl.jac +3 -3
  20. jaclang/core/impl/exec_ctx_impl.jac +3 -6
  21. jaclang/core/primitives.jac +4 -3
  22. jaclang/jac/absyntree.py +555 -180
  23. jaclang/jac/constant.py +6 -0
  24. jaclang/jac/importer.py +34 -56
  25. jaclang/jac/langserve.py +26 -0
  26. jaclang/jac/lexer.py +35 -3
  27. jaclang/jac/parser.py +146 -115
  28. jaclang/jac/passes/blue/__init__.py +8 -3
  29. jaclang/jac/passes/blue/ast_build_pass.py +454 -305
  30. jaclang/jac/passes/blue/blue_pygen_pass.py +112 -74
  31. jaclang/jac/passes/blue/decl_def_match_pass.py +49 -277
  32. jaclang/jac/passes/blue/import_pass.py +1 -1
  33. jaclang/jac/passes/blue/pyout_pass.py +74 -0
  34. jaclang/jac/passes/blue/semantic_check_pass.py +37 -0
  35. jaclang/jac/passes/blue/sym_tab_build_pass.py +1045 -0
  36. jaclang/jac/passes/blue/tests/test_ast_build_pass.py +2 -2
  37. jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +9 -28
  38. jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +13 -22
  39. jaclang/jac/passes/blue/tests/test_sym_tab_build_pass.py +22 -0
  40. jaclang/jac/passes/ir_pass.py +8 -6
  41. jaclang/jac/passes/purple/__jac_gen__/__init__.py +0 -0
  42. jaclang/jac/passes/purple/__jac_gen__/analyze_pass.py +37 -0
  43. jaclang/jac/passes/purple/__jac_gen__/purple_pygen_pass.py +305 -0
  44. jaclang/jac/passes/purple/impl/__jac_gen__/__init__.py +0 -0
  45. jaclang/jac/passes/purple/impl/__jac_gen__/purple_pygen_pass_impl.py +23 -0
  46. jaclang/jac/passes/purple/impl/purple_pygen_pass_impl.jac +2 -5
  47. jaclang/jac/symtable.py +154 -0
  48. jaclang/jac/tests/fixtures/__jac_gen__/__init__.py +0 -0
  49. jaclang/jac/tests/fixtures/__jac_gen__/hello_world.py +16 -0
  50. jaclang/jac/tests/fixtures/fam.jac +7 -8
  51. jaclang/jac/tests/fixtures/mod_doc_test.jac +1 -0
  52. jaclang/jac/tests/test_parser.py +8 -0
  53. jaclang/jac/transform.py +41 -14
  54. jaclang/jac/transpiler.py +18 -9
  55. jaclang/utils/fstring_parser.py +2 -2
  56. jaclang/utils/helpers.py +41 -0
  57. jaclang/utils/lang_tools.py +12 -2
  58. jaclang/utils/test.py +41 -0
  59. jaclang/vendor/__init__.py +1 -0
  60. jaclang/vendor/pygls/__init__.py +25 -0
  61. jaclang/vendor/pygls/capabilities.py +502 -0
  62. jaclang/vendor/pygls/client.py +176 -0
  63. jaclang/vendor/pygls/constants.py +26 -0
  64. jaclang/vendor/pygls/exceptions.py +220 -0
  65. jaclang/vendor/pygls/feature_manager.py +241 -0
  66. jaclang/vendor/pygls/lsp/__init__.py +139 -0
  67. jaclang/vendor/pygls/lsp/client.py +2224 -0
  68. jaclang/vendor/pygls/lsprotocol/__init__.py +2 -0
  69. jaclang/vendor/pygls/lsprotocol/_hooks.py +1233 -0
  70. jaclang/vendor/pygls/lsprotocol/converters.py +17 -0
  71. jaclang/vendor/pygls/lsprotocol/types.py +12820 -0
  72. jaclang/vendor/pygls/lsprotocol/validators.py +47 -0
  73. jaclang/vendor/pygls/progress.py +79 -0
  74. jaclang/vendor/pygls/protocol.py +1184 -0
  75. jaclang/vendor/pygls/server.py +620 -0
  76. jaclang/vendor/pygls/uris.py +184 -0
  77. jaclang/vendor/pygls/workspace/__init__.py +81 -0
  78. jaclang/vendor/pygls/workspace/position.py +204 -0
  79. jaclang/vendor/pygls/workspace/text_document.py +234 -0
  80. jaclang/vendor/pygls/workspace/workspace.py +311 -0
  81. {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/METADATA +1 -1
  82. jaclang-0.0.8.dist-info/RECORD +118 -0
  83. jaclang/core/jaclang.jac +0 -62
  84. jaclang/jac/passes/blue/tests/test_type_analyze_pass.py +0 -53
  85. jaclang/jac/passes/blue/type_analyze_pass.py +0 -728
  86. jaclang/jac/sym_table.py +0 -127
  87. jaclang-0.0.5.dist-info/RECORD +0 -73
  88. /jaclang/{utils → vendor}/sly/__init__.py +0 -0
  89. /jaclang/{utils → vendor}/sly/docparse.py +0 -0
  90. /jaclang/{utils → vendor}/sly/lex.py +0 -0
  91. /jaclang/{utils → vendor}/sly/yacc.py +0 -0
  92. {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/WHEEL +0 -0
  93. {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/entry_points.txt +0 -0
  94. {jaclang-0.0.5.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,40 +130,71 @@ 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 NAME multistring code_block
133
+ test -> KW_TEST code_block
134
+ test -> KW_TEST NAME code_block
125
135
  """
126
- del node.kid[1]
127
- replace_node(
128
- node,
129
- ast.Test(
130
- doc=node.kid[0],
131
- name=node.kid[1],
132
- description=node.kid[2],
133
- body=node.kid[3],
134
- parent=node.parent,
135
- mod_link=self.mod_link,
136
- kid=node.kid,
137
- line=node.line,
138
- ),
139
- )
136
+ if len(node.kid) == 3:
137
+ del node.kid[0]
138
+ replace_node(
139
+ node,
140
+ ast.Test(
141
+ doc=None,
142
+ name=node.kid[0],
143
+ body=node.kid[1],
144
+ parent=node.parent,
145
+ mod_link=self.mod_link,
146
+ kid=node.kid,
147
+ line=node.line,
148
+ ),
149
+ )
150
+ else:
151
+ replace_node(
152
+ node,
153
+ ast.Test(
154
+ doc=None,
155
+ name=node.kid[0],
156
+ body=node.kid[1],
157
+ parent=node.parent,
158
+ mod_link=self.mod_link,
159
+ kid=node.kid,
160
+ line=node.line,
161
+ ),
162
+ )
140
163
 
141
164
  def exit_mod_code(self, node: ast.AstNode) -> None:
142
165
  """Grammar rule.
143
166
 
144
- 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
145
169
  """
146
- node.kid = [node.kid[0], node.kid[-1]]
147
- replace_node(
148
- node,
149
- ast.ModuleCode(
150
- doc=node.kid[0],
151
- body=node.kid[1],
152
- parent=node.parent,
153
- mod_link=self.mod_link,
154
- kid=node.kid,
155
- line=node.line,
156
- ),
157
- )
170
+ if len(node.kid) == 4:
171
+ node.kid = [node.kid[-2], node.kid[-1]]
172
+ replace_node(
173
+ node,
174
+ ast.ModuleCode(
175
+ doc=None,
176
+ name=node.kid[0],
177
+ body=node.kid[1],
178
+ parent=node.parent,
179
+ mod_link=self.mod_link,
180
+ kid=node.kid,
181
+ line=node.line,
182
+ ),
183
+ )
184
+ else:
185
+ node.kid = [node.kid[-1]]
186
+ replace_node(
187
+ node,
188
+ ast.ModuleCode(
189
+ doc=None,
190
+ name=None,
191
+ body=node.kid[0],
192
+ parent=node.parent,
193
+ mod_link=self.mod_link,
194
+ kid=node.kid,
195
+ line=node.line,
196
+ ),
197
+ )
158
198
 
159
199
  def exit_doc_tag(self, node: ast.AstNode) -> None:
160
200
  """Grammar rule.
@@ -164,6 +204,22 @@ class AstBuildPass(Pass):
164
204
  """
165
205
  replace_node(node, node.kid[0])
166
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
+
167
223
  def exit_import_stmt(self, node: ast.AstNode) -> None:
168
224
  """Grammar rule.
169
225
 
@@ -315,29 +371,46 @@ class AstBuildPass(Pass):
315
371
  def exit_architype(self, node: ast.AstNode) -> None:
316
372
  """Grammar rule.
317
373
 
318
- architype -> architype_def
319
- architype -> architype_decl
320
- 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
321
378
  """
322
- 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!")
323
398
 
324
399
  def exit_architype_decl(self, node: ast.AstNode) -> None:
325
400
  """Grammar rule.
326
401
 
327
- architype_decl -> doc_tag decorators arch_type access_tag NAME inherited_archs member_block
328
- architype_decl -> doc_tag arch_type access_tag NAME inherited_archs member_block
329
- architype_decl -> doc_tag decorators arch_type access_tag NAME inherited_archs SEMI
330
- 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
331
404
  """
332
405
  replace_node(
333
406
  node,
334
407
  ast.Architype(
335
- doc=node.kid[0],
336
- decorators=node.kid[1] if len(node.kid) == 7 else None,
337
- arch_type=node.kid[2] if len(node.kid) == 7 else node.kid[1],
338
- access=node.kid[3] if len(node.kid) == 7 else node.kid[2],
339
- name=node.kid[4] if len(node.kid) == 7 else node.kid[3],
340
- 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],
341
414
  body=node.kid[-1] if isinstance(node.kid[-1], ast.ArchBlock) else None,
342
415
  parent=node.parent,
343
416
  mod_link=self.mod_link,
@@ -351,19 +424,17 @@ class AstBuildPass(Pass):
351
424
  def exit_architype_def(self, node: ast.AstNode) -> None:
352
425
  """Grammar rule.
353
426
 
354
- architype_def -> doc_tag dotted_name strict_arch_ref member_block
355
- architype_def -> doc_tag strict_arch_ref member_block
427
+ architype_def -> abil_to_arch_chain member_block
356
428
  """
357
429
  replace_node(
358
430
  node,
359
431
  ast.ArchDef(
360
- doc=node.kid[0],
361
- mod=node.kid[1] if len(node.kid) == 4 else None,
362
- arch=node.kid[2] if len(node.kid) == 4 else node.kid[1],
363
- body=node.kid[-1],
432
+ doc=None,
433
+ target=node.kid[0],
434
+ body=node.kid[1],
364
435
  parent=node.parent,
365
436
  mod_link=self.mod_link,
366
- kid=node.kid,
437
+ kid=[node.kid[1]],
367
438
  line=node.line,
368
439
  ),
369
440
  )
@@ -378,26 +449,12 @@ class AstBuildPass(Pass):
378
449
  """
379
450
  replace_node(node, node.kid[0])
380
451
 
381
- def exit_decorators(self, node: ast.AstNode) -> None:
452
+ def exit_decorator(self, node: ast.AstNode) -> None:
382
453
  """Grammar rule.
383
454
 
384
- decorators -> decorators DECOR_OP atom
385
- decorators -> DECOR_OP atom
455
+ decorator -> DECOR_OP atom
386
456
  """
387
- if len(node.kid) == 3:
388
- node.kid = node.kid[0].kid + [node.kid[2]]
389
- else:
390
- node.kid = [node.kid[1]]
391
- replace_node(
392
- node,
393
- ast.Decorators(
394
- calls=node.kid,
395
- parent=node.parent,
396
- mod_link=self.mod_link,
397
- kid=node.kid,
398
- line=node.line,
399
- ),
400
- )
457
+ replace_node(node, node.kid[1])
401
458
 
402
459
  def exit_inherited_archs(self, node: ast.AstNode) -> None:
403
460
  """Grammar rule.
@@ -472,8 +529,8 @@ class AstBuildPass(Pass):
472
529
  def exit_named_refs(self, node: ast.AstNode) -> None:
473
530
  """Grammar rule.
474
531
 
475
- named_refs -> NAME
476
- named_refs -> arch_ref
532
+ Rule 63 named_refs -> global_ref
533
+ Rule 64 named_refs -> esc_name
477
534
  """
478
535
  replace_node(node, node.kid[0])
479
536
 
@@ -497,40 +554,159 @@ class AstBuildPass(Pass):
497
554
  ),
498
555
  )
499
556
 
557
+ def exit_enum(self, node: ast.AstNode) -> None:
558
+ """Grammar rule.
559
+
560
+ enum -> enum_def
561
+ enum -> enum_decl
562
+ """
563
+ replace_node(node, node.kid[0])
564
+
565
+ def exit_enum_decl(self, node: ast.AstNode) -> None:
566
+ """Grammar rule.
567
+
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
570
+ """
571
+ del node.kid[0]
572
+ replace_node(
573
+ node,
574
+ ast.Enum(
575
+ doc=None,
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,
581
+ parent=node.parent,
582
+ mod_link=self.mod_link,
583
+ kid=node.kid,
584
+ line=node.line,
585
+ ),
586
+ )
587
+ if isinstance(node.kid[-1], ast.Token):
588
+ del node.kid[-1]
589
+
590
+ def exit_enum_def(self, node: ast.AstNode) -> None:
591
+ """Grammar rule.
592
+
593
+ Rule 74 enum_def -> arch_to_enum_chain enum_block
594
+ """
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
+
500
661
  def exit_ability(self, node: ast.AstNode) -> None:
501
662
  """Grammar rule.
502
663
 
503
- ability -> ability_def
504
- ability -> KW_ASYNC ability_decl
505
- ability -> ability_decl
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
506
668
  """
507
- if len(node.kid) == 2:
669
+ if len(node.kid) == 2 and isinstance(node.kid[0], ast.Token):
508
670
  new_node = replace_node(node, node.kid[1])
509
671
  if isinstance(new_node, ast.Ability):
510
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!")
511
690
  else:
512
691
  replace_node(node, node.kid[0])
513
692
 
514
693
  def exit_ability_decl(self, node: ast.AstNode) -> None:
515
694
  """Grammar rule.
516
695
 
517
- ability_decl -> ability_decl_decor
518
- ability_decl -> doc_tag static_tag KW_CAN access_tag all_refs func_decl code_block
519
- ability_decl -> doc_tag static_tag KW_CAN access_tag all_refs event_clause code_block
520
- ability_decl -> doc_tag static_tag KW_CAN access_tag all_refs func_decl SEMI
521
- ability_decl -> doc_tag static_tag KW_CAN access_tag all_refs event_clause SEMI
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
522
700
  """
523
- if len(node.kid) == 1:
524
- replace_node(node, node.kid[0])
525
- return
526
- del node.kid[2]
701
+ del node.kid[1]
527
702
  replace_node(
528
703
  node,
529
704
  ast.Ability(
530
- doc=node.kid[0],
531
- access=node.kid[2],
532
- is_static=node.kid[1],
533
- name_ref=node.kid[3],
705
+ doc=None,
706
+ access=node.kid[1],
707
+ is_static=node.kid[0],
708
+ is_abstract=False,
709
+ name_ref=node.kid[2],
534
710
  body=node.kid[-1] if isinstance(node.kid[-1], ast.CodeBlock) else None,
535
711
  signature=node.kid[-2],
536
712
  is_func=isinstance(node.kid[-2], ast.FuncSignature),
@@ -545,52 +721,47 @@ class AstBuildPass(Pass):
545
721
  if isinstance(node.kid[-1], ast.Token):
546
722
  del node.kid[-1]
547
723
 
548
- def exit_ability_decl_decor(self, node: ast.AstNode) -> None:
724
+ def exit_ability_def(self, node: ast.AstNode) -> None:
549
725
  """Grammar rule.
550
726
 
551
- ability_decl_decor -> doc_tag decorators static_tag KW_CAN access_tag all_refs func_decl code_block
552
- ability_decl_decor -> doc_tag decorators static_tag KW_CAN access_tag all_refs event_clause code_block
553
- ability_decl_decor -> doc_tag decorators static_tag KW_CAN access_tag all_refs func_decl SEMI
554
- ability_decl_decor -> doc_tag decorators static_tag KW_CAN access_tag all_refs event_clause SEMI
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
555
729
  """
556
- del node.kid[3]
557
730
  replace_node(
558
731
  node,
559
- ast.Ability(
560
- doc=node.kid[0],
561
- decorators=node.kid[1],
562
- is_static=node.kid[2],
563
- access=node.kid[3],
564
- name_ref=node.kid[4],
565
- body=node.kid[-1] if isinstance(node.kid[-1], ast.CodeBlock) else None,
732
+ ast.AbilityDef(
733
+ doc=None,
734
+ target=node.kid[0],
566
735
  signature=node.kid[-2],
567
- is_func=isinstance(node.kid[-2], ast.FuncSignature),
568
- is_async=False,
736
+ body=node.kid[-1],
569
737
  parent=node.parent,
570
738
  mod_link=self.mod_link,
571
739
  kid=node.kid,
572
740
  line=node.line,
573
741
  ),
574
742
  )
575
- if isinstance(node.kid[-1], ast.Token):
576
- del node.kid[-1]
577
743
 
578
- def exit_ability_def(self, node: ast.AstNode) -> None:
744
+ def exit_abstract_ability(self, node: ast.AstNode) -> None:
579
745
  """Grammar rule.
580
746
 
581
- ability_def -> doc_tag dotted_name ability_ref func_decl code_block
582
- ability_def -> doc_tag ability_ref func_decl code_block
583
- ability_def -> doc_tag dotted_name ability_ref event_clause code_block
584
- ability_def -> doc_tag ability_ref event_clause code_block
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
585
749
  """
750
+ del node.kid[1]
751
+ del node.kid[-2:]
586
752
  replace_node(
587
753
  node,
588
- ast.AbilityDef(
589
- doc=node.kid[0],
590
- target=node.kid[1] if len(node.kid) == 5 else None,
591
- ability=node.kid[2] if len(node.kid) == 5 else node.kid[1],
592
- signature=node.kid[-2],
593
- body=node.kid[-1],
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,
594
765
  parent=node.parent,
595
766
  mod_link=self.mod_link,
596
767
  kid=node.kid,
@@ -723,135 +894,6 @@ class AstBuildPass(Pass):
723
894
  ),
724
895
  )
725
896
 
726
- def exit_enum(self, node: ast.AstNode) -> None:
727
- """Grammar rule.
728
-
729
- enum -> enum_def
730
- enum -> enum_decl
731
- """
732
- replace_node(node, node.kid[0])
733
-
734
- def exit_enum_decl(self, node: ast.AstNode) -> None:
735
- """Grammar rule.
736
-
737
- enum_decl -> doc_tag decorators KW_ENUM access_tag NAME inherited_archs enum_block
738
- enum_decl -> doc_tag decorators KW_ENUM access_tag NAME inherited_archs SEMI
739
- enum_decl -> doc_tag KW_ENUM access_tag NAME inherited_archs enum_block
740
- enum_decl -> doc_tag KW_ENUM access_tag NAME inherited_archs SEMI
741
- """
742
- if isinstance(node.kid[1], ast.Token):
743
- del node.kid[1]
744
- replace_node(
745
- node,
746
- ast.Enum(
747
- doc=node.kid[0],
748
- decorators=None,
749
- access=node.kid[1],
750
- name=node.kid[2],
751
- base_classes=node.kid[3],
752
- body=node.kid[-1]
753
- if isinstance(node.kid[-1], ast.EnumBlock)
754
- else None,
755
- parent=node.parent,
756
- mod_link=self.mod_link,
757
- kid=node.kid,
758
- line=node.line,
759
- ),
760
- )
761
- else:
762
- replace_node(
763
- node,
764
- ast.Enum(
765
- doc=node.kid[0],
766
- decorators=node.kid[1],
767
- access=node.kid[2],
768
- name=node.kid[3],
769
- base_classes=node.kid[4],
770
- body=node.kid[-1]
771
- if isinstance(node.kid[-1], ast.EnumBlock)
772
- else None,
773
- parent=node.parent,
774
- mod_link=self.mod_link,
775
- kid=node.kid,
776
- line=node.line,
777
- ),
778
- )
779
- if isinstance(node.kid[-1], ast.Token):
780
- del node.kid[-1]
781
-
782
- def exit_enum_def(self, node: ast.AstNode) -> None:
783
- """Grammar rule.
784
-
785
- enum_def -> doc_tag dotted_name enum_ref enum_block
786
- enum_def -> doc_tag enum_ref enum_block
787
- """
788
- replace_node(
789
- node,
790
- ast.EnumDef(
791
- doc=node.kid[0],
792
- enum=node.kid[-2],
793
- mod=node.kid[1] if len(node.kid) == 4 else None,
794
- body=node.kid[-1],
795
- parent=node.parent,
796
- mod_link=self.mod_link,
797
- kid=node.kid,
798
- line=node.line,
799
- ),
800
- )
801
-
802
- def exit_enum_block(self, node: ast.AstNode) -> None:
803
- """Grammar rule.
804
-
805
- enum_block -> LBRACE enum_stmt_list RBRACE
806
- enum_block -> LBRACE RBRACE
807
- """
808
- if len(node.kid) == 3:
809
- ret = replace_node(node, node.kid[1])
810
- node = ret if ret else node
811
- else:
812
- node.kid = []
813
- replace_node(
814
- node,
815
- ast.EnumBlock(
816
- stmts=node.kid,
817
- parent=node.parent,
818
- mod_link=self.mod_link,
819
- kid=node.kid,
820
- line=node.line,
821
- ),
822
- )
823
-
824
- def exit_enum_stmt_list(self, node: ast.AstNode) -> None:
825
- """Grammar rule.
826
-
827
- enum_stmt_list -> enum_stmt_list COMMA enum_op_assign
828
- enum_stmt_list -> enum_stmt_list COMMA NAME
829
- enum_stmt_list -> enum_op_assign
830
- enum_stmt_list -> NAME
831
- """
832
- if len(node.kid) == 3:
833
- node.kid = node.kid[0].kid + [node.kid[2]]
834
-
835
- def exit_enum_op_assign(self, node: ast.AstNode) -> None:
836
- """Grammar rule.
837
-
838
- enum_op_assign -> NAME EQ expression
839
- """
840
- del node.kid[1]
841
- replace_node(
842
- node,
843
- ast.Assignment(
844
- target=node.kid[0],
845
- value=node.kid[1],
846
- mutable=False,
847
- is_static=False,
848
- parent=node.parent,
849
- mod_link=self.mod_link,
850
- kid=node.kid,
851
- line=node.line,
852
- ),
853
- )
854
-
855
897
  def exit_member_block(self, node: ast.AstNode) -> None:
856
898
  """Grammar rule.
857
899
 
@@ -886,26 +928,38 @@ class AstBuildPass(Pass):
886
928
  def exit_member_stmt(self, node: ast.AstNode) -> None:
887
929
  """Grammar rule.
888
930
 
889
- member_stmt -> ability
890
- 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
891
936
  """
892
- 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])
893
947
 
894
948
  def exit_has_stmt(self, node: ast.AstNode) -> None:
895
949
  """Grammar rule.
896
950
 
897
- has_stmt -> doc_tag static_tag KW_FREEZE access_tag has_assign_clause SEMI
898
- 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
899
953
  """
900
- is_frozen = node.kid[2].name == Tok.KW_FREEZE
901
- 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]]
902
956
  replace_node(
903
957
  node,
904
958
  ast.ArchHas(
905
- doc=node.kid[0],
906
- is_static=node.kid[1],
907
- access=node.kid[2],
908
- vars=node.kid[3],
959
+ doc=None,
960
+ is_static=node.kid[0],
961
+ access=node.kid[1],
962
+ vars=node.kid[2],
909
963
  is_frozen=is_frozen,
910
964
  parent=node.parent,
911
965
  mod_link=self.mod_link,
@@ -1095,27 +1149,57 @@ class AstBuildPass(Pass):
1095
1149
  def exit_statement(self, node: ast.AstNode) -> None:
1096
1150
  """Grammar rule.
1097
1151
 
1098
- statement -> walker_stmt
1099
- statement -> await_stmt SEMI
1100
- statement -> yield_stmt SEMI
1101
- statement -> return_stmt SEMI
1102
- statement -> report_stmt SEMI
1103
- statement -> delete_stmt SEMI
1104
- statement -> ctrl_stmt SEMI
1105
- statement -> assert_stmt SEMI
1106
- statement -> raise_stmt SEMI
1107
- statement -> with_ctx_stmt
1108
- statement -> while_stmt
1109
- statement -> for_stmt
1110
- statement -> try_stmt
1111
- statement -> if_stmt
1112
- statement -> expression SEMI
1113
- statement -> static_assignment
1114
- statement -> assignment SEMI
1115
- statement -> ability_decl
1116
- statement -> architype_decl
1117
- """
1118
- 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])
1119
1203
 
1120
1204
  def exit_typed_ctx_block(self, node: ast.AstNode) -> None:
1121
1205
  """Grammar rule.
@@ -2546,7 +2630,6 @@ class AstBuildPass(Pass):
2546
2630
  """Grammar rule.
2547
2631
 
2548
2632
  atomic_chain_unsafe -> atom filter_compr
2549
- atomic_chain_unsafe -> atom arch_ref
2550
2633
  atomic_chain_unsafe -> atom index_slice
2551
2634
  atomic_chain_unsafe -> atom DOT NAME
2552
2635
  atomic_chain_unsafe -> atom DOT_FWD NAME
@@ -2576,7 +2659,6 @@ class AstBuildPass(Pass):
2576
2659
  """Grammar rule.
2577
2660
 
2578
2661
  atomic_chain_safe -> atom NULL_OK filter_compr
2579
- atomic_chain_safe -> atom NULL_OK arch_ref
2580
2662
  atomic_chain_safe -> atom NULL_OK index_slice
2581
2663
  atomic_chain_safe -> atom NULL_OK DOT NAME
2582
2664
  atomic_chain_safe -> atom NULL_OK DOT_FWD NAME
@@ -2705,7 +2787,7 @@ class AstBuildPass(Pass):
2705
2787
  index_slice -> LSQUARE expression RSQUARE
2706
2788
  """
2707
2789
  if len(node.kid) == 3:
2708
- if isinstance(node.kid[1], ast.Token) and node.kid[1].name == Tok.COLON:
2790
+ if hasattr(node.kid[1], "name") and node.kid[1].name == Tok.COLON:
2709
2791
  node.kid = []
2710
2792
  replace_node(
2711
2793
  node,
@@ -2787,23 +2869,90 @@ class AstBuildPass(Pass):
2787
2869
  def exit_arch_ref(self, node: ast.AstNode) -> None:
2788
2870
  """Grammar rule.
2789
2871
 
2790
- arch_ref -> ability_ref
2791
- arch_ref -> object_ref
2792
- arch_ref -> walker_ref
2793
- arch_ref -> edge_ref
2794
- 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
2795
2876
  """
2796
2877
  replace_node(node, node.kid[0])
2797
2878
 
2798
- def exit_strict_arch_ref(self, node: ast.AstNode) -> None:
2879
+ def exit_arch_or_ability_chain(self, node: ast.AstNode) -> None:
2799
2880
  """Grammar rule.
2800
2881
 
2801
- strict_arch_ref -> object_ref
2802
- strict_arch_ref -> walker_ref
2803
- strict_arch_ref -> edge_ref
2804
- 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
2805
2886
  """
2806
- 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
+ )
2807
2956
 
2808
2957
  def exit_node_ref(self, node: ast.AstNode) -> None:
2809
2958
  """Grammar rule.