jaclang 0.0.1__py3-none-any.whl → 0.0.3__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 (73) hide show
  1. jaclang/__init__.py +4 -0
  2. jaclang/cli/__init__.py +7 -0
  3. jaclang/cli/cli.jac +46 -0
  4. jaclang/cli/cmds.jac +14 -0
  5. jaclang/cli/impl/__init__.py +1 -0
  6. jaclang/cli/impl/cli_impl.jac +93 -0
  7. jaclang/cli/impl/cmds_impl.jac +26 -0
  8. jaclang/core/__init__.py +12 -0
  9. jaclang/core/impl/__init__.py +1 -0
  10. jaclang/core/impl/arch_impl.jac +112 -0
  11. jaclang/core/impl/element_impl.jac +95 -0
  12. jaclang/core/impl/exec_ctx_impl.jac +17 -0
  13. jaclang/core/impl/memory_impl.jac +57 -0
  14. jaclang/core/primitives.jac +104 -0
  15. jaclang/jac/__init__.py +1 -0
  16. jaclang/jac/absyntree.py +1787 -0
  17. jaclang/jac/constant.py +46 -0
  18. jaclang/jac/importer.py +130 -0
  19. jaclang/jac/lexer.py +538 -0
  20. jaclang/jac/parser.py +1474 -0
  21. jaclang/jac/passes/__init__.py +5 -0
  22. jaclang/jac/passes/blue/__init__.py +25 -0
  23. jaclang/jac/passes/blue/ast_build_pass.py +3190 -0
  24. jaclang/jac/passes/blue/blue_pygen_pass.py +1335 -0
  25. jaclang/jac/passes/blue/decl_def_match_pass.py +278 -0
  26. jaclang/jac/passes/blue/import_pass.py +75 -0
  27. jaclang/jac/passes/blue/sub_node_tab_pass.py +30 -0
  28. jaclang/jac/passes/blue/tests/__init__.py +1 -0
  29. jaclang/jac/passes/blue/tests/test_ast_build_pass.py +61 -0
  30. jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +117 -0
  31. jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +43 -0
  32. jaclang/jac/passes/blue/tests/test_import_pass.py +18 -0
  33. jaclang/jac/passes/blue/tests/test_sub_node_pass.py +26 -0
  34. jaclang/jac/passes/blue/tests/test_type_analyze_pass.py +53 -0
  35. jaclang/jac/passes/blue/type_analyze_pass.py +731 -0
  36. jaclang/jac/passes/ir_pass.py +154 -0
  37. jaclang/jac/passes/purple/__init__.py +17 -0
  38. jaclang/jac/passes/purple/impl/__init__.py +1 -0
  39. jaclang/jac/passes/purple/impl/purple_pygen_pass_impl.jac +289 -0
  40. jaclang/jac/passes/purple/purple_pygen_pass.jac +35 -0
  41. jaclang/jac/sym_table.py +127 -0
  42. jaclang/jac/tests/__init__.py +1 -0
  43. jaclang/jac/tests/fixtures/__init__.py +1 -0
  44. jaclang/jac/tests/fixtures/activity.py +10 -0
  45. jaclang/jac/tests/fixtures/fam.jac +68 -0
  46. jaclang/jac/tests/fixtures/hello_world.jac +5 -0
  47. jaclang/jac/tests/fixtures/lexer_fam.jac +61 -0
  48. jaclang/jac/tests/fixtures/stuff.jac +6 -0
  49. jaclang/jac/tests/test_importer.py +24 -0
  50. jaclang/jac/tests/test_lexer.py +57 -0
  51. jaclang/jac/tests/test_parser.py +50 -0
  52. jaclang/jac/tests/test_utils.py +12 -0
  53. jaclang/jac/transform.py +63 -0
  54. jaclang/jac/transpiler.py +69 -0
  55. jaclang/jac/utils.py +120 -0
  56. jaclang/utils/__init__.py +1 -0
  57. jaclang/utils/fstring_parser.py +73 -0
  58. jaclang/utils/log.py +9 -0
  59. jaclang/utils/sly/__init__.py +6 -0
  60. jaclang/utils/sly/docparse.py +62 -0
  61. jaclang/utils/sly/lex.py +510 -0
  62. jaclang/utils/sly/yacc.py +2398 -0
  63. jaclang/utils/test.py +81 -0
  64. jaclang/utils/tests/__init__.py +1 -0
  65. jaclang/utils/tests/test_fstring_parser.py +55 -0
  66. jaclang-0.0.3.dist-info/METADATA +12 -0
  67. jaclang-0.0.3.dist-info/RECORD +70 -0
  68. {jaclang-0.0.1.dist-info → jaclang-0.0.3.dist-info}/WHEEL +1 -1
  69. jaclang-0.0.3.dist-info/entry_points.txt +3 -0
  70. jaclang-0.0.3.dist-info/top_level.txt +1 -0
  71. jaclang-0.0.1.dist-info/METADATA +0 -7
  72. jaclang-0.0.1.dist-info/RECORD +0 -4
  73. jaclang-0.0.1.dist-info/top_level.txt +0 -1
jaclang/jac/parser.py ADDED
@@ -0,0 +1,1474 @@
1
+ # type: ignore
2
+ """Parser for Jac."""
3
+ from typing import Generator, Optional
4
+
5
+ import jaclang.jac.absyntree as ast
6
+ from jaclang.jac.lexer import JacLexer
7
+ from jaclang.jac.transform import ABCParserMeta, Transform
8
+ from jaclang.utils.sly.yacc import Parser, YaccProduction
9
+
10
+
11
+ _ = None # For flake8 linting
12
+
13
+
14
+ class JacParser(Transform, Parser, metaclass=ABCParserMeta):
15
+ """Parser for Jac."""
16
+
17
+ start = "module"
18
+
19
+ def __init__(
20
+ self,
21
+ mod_path: str,
22
+ input_ir: Generator,
23
+ base_path: str = "",
24
+ prior: Optional[Transform] = None,
25
+ ) -> None:
26
+ """Initialize parser."""
27
+ Transform.__init__(self, mod_path, input_ir, base_path, prior)
28
+ self.ir_tup = self.ir
29
+ if self.errors_had:
30
+ print(self.errors_had)
31
+ self.ir: ast.AstNode = parse_tree_to_ast(self.ir)
32
+
33
+ tokens = JacLexer.tokens
34
+ # debugfile = "parser.out"
35
+
36
+ # All mighty start rule
37
+ # ---------------------
38
+ @_(
39
+ "DOC_STRING",
40
+ "DOC_STRING element_list",
41
+ )
42
+ def module(self, p: YaccProduction) -> YaccProduction:
43
+ """Start rule."""
44
+ return p
45
+
46
+ # Jac program structured as a list of elements
47
+ # --------------------------------------------
48
+ @_(
49
+ "element",
50
+ "element_list element",
51
+ )
52
+ def element_list(self, p: YaccProduction) -> YaccProduction:
53
+ """Element list rule."""
54
+ return p
55
+
56
+ # Element types
57
+ # -------------
58
+ @_(
59
+ "global_var",
60
+ "test",
61
+ "mod_code",
62
+ "import_stmt",
63
+ "include_stmt",
64
+ "architype",
65
+ "ability",
66
+ "enum",
67
+ )
68
+ def element(self, p: YaccProduction) -> YaccProduction:
69
+ """Element rule."""
70
+ return p
71
+
72
+ @_(
73
+ "doc_tag KW_GLOBAL access_tag assignment_list SEMI",
74
+ "doc_tag KW_FREEZE access_tag assignment_list SEMI",
75
+ )
76
+ def global_var(self, p: YaccProduction) -> YaccProduction:
77
+ """Global variable rule."""
78
+ return p
79
+
80
+ @_(
81
+ "KW_PRIV",
82
+ "KW_PUB",
83
+ "KW_PROT",
84
+ )
85
+ def access(self, p: YaccProduction) -> YaccProduction:
86
+ """Permission tag rule."""
87
+ return p
88
+
89
+ @_(
90
+ "COLON access",
91
+ "empty",
92
+ )
93
+ def access_tag(self, p: YaccProduction) -> YaccProduction:
94
+ """Permission tag rule."""
95
+ return p
96
+
97
+ @_("doc_tag KW_TEST NAME multistring code_block")
98
+ def test(self, p: YaccProduction) -> YaccProduction:
99
+ """Test rule."""
100
+ return p
101
+
102
+ @_("doc_tag KW_WITH KW_ENTRY code_block")
103
+ def mod_code(self, p: YaccProduction) -> YaccProduction:
104
+ """Module-level free code rule."""
105
+ return p
106
+
107
+ @_(
108
+ "empty",
109
+ "DOC_STRING",
110
+ )
111
+ def doc_tag(self, p: YaccProduction) -> YaccProduction:
112
+ """Doc tag rule."""
113
+ return p
114
+
115
+ # Import Statements
116
+ # -----------------
117
+ @_(
118
+ "KW_IMPORT sub_name import_path SEMI",
119
+ "KW_IMPORT sub_name import_path KW_AS NAME SEMI",
120
+ "KW_IMPORT sub_name KW_FROM import_path COMMA import_items SEMI",
121
+ )
122
+ def import_stmt(self, p: YaccProduction) -> YaccProduction:
123
+ """Import rule."""
124
+ return p
125
+
126
+ @_("KW_INCLUDE sub_name import_path SEMI")
127
+ def include_stmt(self, p: YaccProduction) -> YaccProduction:
128
+ """Import rule."""
129
+ return p
130
+
131
+ @_(
132
+ "import_path_prefix",
133
+ "import_path_prefix import_path_tail",
134
+ )
135
+ def import_path(self, p: YaccProduction) -> YaccProduction:
136
+ """Import path rule."""
137
+ return p
138
+
139
+ @_(
140
+ "NAME",
141
+ "DOT NAME",
142
+ "DOT DOT NAME",
143
+ )
144
+ def import_path_prefix(self, p: YaccProduction) -> YaccProduction:
145
+ """Import path prefix rule."""
146
+ return p
147
+
148
+ @_(
149
+ "DOT NAME",
150
+ "import_path_tail DOT NAME",
151
+ )
152
+ def import_path_tail(self, p: YaccProduction) -> YaccProduction:
153
+ """Import path tail rule."""
154
+ return p
155
+
156
+ @_(
157
+ "named_refs",
158
+ "named_refs KW_AS NAME",
159
+ "import_items COMMA named_refs",
160
+ "import_items COMMA named_refs KW_AS NAME",
161
+ )
162
+ def import_items(self, p: YaccProduction) -> YaccProduction:
163
+ """Name as list rule."""
164
+ return p
165
+
166
+ # Architype elements
167
+ # ------------------
168
+ @_(
169
+ "architype_decl",
170
+ "architype_def",
171
+ )
172
+ def architype(self, p: YaccProduction) -> YaccProduction:
173
+ """Architype rule."""
174
+ return p
175
+
176
+ @_(
177
+ "doc_tag arch_type access_tag NAME inherited_archs SEMI",
178
+ "doc_tag decorators arch_type access_tag NAME inherited_archs SEMI",
179
+ "doc_tag arch_type access_tag NAME inherited_archs member_block",
180
+ "doc_tag decorators arch_type access_tag NAME inherited_archs member_block",
181
+ )
182
+ def architype_decl(self, p: YaccProduction) -> YaccProduction:
183
+ """Architype declaration rule."""
184
+ return p
185
+
186
+ @_(
187
+ "doc_tag strict_arch_ref member_block",
188
+ "doc_tag dotted_name strict_arch_ref member_block",
189
+ )
190
+ def architype_def(self, p: YaccProduction) -> YaccProduction:
191
+ """Architype definition rule."""
192
+ return p
193
+
194
+ @_(
195
+ "KW_NODE",
196
+ "KW_EDGE",
197
+ "KW_OBJECT",
198
+ "KW_WALKER",
199
+ )
200
+ def arch_type(self, p: YaccProduction) -> YaccProduction:
201
+ """Arch type rule."""
202
+ return p
203
+
204
+ @_(
205
+ "DECOR_OP atom",
206
+ "decorators DECOR_OP atom",
207
+ )
208
+ def decorators(self, p: YaccProduction) -> YaccProduction:
209
+ """Python style decorator rule."""
210
+ return p
211
+
212
+ @_(
213
+ "empty",
214
+ "inherited_archs sub_name_dotted",
215
+ )
216
+ def inherited_archs(self, p: YaccProduction) -> YaccProduction:
217
+ """Sub name list rule."""
218
+ return p
219
+
220
+ @_("COLON NAME")
221
+ def sub_name(self, p: YaccProduction) -> YaccProduction:
222
+ """Sub name rule."""
223
+ return p
224
+
225
+ @_("COLON dotted_name")
226
+ def sub_name_dotted(self, p: YaccProduction) -> YaccProduction:
227
+ """Sub name rule."""
228
+ return p
229
+
230
+ @_(
231
+ "all_refs",
232
+ "dotted_name DOT all_refs",
233
+ )
234
+ def dotted_name(self, p: YaccProduction) -> YaccProduction:
235
+ """Strict arch reference rule."""
236
+ return p
237
+
238
+ @_(
239
+ "named_refs",
240
+ "special_refs",
241
+ )
242
+ def all_refs(self, p: YaccProduction) -> YaccProduction:
243
+ """All reference rules."""
244
+ return p
245
+
246
+ @_(
247
+ "NAME",
248
+ "arch_ref",
249
+ )
250
+ def named_refs(self, p: YaccProduction) -> YaccProduction:
251
+ """All reference rules."""
252
+ return p
253
+
254
+ @_(
255
+ "here_ref",
256
+ "self_ref",
257
+ "super_ref",
258
+ "root_ref",
259
+ )
260
+ def special_refs(self, p: YaccProduction) -> YaccProduction:
261
+ """All reference rules."""
262
+ return p
263
+
264
+ # Ability elements
265
+ # ----------------
266
+ @_(
267
+ "ability_decl",
268
+ "KW_ASYNC ability_decl",
269
+ "ability_def",
270
+ )
271
+ def ability(self, p: YaccProduction) -> YaccProduction:
272
+ """Ability rule."""
273
+ return p
274
+
275
+ @_(
276
+ "doc_tag static_tag KW_CAN access_tag NAME event_clause SEMI",
277
+ "doc_tag static_tag KW_CAN access_tag NAME func_decl SEMI",
278
+ "doc_tag static_tag KW_CAN access_tag NAME event_clause code_block",
279
+ "doc_tag static_tag KW_CAN access_tag NAME func_decl code_block",
280
+ "ability_decl_decor",
281
+ )
282
+ def ability_decl(self, p: YaccProduction) -> YaccProduction:
283
+ """Ability rule."""
284
+ return p
285
+
286
+ @_(
287
+ "doc_tag decorators static_tag KW_CAN access_tag NAME event_clause SEMI",
288
+ "doc_tag decorators static_tag KW_CAN access_tag NAME func_decl SEMI",
289
+ "doc_tag decorators static_tag KW_CAN access_tag NAME event_clause code_block",
290
+ "doc_tag decorators static_tag KW_CAN access_tag NAME func_decl code_block",
291
+ )
292
+ def ability_decl_decor(self, p: YaccProduction) -> YaccProduction:
293
+ """Ability declaration rule."""
294
+ return p
295
+
296
+ @_(
297
+ "doc_tag ability_ref event_clause code_block",
298
+ "doc_tag dotted_name ability_ref event_clause code_block",
299
+ "doc_tag ability_ref func_decl code_block",
300
+ "doc_tag dotted_name ability_ref func_decl code_block",
301
+ )
302
+ def ability_def(self, p: YaccProduction) -> YaccProduction:
303
+ """Ability rule."""
304
+ return p
305
+
306
+ @_(
307
+ "KW_WITH KW_ENTRY return_type_tag",
308
+ "KW_WITH KW_EXIT return_type_tag",
309
+ "KW_WITH type_spec KW_ENTRY return_type_tag",
310
+ "KW_WITH type_spec KW_EXIT return_type_tag",
311
+ )
312
+ def event_clause(self, p: YaccProduction) -> YaccProduction:
313
+ """Event clause rule."""
314
+ return p
315
+
316
+ @_(
317
+ "return_type_tag",
318
+ "LPAREN RPAREN return_type_tag",
319
+ "LPAREN func_decl_param_list RPAREN return_type_tag",
320
+ )
321
+ def func_decl(self, p: YaccProduction) -> YaccProduction:
322
+ """Func declaration parameter rule."""
323
+ return p
324
+
325
+ @_(
326
+ "param_var",
327
+ "func_decl_param_list COMMA param_var",
328
+ )
329
+ def func_decl_param_list(self, p: YaccProduction) -> YaccProduction:
330
+ """Func declaration parameters list rule."""
331
+ return p
332
+
333
+ @_(
334
+ "NAME type_tag",
335
+ "NAME type_tag EQ expression",
336
+ "STAR_MUL NAME type_tag",
337
+ "STAR_MUL NAME type_tag EQ expression",
338
+ "STAR_POW NAME type_tag",
339
+ "STAR_POW NAME type_tag EQ expression",
340
+ )
341
+ def param_var(self, p: YaccProduction) -> YaccProduction:
342
+ """Parameter variable rule rule."""
343
+ return p
344
+
345
+ # Enum elements
346
+ # ----------------
347
+ @_(
348
+ "enum_decl",
349
+ "enum_def",
350
+ )
351
+ def enum(self, p: YaccProduction) -> YaccProduction:
352
+ """Enum rule."""
353
+ return p
354
+
355
+ @_(
356
+ "doc_tag KW_ENUM access_tag NAME inherited_archs SEMI",
357
+ "doc_tag KW_ENUM access_tag NAME inherited_archs enum_block",
358
+ "doc_tag decorators KW_ENUM access_tag NAME inherited_archs SEMI",
359
+ "doc_tag decorators KW_ENUM access_tag NAME inherited_archs enum_block",
360
+ )
361
+ def enum_decl(self, p: YaccProduction) -> YaccProduction:
362
+ """Enum decl rule."""
363
+ return p
364
+
365
+ @_(
366
+ "doc_tag enum_ref enum_block",
367
+ "doc_tag dotted_name enum_ref enum_block",
368
+ )
369
+ def enum_def(self, p: YaccProduction) -> YaccProduction:
370
+ """Enum def rule."""
371
+ return p
372
+
373
+ @_(
374
+ "LBRACE RBRACE",
375
+ "LBRACE enum_stmt_list RBRACE",
376
+ )
377
+ def enum_block(self, p: YaccProduction) -> YaccProduction:
378
+ """Enum block rule."""
379
+ return p
380
+
381
+ @_(
382
+ "NAME",
383
+ "enum_op_assign",
384
+ "enum_stmt_list COMMA NAME",
385
+ "enum_stmt_list COMMA enum_op_assign",
386
+ )
387
+ def enum_stmt_list(self, p: YaccProduction) -> YaccProduction:
388
+ """Enum op list rule."""
389
+ return p
390
+
391
+ @_(
392
+ "NAME EQ expression",
393
+ )
394
+ def enum_op_assign(self, p: YaccProduction) -> YaccProduction:
395
+ """Enum op assign rule."""
396
+ return p
397
+
398
+ # Attribute blocks
399
+ # ----------------
400
+ @_(
401
+ "LBRACE RBRACE",
402
+ "LBRACE member_stmt_list RBRACE",
403
+ )
404
+ def member_block(self, p: YaccProduction) -> YaccProduction:
405
+ """Attribute block rule."""
406
+ return p
407
+
408
+ @_(
409
+ "member_stmt",
410
+ "member_stmt_list member_stmt",
411
+ )
412
+ def member_stmt_list(self, p: YaccProduction) -> YaccProduction:
413
+ """Attribute statement list rule."""
414
+ return p
415
+
416
+ @_(
417
+ "has_stmt",
418
+ "ability",
419
+ )
420
+ def member_stmt(self, p: YaccProduction) -> YaccProduction:
421
+ """Attribute statement rule."""
422
+ return p
423
+
424
+ # Has statements
425
+ # --------------
426
+ @_(
427
+ "doc_tag static_tag KW_HAS access_tag has_assign_clause SEMI",
428
+ "doc_tag static_tag KW_FREEZE access_tag has_assign_clause SEMI",
429
+ )
430
+ def has_stmt(self, p: YaccProduction) -> YaccProduction:
431
+ """Has statement rule."""
432
+ return p
433
+
434
+ @_(
435
+ "empty",
436
+ "KW_STATIC",
437
+ )
438
+ def static_tag(self, p: YaccProduction) -> YaccProduction:
439
+ """KW_Static tag rule."""
440
+ return p
441
+
442
+ @_(
443
+ "typed_has_clause",
444
+ "has_assign_clause COMMA typed_has_clause",
445
+ )
446
+ def has_assign_clause(self, p: YaccProduction) -> YaccProduction:
447
+ """Has assign list rule."""
448
+ return p
449
+
450
+ @_(
451
+ "NAME type_tag",
452
+ "NAME type_tag EQ expression",
453
+ )
454
+ def typed_has_clause(self, p: YaccProduction) -> YaccProduction:
455
+ """Parameter variable rule rule."""
456
+ return p
457
+
458
+ @_("COLON type_spec")
459
+ def type_tag(self, p: YaccProduction) -> YaccProduction:
460
+ """Type hint rule."""
461
+ return p
462
+
463
+ @_(
464
+ "empty",
465
+ "RETURN_HINT type_spec",
466
+ )
467
+ def return_type_tag(self, p: YaccProduction) -> YaccProduction:
468
+ """Type hint rule."""
469
+ return p
470
+
471
+ @_(
472
+ "single_type",
473
+ "type_spec NULL_OK",
474
+ "type_spec BW_OR single_type",
475
+ )
476
+ def type_spec(self, p: YaccProduction) -> YaccProduction:
477
+ """Type hint rule."""
478
+ return p
479
+
480
+ @_(
481
+ "builtin_type",
482
+ "NULL",
483
+ "dotted_name",
484
+ "TYP_LIST LSQUARE single_type RSQUARE",
485
+ "TYP_TUPLE LSQUARE single_type RSQUARE",
486
+ "TYP_SET LSQUARE single_type RSQUARE",
487
+ "TYP_DICT LSQUARE single_type COMMA single_type RSQUARE",
488
+ )
489
+ def single_type(self, p: YaccProduction) -> YaccProduction:
490
+ """Type hint rule."""
491
+ return p
492
+
493
+ @_(
494
+ "TYP_STRING",
495
+ "TYP_BYTES",
496
+ "TYP_INT",
497
+ "TYP_FLOAT",
498
+ "TYP_LIST",
499
+ "TYP_TUPLE",
500
+ "TYP_SET",
501
+ "TYP_DICT",
502
+ "TYP_BOOL",
503
+ "TYP_ANY",
504
+ "TYP_TYPE",
505
+ )
506
+ def builtin_type(self, p: YaccProduction) -> YaccProduction:
507
+ """Any type rule."""
508
+ return p
509
+
510
+ # Codeblock statements
511
+ # --------------------
512
+ @_(
513
+ "LBRACE RBRACE",
514
+ "LBRACE statement_list RBRACE",
515
+ )
516
+ def code_block(self, p: YaccProduction) -> YaccProduction:
517
+ """Code block rule."""
518
+ return p
519
+
520
+ @_(
521
+ "statement_list statement",
522
+ "statement",
523
+ )
524
+ def statement_list(self, p: YaccProduction) -> YaccProduction:
525
+ """Statement list rule."""
526
+ return p
527
+
528
+ @_(
529
+ "architype_decl",
530
+ "ability_decl",
531
+ "typed_ctx_block",
532
+ "assignment SEMI",
533
+ "static_assignment",
534
+ "expression SEMI",
535
+ "if_stmt",
536
+ "try_stmt",
537
+ "for_stmt",
538
+ "while_stmt",
539
+ "with_stmt",
540
+ "raise_stmt SEMI",
541
+ "assert_stmt SEMI",
542
+ "ctrl_stmt SEMI",
543
+ "delete_stmt SEMI",
544
+ "report_stmt SEMI",
545
+ "return_stmt SEMI",
546
+ "yield_stmt SEMI",
547
+ "await_stmt SEMI",
548
+ "walker_stmt",
549
+ )
550
+ def statement(self, p: YaccProduction) -> YaccProduction:
551
+ """Statement rule."""
552
+ return p
553
+
554
+ @_("RETURN_HINT type_spec code_block")
555
+ def typed_ctx_block(self, p: YaccProduction) -> YaccProduction:
556
+ """Typed context block rule."""
557
+ return p
558
+
559
+ @_(
560
+ "KW_IF expression code_block",
561
+ "KW_IF expression code_block else_stmt",
562
+ "KW_IF expression code_block elif_list",
563
+ "KW_IF expression code_block elif_list else_stmt",
564
+ )
565
+ def if_stmt(self, p: YaccProduction) -> YaccProduction:
566
+ """If statement rule."""
567
+ return p
568
+
569
+ @_(
570
+ "KW_ELIF expression code_block",
571
+ "elif_list KW_ELIF expression code_block",
572
+ )
573
+ def elif_list(self, p: YaccProduction) -> YaccProduction:
574
+ """Else if statement list rule."""
575
+ return p
576
+
577
+ @_("KW_ELSE code_block")
578
+ def else_stmt(self, p: YaccProduction) -> YaccProduction:
579
+ """Else statement rule."""
580
+ return p
581
+
582
+ @_(
583
+ "KW_TRY code_block",
584
+ "KW_TRY code_block except_list",
585
+ "KW_TRY code_block finally_stmt",
586
+ "KW_TRY code_block except_list finally_stmt",
587
+ )
588
+ def try_stmt(self, p: YaccProduction) -> YaccProduction:
589
+ """Try statement rule."""
590
+ return p
591
+
592
+ @_(
593
+ "except_def",
594
+ "except_list except_def",
595
+ )
596
+ def except_list(self, p: YaccProduction) -> YaccProduction:
597
+ """Except statement list rule."""
598
+ return p
599
+
600
+ @_(
601
+ "KW_EXCEPT expression code_block",
602
+ "KW_EXCEPT expression KW_AS NAME code_block",
603
+ )
604
+ def except_def(self, p: YaccProduction) -> YaccProduction:
605
+ """Except definition rule."""
606
+ return p
607
+
608
+ @_(
609
+ "KW_FINALLY code_block",
610
+ )
611
+ def finally_stmt(self, p: YaccProduction) -> YaccProduction:
612
+ """Except finally statement rule."""
613
+ return p
614
+
615
+ @_(
616
+ "KW_FOR assignment KW_TO expression KW_BY expression code_block",
617
+ "KW_FOR NAME KW_IN expression code_block",
618
+ "KW_FOR NAME COMMA NAME KW_IN expression code_block",
619
+ )
620
+ def for_stmt(self, p: YaccProduction) -> YaccProduction:
621
+ """For statement rule."""
622
+ return p
623
+
624
+ @_("KW_WHILE expression code_block")
625
+ def while_stmt(self, p: YaccProduction) -> YaccProduction:
626
+ """While statement rule."""
627
+ return p
628
+
629
+ @_("KW_WITH expr_as_list code_block")
630
+ def with_stmt(self, p: YaccProduction) -> YaccProduction:
631
+ """With statement rule."""
632
+ return p
633
+
634
+ @_(
635
+ "expression",
636
+ "expression KW_AS NAME",
637
+ "expr_as_list COMMA NAME",
638
+ "expr_as_list COMMA expression KW_AS NAME",
639
+ )
640
+ def expr_as_list(self, p: YaccProduction) -> YaccProduction:
641
+ """Name as list rule."""
642
+ return p
643
+
644
+ @_(
645
+ "KW_RAISE",
646
+ "KW_RAISE expression",
647
+ )
648
+ def raise_stmt(self, p: YaccProduction) -> YaccProduction:
649
+ """Raise statement rule."""
650
+ return p
651
+
652
+ @_(
653
+ "KW_ASSERT expression",
654
+ "KW_ASSERT expression COMMA expression",
655
+ )
656
+ def assert_stmt(self, p: YaccProduction) -> YaccProduction:
657
+ """Assert statement rule."""
658
+ return p
659
+
660
+ @_(
661
+ "KW_CONTINUE",
662
+ "KW_BREAK",
663
+ "KW_SKIP",
664
+ )
665
+ def ctrl_stmt(self, p: YaccProduction) -> YaccProduction:
666
+ """Control statement rule."""
667
+ return p
668
+
669
+ @_("KW_DELETE expression")
670
+ def delete_stmt(self, p: YaccProduction) -> YaccProduction:
671
+ """Delete statement rule."""
672
+ return p
673
+
674
+ @_(
675
+ "KW_REPORT expression",
676
+ )
677
+ def report_stmt(self, p: YaccProduction) -> YaccProduction:
678
+ """Report statement rule."""
679
+ return p
680
+
681
+ @_(
682
+ "KW_RETURN",
683
+ "KW_RETURN expression",
684
+ )
685
+ def return_stmt(self, p: YaccProduction) -> YaccProduction:
686
+ """Report statement rule."""
687
+ return p
688
+
689
+ @_(
690
+ "KW_YIELD",
691
+ "KW_YIELD expression",
692
+ )
693
+ def yield_stmt(self, p: YaccProduction) -> YaccProduction:
694
+ """Yield statement rule."""
695
+ return p
696
+
697
+ @_(
698
+ "ignore_stmt SEMI",
699
+ "visit_stmt",
700
+ "revisit_stmt",
701
+ "disengage_stmt SEMI",
702
+ )
703
+ def walker_stmt(self, p: YaccProduction) -> YaccProduction:
704
+ """Walker statement rule."""
705
+ return p
706
+
707
+ @_("KW_IGNORE expression")
708
+ def ignore_stmt(self, p: YaccProduction) -> YaccProduction:
709
+ """Ignore statement rule."""
710
+ return p
711
+
712
+ @_(
713
+ "KW_VISIT expression SEMI",
714
+ "KW_VISIT sub_name_dotted expression SEMI",
715
+ "KW_VISIT expression else_stmt",
716
+ "KW_VISIT sub_name_dotted expression else_stmt",
717
+ )
718
+ def visit_stmt(self, p: YaccProduction) -> YaccProduction:
719
+ """Visit statement rule."""
720
+ return p
721
+
722
+ @_(
723
+ "KW_REVISIT SEMI",
724
+ "KW_REVISIT expression SEMI",
725
+ "KW_REVISIT else_stmt",
726
+ "KW_REVISIT expression else_stmt",
727
+ )
728
+ def revisit_stmt(self, p: YaccProduction) -> YaccProduction:
729
+ """Visit statement rule."""
730
+ return p
731
+
732
+ @_("KW_DISENGAGE")
733
+ def disengage_stmt(self, p: YaccProduction) -> YaccProduction:
734
+ """Disengage statement rule."""
735
+ return p
736
+
737
+ @_("KW_AWAIT expression")
738
+ def await_stmt(self, p: YaccProduction) -> YaccProduction:
739
+ """Sync statement rule."""
740
+ return p
741
+
742
+ # Expression rules (precedence built into grammar)
743
+ # ------------------------------------------------
744
+ @_(
745
+ "atom EQ expression",
746
+ "KW_FREEZE atom EQ expression",
747
+ )
748
+ def assignment(self, p: YaccProduction) -> YaccProduction:
749
+ """Rule for assignment statement."""
750
+ return p
751
+
752
+ @_("KW_HAS assignment_list SEMI")
753
+ def static_assignment(self, p: YaccProduction) -> YaccProduction:
754
+ """Rule for static assignment statement."""
755
+ return p
756
+
757
+ @_(
758
+ "pipe",
759
+ "pipe KW_IF expression KW_ELSE expression",
760
+ )
761
+ def expression(self, p: YaccProduction) -> YaccProduction:
762
+ """Expression rule."""
763
+ return p
764
+
765
+ @_(
766
+ "pipe_back",
767
+ "pipe_back PIPE_FWD pipe", # casting achieved here
768
+ )
769
+ def pipe(self, p: YaccProduction) -> YaccProduction:
770
+ """Pipe forward rule."""
771
+ return p
772
+
773
+ @_(
774
+ "elvis_check",
775
+ "elvis_check PIPE_BKWD pipe_back",
776
+ )
777
+ def pipe_back(self, p: YaccProduction) -> YaccProduction:
778
+ """Pipe backward rule."""
779
+ return p
780
+
781
+ @_(
782
+ "bitwise_or",
783
+ "bitwise_or ELVIS_OP elvis_check",
784
+ )
785
+ def elvis_check(self, p: YaccProduction) -> YaccProduction:
786
+ """Expression rule."""
787
+ return p
788
+
789
+ @_(
790
+ "bitwise_xor",
791
+ "bitwise_xor BW_OR bitwise_or",
792
+ )
793
+ def bitwise_or(self, p: YaccProduction) -> YaccProduction:
794
+ """Bitwise or rule."""
795
+ return p
796
+
797
+ @_(
798
+ "bitwise_and",
799
+ "bitwise_and BW_XOR bitwise_xor",
800
+ )
801
+ def bitwise_xor(self, p: YaccProduction) -> YaccProduction:
802
+ """Bitwise xor rule."""
803
+ return p
804
+
805
+ @_(
806
+ "shift",
807
+ "shift BW_AND bitwise_and",
808
+ )
809
+ def bitwise_and(self, p: YaccProduction) -> YaccProduction:
810
+ """Bitwise and rule."""
811
+ return p
812
+
813
+ @_(
814
+ "logical",
815
+ "logical LSHIFT shift",
816
+ "logical RSHIFT shift",
817
+ )
818
+ def shift(self, p: YaccProduction) -> YaccProduction:
819
+ """Shift expression rule."""
820
+ return p
821
+
822
+ @_(
823
+ "compare",
824
+ "compare KW_AND logical",
825
+ "compare KW_OR logical",
826
+ "NOT logical",
827
+ )
828
+ def logical(self, p: YaccProduction) -> YaccProduction:
829
+ """Logical rule."""
830
+ return p
831
+
832
+ @_(
833
+ "arithmetic",
834
+ "arithmetic cmp_op compare",
835
+ )
836
+ def compare(self, p: YaccProduction) -> YaccProduction:
837
+ """Compare rule."""
838
+ return p
839
+
840
+ @_(
841
+ "term",
842
+ "term PLUS arithmetic",
843
+ "term MINUS arithmetic",
844
+ )
845
+ def arithmetic(self, p: YaccProduction) -> YaccProduction:
846
+ """Arithmetic rule."""
847
+ return p
848
+
849
+ @_(
850
+ "factor",
851
+ "factor STAR_MUL term",
852
+ "factor FLOOR_DIV term",
853
+ "factor DIV term",
854
+ "factor MOD term",
855
+ )
856
+ def term(self, p: YaccProduction) -> YaccProduction:
857
+ """Term rule."""
858
+ return p
859
+
860
+ @_(
861
+ "PLUS factor",
862
+ "MINUS factor",
863
+ "BW_NOT factor",
864
+ "power",
865
+ )
866
+ def factor(self, p: YaccProduction) -> YaccProduction:
867
+ """Factor rule."""
868
+ return p
869
+
870
+ @_(
871
+ "connect",
872
+ "connect STAR_POW power",
873
+ )
874
+ def power(self, p: YaccProduction) -> YaccProduction:
875
+ """Power rule."""
876
+ return p
877
+
878
+ @_(
879
+ "atomic_pipe disconnect_op connect",
880
+ "atomic_pipe connect_op connect",
881
+ "atomic_pipe",
882
+ )
883
+ def connect(self, p: YaccProduction) -> YaccProduction:
884
+ """Connect rule."""
885
+ return p
886
+
887
+ @_(
888
+ "atomic_pipe A_PIPE_FWD atomic_pipe_back",
889
+ "atomic_pipe KW_SPAWN atomic_pipe_back", # For high level readability
890
+ "atomic_pipe_back",
891
+ )
892
+ def atomic_pipe(self, p: YaccProduction) -> YaccProduction:
893
+ """Pipe forward rule."""
894
+ return p
895
+
896
+ @_(
897
+ "atomic_pipe_back A_PIPE_BKWD unpack",
898
+ "unpack",
899
+ )
900
+ def atomic_pipe_back(self, p: YaccProduction) -> YaccProduction:
901
+ """Pipe backward rule."""
902
+ return p
903
+
904
+ @_(
905
+ "STAR_POW atom",
906
+ "STAR_MUL atom",
907
+ "ref",
908
+ )
909
+ def unpack(self, p: YaccProduction) -> YaccProduction:
910
+ """Unpack rule."""
911
+ return p
912
+
913
+ @_(
914
+ "BW_AND ds_call",
915
+ "ds_call",
916
+ )
917
+ def ref(self, p: YaccProduction) -> YaccProduction:
918
+ """Unpack rule."""
919
+ return p
920
+
921
+ @_(
922
+ "KW_SPAWN walrus_assign",
923
+ "A_PIPE_FWD walrus_assign",
924
+ "PIPE_FWD walrus_assign",
925
+ "walrus_assign",
926
+ )
927
+ def ds_call(self, p: YaccProduction) -> YaccProduction:
928
+ """Unpack rule."""
929
+ return p
930
+
931
+ @_(
932
+ "atom",
933
+ "atom walrus_op walrus_assign",
934
+ )
935
+ def walrus_assign(self, p: YaccProduction) -> YaccProduction:
936
+ """Walrus assignment rule."""
937
+ return p
938
+
939
+ @_(
940
+ "WALRUS_EQ",
941
+ "ADD_EQ",
942
+ "SUB_EQ",
943
+ "MUL_EQ",
944
+ "FLOOR_DIV_EQ",
945
+ "DIV_EQ",
946
+ "MOD_EQ",
947
+ "BW_AND_EQ",
948
+ "BW_OR_EQ",
949
+ "BW_XOR_EQ",
950
+ "BW_NOT_EQ",
951
+ "LSHIFT_EQ",
952
+ "RSHIFT_EQ",
953
+ )
954
+ def walrus_op(self, p: YaccProduction) -> YaccProduction:
955
+ """Production Assignment rule."""
956
+ return p
957
+
958
+ @_(
959
+ "EE",
960
+ "LT",
961
+ "GT",
962
+ "LTE",
963
+ "GTE",
964
+ "NE",
965
+ "KW_IN",
966
+ "KW_NIN",
967
+ "KW_IS",
968
+ "KW_ISN",
969
+ )
970
+ def cmp_op(self, p: YaccProduction) -> YaccProduction:
971
+ """Compare operator rule."""
972
+ return p
973
+
974
+ # Atom rules
975
+ # --------------------
976
+ @_(
977
+ "atom_literal",
978
+ "atom_collection",
979
+ "LPAREN expression RPAREN",
980
+ "atomic_chain",
981
+ "all_refs",
982
+ "edge_op_ref",
983
+ )
984
+ def atom(self, p: YaccProduction) -> YaccProduction:
985
+ """Atom rule."""
986
+ return p
987
+
988
+ @_(
989
+ "INT",
990
+ "HEX",
991
+ "BIN",
992
+ "OCT",
993
+ "FLOAT",
994
+ "multistring",
995
+ "BOOL",
996
+ "NULL",
997
+ "builtin_type",
998
+ )
999
+ def atom_literal(self, p: YaccProduction) -> YaccProduction:
1000
+ """Atom rule."""
1001
+ return p
1002
+
1003
+ @_(
1004
+ "list_val",
1005
+ "tuple_val",
1006
+ "set_val",
1007
+ "dict_val",
1008
+ "list_compr",
1009
+ "gen_compr",
1010
+ "set_compr",
1011
+ "dict_compr",
1012
+ )
1013
+ def atom_collection(self, p: YaccProduction) -> YaccProduction:
1014
+ """Atom rule."""
1015
+ return p
1016
+
1017
+ @_(
1018
+ "STRING",
1019
+ "FSTRING",
1020
+ "multistring STRING",
1021
+ "multistring FSTRING",
1022
+ )
1023
+ def multistring(self, p: YaccProduction) -> YaccProduction:
1024
+ """Multistring rule."""
1025
+ return p
1026
+
1027
+ @_(
1028
+ "LSQUARE RSQUARE",
1029
+ "LSQUARE expr_list RSQUARE",
1030
+ )
1031
+ def list_val(self, p: YaccProduction) -> YaccProduction:
1032
+ """List value rule."""
1033
+ return p
1034
+
1035
+ @_(
1036
+ "LPAREN RPAREN",
1037
+ "LPAREN tuple_list RPAREN",
1038
+ )
1039
+ def tuple_val(self, p: YaccProduction) -> YaccProduction:
1040
+ """Tuple value rule."""
1041
+ return p
1042
+
1043
+ @_(
1044
+ "LBRACE expr_list RBRACE",
1045
+ )
1046
+ def set_val(self, p: YaccProduction) -> YaccProduction:
1047
+ """Set value rule."""
1048
+ return p
1049
+
1050
+ @_(
1051
+ "expression",
1052
+ "expr_list COMMA expression",
1053
+ )
1054
+ def expr_list(self, p: YaccProduction) -> YaccProduction:
1055
+ """Expression list rule."""
1056
+ return p
1057
+
1058
+ @_(
1059
+ "expression COMMA",
1060
+ "expression COMMA expr_list",
1061
+ "assignment_list",
1062
+ "expression COMMA assignment_list",
1063
+ "expression COMMA expr_list COMMA assignment_list",
1064
+ )
1065
+ def tuple_list(self, p: YaccProduction) -> YaccProduction:
1066
+ """Tuple list rule."""
1067
+ return p
1068
+
1069
+ @_(
1070
+ "LBRACE RBRACE",
1071
+ "LBRACE kv_pairs RBRACE",
1072
+ )
1073
+ def dict_val(self, p: YaccProduction) -> YaccProduction:
1074
+ """Production for dictionary value rule."""
1075
+ return p
1076
+
1077
+ @_("LSQUARE inner_compr RSQUARE")
1078
+ def list_compr(self, p: YaccProduction) -> YaccProduction:
1079
+ """Comprehension rule."""
1080
+ return p
1081
+
1082
+ @_("LPAREN inner_compr RPAREN")
1083
+ def gen_compr(self, p: YaccProduction) -> YaccProduction:
1084
+ """Comprehension rule."""
1085
+ return p
1086
+
1087
+ @_("LBRACE inner_compr RBRACE")
1088
+ def set_compr(self, p: YaccProduction) -> YaccProduction:
1089
+ """Comprehension rule."""
1090
+ return p
1091
+
1092
+ @_(
1093
+ "expression KW_FOR NAME KW_IN walrus_assign",
1094
+ "expression KW_FOR NAME KW_IN walrus_assign KW_IF expression",
1095
+ )
1096
+ def inner_compr(self, p: YaccProduction) -> YaccProduction:
1097
+ """Comprehension rule."""
1098
+ return p
1099
+
1100
+ @_(
1101
+ "LBRACE expression COLON expression KW_FOR NAME KW_IN walrus_assign RBRACE",
1102
+ "LBRACE expression COLON expression KW_FOR NAME KW_IN walrus_assign KW_IF expression RBRACE",
1103
+ "LBRACE expression COLON expression KW_FOR NAME COMMA NAME KW_IN walrus_assign RBRACE",
1104
+ "LBRACE expression COLON expression KW_FOR NAME COMMA NAME KW_IN walrus_assign KW_IF expression RBRACE",
1105
+ )
1106
+ def dict_compr(self, p: YaccProduction) -> YaccProduction:
1107
+ """Comprehension rule."""
1108
+ return p
1109
+
1110
+ @_(
1111
+ "expression COLON expression",
1112
+ "kv_pairs COMMA expression COLON expression",
1113
+ )
1114
+ def kv_pairs(self, p: YaccProduction) -> YaccProduction:
1115
+ """Key/value pairs rule."""
1116
+ return p
1117
+
1118
+ @_(
1119
+ "atomic_chain_safe",
1120
+ "atomic_chain_unsafe",
1121
+ "atomic_call",
1122
+ )
1123
+ def atomic_chain(self, p: YaccProduction) -> YaccProduction:
1124
+ """Atom trailer rule."""
1125
+ return p
1126
+
1127
+ @_(
1128
+ "atom DOT all_refs",
1129
+ "atom DOT_FWD all_refs",
1130
+ "atom DOT_BKWD all_refs",
1131
+ "atom index_slice",
1132
+ "atom arch_ref",
1133
+ "atom edge_op_ref",
1134
+ "atom filter_compr",
1135
+ )
1136
+ def atomic_chain_unsafe(self, p: YaccProduction) -> YaccProduction:
1137
+ """Atom trailer rule."""
1138
+ return p
1139
+
1140
+ @_(
1141
+ "atom NULL_OK DOT all_refs",
1142
+ "atom NULL_OK DOT_FWD all_refs",
1143
+ "atom NULL_OK DOT_BKWD all_refs",
1144
+ "atom NULL_OK index_slice",
1145
+ "atom NULL_OK arch_ref",
1146
+ "atom NULL_OK edge_op_ref",
1147
+ "atom NULL_OK filter_compr",
1148
+ )
1149
+ def atomic_chain_safe(self, p: YaccProduction) -> YaccProduction:
1150
+ """Atom trailer rule."""
1151
+ return p
1152
+
1153
+ @_("atom func_call_tail")
1154
+ def atomic_call(self, p: YaccProduction) -> YaccProduction:
1155
+ """Ability call rule."""
1156
+ return p
1157
+
1158
+ @_(
1159
+ "LPAREN RPAREN",
1160
+ "LPAREN param_list RPAREN",
1161
+ )
1162
+ def func_call_tail(self, p: YaccProduction) -> YaccProduction:
1163
+ """Rule for function calls."""
1164
+ return p
1165
+
1166
+ @_(
1167
+ "expr_list",
1168
+ "assignment_list",
1169
+ "expr_list COMMA assignment_list",
1170
+ )
1171
+ def param_list(self, p: YaccProduction) -> YaccProduction:
1172
+ """Parameter list rule."""
1173
+ return p
1174
+
1175
+ @_(
1176
+ "assignment",
1177
+ "assignment_list COMMA assignment",
1178
+ )
1179
+ def assignment_list(self, p: YaccProduction) -> YaccProduction:
1180
+ """Keyword expression list rule."""
1181
+ return p
1182
+
1183
+ @_(
1184
+ "LSQUARE expression RSQUARE",
1185
+ "LSQUARE expression COLON expression RSQUARE",
1186
+ "LSQUARE expression COLON RSQUARE",
1187
+ "LSQUARE COLON expression RSQUARE",
1188
+ )
1189
+ def index_slice(self, p: YaccProduction) -> YaccProduction:
1190
+ """Index/slice rule."""
1191
+ return p
1192
+
1193
+ @_("HERE_OP")
1194
+ def here_ref(self, p: YaccProduction) -> YaccProduction:
1195
+ """Global reference rule."""
1196
+ return p
1197
+
1198
+ @_("SELF_OP")
1199
+ def self_ref(self, p: YaccProduction) -> YaccProduction:
1200
+ """Global reference rule."""
1201
+ return p
1202
+
1203
+ @_("SUPER_OP")
1204
+ def super_ref(self, p: YaccProduction) -> YaccProduction:
1205
+ """Global reference rule."""
1206
+ return p
1207
+
1208
+ @_("ROOT_OP")
1209
+ def root_ref(self, p: YaccProduction) -> YaccProduction:
1210
+ """Global reference rule."""
1211
+ return p
1212
+
1213
+ # Architype reference rules
1214
+ # -------------------------
1215
+ @_(
1216
+ "strict_arch_ref",
1217
+ "ability_ref",
1218
+ "enum_ref",
1219
+ "global_ref",
1220
+ )
1221
+ def arch_ref(self, p: YaccProduction) -> YaccProduction:
1222
+ """Architype reference rule."""
1223
+ return p
1224
+
1225
+ @_(
1226
+ "node_ref",
1227
+ "edge_ref",
1228
+ "walker_ref",
1229
+ "object_ref",
1230
+ )
1231
+ def strict_arch_ref(self, p: YaccProduction) -> YaccProduction:
1232
+ """Strict Architype reference rule."""
1233
+ return p
1234
+
1235
+ @_("NODE_OP NAME")
1236
+ def node_ref(self, p: YaccProduction) -> YaccProduction:
1237
+ """Node reference rule."""
1238
+ return p
1239
+
1240
+ @_("EDGE_OP NAME")
1241
+ def edge_ref(self, p: YaccProduction) -> YaccProduction:
1242
+ """Edge reference rule."""
1243
+ return p
1244
+
1245
+ @_("WALKER_OP NAME")
1246
+ def walker_ref(self, p: YaccProduction) -> YaccProduction:
1247
+ """Walker reference rule."""
1248
+ return p
1249
+
1250
+ @_("OBJECT_OP NAME")
1251
+ def object_ref(self, p: YaccProduction) -> YaccProduction:
1252
+ """Object type reference rule."""
1253
+ return p
1254
+
1255
+ @_("ENUM_OP NAME")
1256
+ def enum_ref(self, p: YaccProduction) -> YaccProduction:
1257
+ """Object type reference rule."""
1258
+ return p
1259
+
1260
+ @_("ABILITY_OP NAME")
1261
+ def ability_ref(self, p: YaccProduction) -> YaccProduction:
1262
+ """Ability reference rule."""
1263
+ return p
1264
+
1265
+ @_("GLOBAL_OP NAME")
1266
+ def global_ref(self, p: YaccProduction) -> YaccProduction:
1267
+ """Global reference rule."""
1268
+ return p
1269
+
1270
+ # Node / Edge reference and connection rules
1271
+ # ------------------------------------------
1272
+ @_(
1273
+ "edge_to",
1274
+ "edge_from",
1275
+ "edge_any",
1276
+ )
1277
+ def edge_op_ref(self, p: YaccProduction) -> YaccProduction:
1278
+ """Edge reference rule."""
1279
+ return p
1280
+
1281
+ @_(
1282
+ "ARROW_R",
1283
+ "ARROW_R_p1 expression ARROW_R_p2",
1284
+ "ARROW_R_p1 expression COLON filter_compare_list ARROW_R_p2",
1285
+ )
1286
+ def edge_to(self, p: YaccProduction) -> YaccProduction:
1287
+ """Edge to rule."""
1288
+ return p
1289
+
1290
+ @_(
1291
+ "ARROW_L",
1292
+ "ARROW_L_p1 expression ARROW_L_p2",
1293
+ "ARROW_L_p1 expression COLON filter_compare_list ARROW_L_p2",
1294
+ )
1295
+ def edge_from(self, p: YaccProduction) -> YaccProduction:
1296
+ """Edge from rule."""
1297
+ return p
1298
+
1299
+ @_(
1300
+ "ARROW_BI",
1301
+ "ARROW_L_p1 expression ARROW_R_p2",
1302
+ "ARROW_L_p1 expression COLON filter_compare_list ARROW_R_p2",
1303
+ )
1304
+ def edge_any(self, p: YaccProduction) -> YaccProduction:
1305
+ """Edge any rule."""
1306
+ return p
1307
+
1308
+ @_(
1309
+ "connect_to",
1310
+ "connect_from",
1311
+ )
1312
+ def connect_op(self, p: YaccProduction) -> YaccProduction:
1313
+ """Connect operator rule."""
1314
+ return p
1315
+
1316
+ @_("NOT edge_op_ref")
1317
+ def disconnect_op(self, p: YaccProduction) -> YaccProduction:
1318
+ """Connect operator not rule."""
1319
+ return p
1320
+
1321
+ @_(
1322
+ "CARROW_R",
1323
+ "CARROW_R_p1 expression CARROW_R_p2",
1324
+ "CARROW_R_p1 expression COLON assignment_list CARROW_R_p2",
1325
+ )
1326
+ def connect_to(self, p: YaccProduction) -> YaccProduction:
1327
+ """Connect to rule."""
1328
+ return p
1329
+
1330
+ @_(
1331
+ "CARROW_L",
1332
+ "CARROW_L_p1 expression CARROW_L_p2",
1333
+ "CARROW_L_p1 expression COLON assignment_list CARROW_L_p2",
1334
+ )
1335
+ def connect_from(self, p: YaccProduction) -> YaccProduction:
1336
+ """Connect from rule."""
1337
+ return p
1338
+
1339
+ @_("LPAREN EQ filter_compare_list RPAREN")
1340
+ def filter_compr(self, p: YaccProduction) -> YaccProduction:
1341
+ """Filter context rule."""
1342
+ return p
1343
+
1344
+ @_(
1345
+ "NAME cmp_op expression",
1346
+ "filter_compare_list COMMA NAME cmp_op expression",
1347
+ )
1348
+ def filter_compare_list(self, p: YaccProduction) -> YaccProduction:
1349
+ """Filter comparison list rule."""
1350
+ return p
1351
+
1352
+ @_("")
1353
+ def empty(self, p: YaccProduction) -> YaccProduction:
1354
+ """Empty rule."""
1355
+ return p
1356
+
1357
+ # Transform Implementations
1358
+ # -------------------------
1359
+ def transform(self, ir: list) -> ast.AstNode:
1360
+ """Tokenize the input."""
1361
+ return self.parse(ir)
1362
+
1363
+ def error(self, p: YaccProduction) -> None:
1364
+ """Improved error handling for Jac Parser."""
1365
+ self.cur_line = p.lineno if p else 0
1366
+ if not p:
1367
+ self.log_error("Escaping at end of File! Not Valid Jac!\n")
1368
+ return
1369
+ self.log_error(f'JParse Error, incorrect usage of "{p.value}" ({p.type})\n')
1370
+
1371
+ # Read ahead looking for a closing '}'
1372
+ while True:
1373
+ tok = next(self.tokens, None) # type: ignore
1374
+ if not tok or tok.type == "RBRACE":
1375
+ break
1376
+ self.restart()
1377
+
1378
+
1379
+ def fstr_sly_parser_hack() -> Optional[dict]:
1380
+ """Hack to map expression parser for fstrings in sly parser."""
1381
+ if "__file__" in globals():
1382
+ with open(__file__, "r") as file:
1383
+ module_data = file.read()
1384
+
1385
+ new_module_data = module_data.replace(
1386
+ 'start = "module"', 'start = "expression"'
1387
+ ).replace('debugfile = "parser.out"', "")
1388
+ new_module_namespace = {}
1389
+ exec(new_module_data, new_module_namespace)
1390
+ return (
1391
+ new_module_namespace["JacParser"]
1392
+ if "JacParser" in new_module_namespace
1393
+ else None
1394
+ )
1395
+
1396
+
1397
+ JacParserExpr = fstr_sly_parser_hack()
1398
+
1399
+
1400
+ def parse_tree_to_ast(
1401
+ tree: tuple, parent: Optional[ast.AstNode] = None, lineno: int = 0
1402
+ ) -> ast.AstNode:
1403
+ """Convert parser output to ast, also parses fstrings."""
1404
+
1405
+ def find_and_concat_fstr_pieces(tup: tuple) -> str:
1406
+ result = ""
1407
+ for item in tup:
1408
+ if isinstance(item, tuple):
1409
+ result += find_and_concat_fstr_pieces(item)
1410
+ elif isinstance(item, LexToken) and item.type == "PIECE":
1411
+ result += item.value
1412
+ return result
1413
+
1414
+ from jaclang.utils.fstring_parser import FStringLexer, FStringParser
1415
+ from jaclang.utils.sly.lex import Token as LexToken
1416
+
1417
+ ast_tree: ast.AstNode = None
1418
+ if not isinstance(tree, ast.AstNode):
1419
+ if isinstance(tree, tuple):
1420
+ if tree[0] == "fstr_expr":
1421
+ tree = JacParserExpr(
1422
+ mod_path="",
1423
+ input_ir=JacLexer(
1424
+ mod_path="", input_ir=find_and_concat_fstr_pieces(tree)
1425
+ ).ir,
1426
+ ).ir_tup[2]
1427
+ kids = tree[2:]
1428
+ ast_tree = ast.Parse(
1429
+ name=tree[0],
1430
+ parent=parent,
1431
+ mod_link=None,
1432
+ line=tree[1] if lineno == 0 else lineno,
1433
+ kid=[],
1434
+ )
1435
+ ast_tree.kid = [
1436
+ parse_tree_to_ast(x, parent=ast_tree, lineno=lineno) for x in kids
1437
+ ]
1438
+ elif isinstance(tree, LexToken):
1439
+ if tree.type == "FSTRING":
1440
+ lineno = tree.lineno
1441
+ ftree = FStringParser().parse(FStringLexer().tokenize(tree.value))
1442
+ return parse_tree_to_ast(ftree, parent=parent, lineno=lineno)
1443
+ else:
1444
+ meta = {
1445
+ "name": tree.type,
1446
+ "parent": parent,
1447
+ "mod_link": None,
1448
+ "value": tree.value,
1449
+ "kid": [],
1450
+ "line": tree.lineno if lineno == 0 else lineno,
1451
+ "col_start": tree.index - tree.lineidx + 1,
1452
+ "col_end": tree.end - tree.lineidx + 1,
1453
+ }
1454
+ if tree.type == "NAME":
1455
+ ast_tree = ast.Name(already_declared=False, **meta)
1456
+ elif tree.type == "FLOAT":
1457
+ ast_tree = ast.Constant(typ=float, **meta)
1458
+ elif tree.type in ["INT", "HEX", "BIN", "OCT"]:
1459
+ ast_tree = ast.Constant(typ=int, **meta)
1460
+ elif tree.type in ["STRING", "FSTRING"]:
1461
+ ast_tree = ast.Constant(typ=str, **meta)
1462
+ elif tree.type == "BOOL":
1463
+ ast_tree = ast.Constant(typ=bool, **meta)
1464
+ elif tree.type == "NULL":
1465
+ ast_tree = ast.Constant(typ=type(None), **meta)
1466
+ elif tree.type.startswith("TYP_"):
1467
+ ast_tree = ast.Constant(typ=type, **meta)
1468
+ else:
1469
+ ast_tree = ast.Token(**meta)
1470
+ else:
1471
+ raise ValueError("Syntax Error encountered while parsing Jac program.")
1472
+ if not ast_tree:
1473
+ raise ValueError(f"node must be AstNode: {tree}")
1474
+ return ast_tree