|
2 | 2 | """ |
3 | 3 | Python 3.7 base code. We keep non-custom-generated grammar rules out of this file. |
4 | 4 | """ |
5 | | -from uncompyle6.parser import ParserError, PythonParser, nop_func |
6 | | -from uncompyle6.parsers.treenode import SyntaxTree |
7 | 5 | from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG |
8 | 6 | from spark_parser.spark import rule2str |
9 | 7 |
|
| 8 | +from uncompyle6.parser import ParserError, PythonParser, nop_func |
10 | 9 | from uncompyle6.parsers.reducecheck import ( |
11 | 10 | and_invalid, |
12 | 11 | ifelsestmt, |
|
16 | 15 | or_check, |
17 | 16 | testtrue, |
18 | 17 | tryelsestmtl3, |
19 | | - while1stmt, |
20 | 18 | while1elsestmt, |
| 19 | + while1stmt, |
21 | 20 | ) |
| 21 | +from uncompyle6.parsers.treenode import SyntaxTree |
22 | 22 |
|
23 | 23 |
|
24 | 24 | class Python37BaseParser(PythonParser): |
@@ -54,7 +54,7 @@ def custom_build_class_rule(self, opname, i, token, tokens, customize): |
54 | 54 | expr |
55 | 55 | call |
56 | 56 | CALL_FUNCTION_3 |
57 | | - """ |
| 57 | + """ |
58 | 58 | # FIXME: I bet this can be simplified |
59 | 59 | # look for next MAKE_FUNCTION |
60 | 60 | for i in range(i + 1, len(tokens)): |
@@ -104,7 +104,6 @@ def custom_build_class_rule(self, opname, i, token, tokens, customize): |
104 | 104 | # organization for this. For example, arrange organize by opcode base? |
105 | 105 |
|
106 | 106 | def customize_grammar_rules(self, tokens, customize): |
107 | | - |
108 | 107 | is_pypy = False |
109 | 108 |
|
110 | 109 | # For a rough break out on the first word. This may |
@@ -348,7 +347,6 @@ def customize_grammar_rules(self, tokens, customize): |
348 | 347 | self.addRule(rule, nop_func) |
349 | 348 |
|
350 | 349 | elif opname_base in ("BUILD_MAP", "BUILD_MAP_UNPACK"): |
351 | | - |
352 | 350 | if opname == "BUILD_MAP_UNPACK": |
353 | 351 | self.addRule( |
354 | 352 | """ |
@@ -525,7 +523,6 @@ def customize_grammar_rules(self, tokens, customize): |
525 | 523 | "CALL_FUNCTION_VAR_KW", |
526 | 524 | ) |
527 | 525 | ) or opname.startswith("CALL_FUNCTION_KW"): |
528 | | - |
529 | 526 | if opname == "CALL_FUNCTION" and token.attr == 1: |
530 | 527 | rule = """ |
531 | 528 | expr ::= dict_comp |
@@ -720,7 +717,9 @@ def customize_grammar_rules(self, tokens, customize): |
720 | 717 | ) |
721 | 718 | custom_ops_processed.add(opname) |
722 | 719 | elif opname == "LOAD_LISTCOMP": |
723 | | - self.add_unique_rule("expr ::= listcomp", opname, token.attr, customize) |
| 720 | + self.add_unique_rule( |
| 721 | + "expr ::= list_comp", opname, token.attr, customize |
| 722 | + ) |
724 | 723 | custom_ops_processed.add(opname) |
725 | 724 | elif opname == "LOAD_NAME": |
726 | 725 | if ( |
@@ -799,7 +798,7 @@ def customize_grammar_rules(self, tokens, customize): |
799 | 798 | # and have GET_ITER CALL_FUNCTION_1 |
800 | 799 | # Todo: For Pypy we need to modify this slightly |
801 | 800 | rule_pat = ( |
802 | | - "listcomp ::= %sload_closure LOAD_LISTCOMP %%s%s expr " |
| 801 | + "list_comp ::= %sload_closure LOAD_LISTCOMP %%s%s expr " |
803 | 802 | "GET_ITER CALL_FUNCTION_1" |
804 | 803 | % ("pos_arg " * args_pos, opname) |
805 | 804 | ) |
@@ -897,14 +896,14 @@ def customize_grammar_rules(self, tokens, customize): |
897 | 896 | # 'exprs' in the rule above into a |
898 | 897 | # tuple. |
899 | 898 | rule_pat = ( |
900 | | - "listcomp ::= load_closure LOAD_LISTCOMP %%s%s " |
| 899 | + "list_comp ::= load_closure LOAD_LISTCOMP %%s%s " |
901 | 900 | "expr GET_ITER CALL_FUNCTION_1" % (opname,) |
902 | 901 | ) |
903 | 902 | self.add_make_function_rule( |
904 | 903 | rule_pat, opname, token.attr, customize |
905 | 904 | ) |
906 | 905 | rule_pat = ( |
907 | | - "listcomp ::= %sLOAD_LISTCOMP %%s%s expr " |
| 906 | + "list_comp ::= %sLOAD_LISTCOMP %%s%s expr " |
908 | 907 | "GET_ITER CALL_FUNCTION_1" % ("expr " * args_pos, opname) |
909 | 908 | ) |
910 | 909 | self.add_make_function_rule( |
@@ -938,7 +937,7 @@ def customize_grammar_rules(self, tokens, customize): |
938 | 937 | # and have GET_ITER CALL_FUNCTION_1 |
939 | 938 | # Todo: For Pypy we need to modify this slightly |
940 | 939 | rule_pat = ( |
941 | | - "listcomp ::= %sLOAD_LISTCOMP %%s%s expr " |
| 940 | + "list_comp ::= %sLOAD_LISTCOMP %%s%s expr " |
942 | 941 | "GET_ITER CALL_FUNCTION_1" % ("expr " * args_pos, opname) |
943 | 942 | ) |
944 | 943 | self.add_make_function_rule( |
@@ -1259,7 +1258,8 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last): |
1259 | 1258 | if fn: |
1260 | 1259 | return fn(self, lhs, n, rule, ast, tokens, first, last) |
1261 | 1260 | except Exception: |
1262 | | - import sys, traceback |
| 1261 | + import sys |
| 1262 | + import traceback |
1263 | 1263 |
|
1264 | 1264 | print( |
1265 | 1265 | f"Exception in {fn.__name__} {sys.exc_info()[1]}\n" |
|
0 commit comments