1- # Copyright (c) 2015-2023 Rocky Bernstein
1+ # Copyright (c) 2015-2024 Rocky Bernstein
22# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
33# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
44# Copyright (c) 1999 John Aycock
2121
2222import sys
2323
24- from spark_parser import GenericASTBuilder , DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
25- from uncompyle6 .show import maybe_show_asm
24+ from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG , GenericASTBuilder
2625from xdis import iscode
2726
27+ from uncompyle6 .show import maybe_show_asm
28+
2829
2930class ParserError (Exception ):
3031 def __init__ (self , token , offset , debug = PARSER_DEFAULT_DEBUG ):
@@ -91,7 +92,14 @@ def __init__(self, syntax_tree_class, start, debug):
9192 # singleton reduction that we can simplify. It also happens to be optional
9293 # in its other derivation
9394 self .optional_nt |= frozenset (
94- ("come_froms" , "suite_stmts" , "l_stmts_opt" , "c_stmts_opt" , "stmts_opt" , "stmt" )
95+ (
96+ "come_froms" ,
97+ "suite_stmts" ,
98+ "l_stmts_opt" ,
99+ "c_stmts_opt" ,
100+ "stmts_opt" ,
101+ "stmt" ,
102+ )
95103 )
96104
97105 # Reduce singleton reductions in these nonterminals:
@@ -113,10 +121,10 @@ def ast_first_offset(self, ast):
113121
114122 def add_unique_rule (self , rule , opname , arg_count , customize ):
115123 """Add rule to grammar, but only if it hasn't been added previously
116- opname and stack_count are used in the customize() semantic
117- the actions to add the semantic action rule. Stack_count is
118- used in custom opcodes like MAKE_FUNCTION to indicate how
119- many arguments it has. Often it is not used.
124+ opname and stack_count are used in the customize() semantic
125+ the actions to add the semantic action rule. Stack_count is
126+ used in custom opcodes like MAKE_FUNCTION to indicate how
127+ many arguments it has. Often it is not used.
120128 """
121129 if rule not in self .new_rules :
122130 # print("XXX ", rule) # debug
@@ -223,7 +231,9 @@ def get_pos_kw(self, token):
223231 """
224232 # Low byte indicates number of positional parameters,
225233 # high byte number of keyword parameters
226- assert token .kind .startswith ("CALL_FUNCTION" ) or token .kind .startswith ("CALL_METHOD" )
234+ assert token .kind .startswith ("CALL_FUNCTION" ) or token .kind .startswith (
235+ "CALL_METHOD"
236+ )
227237 args_pos = token .attr & 0xFF
228238 args_kw = (token .attr >> 8 ) & 0xFF
229239 return args_pos , args_kw
@@ -364,7 +374,7 @@ def p_stmt(self, args):
364374 stmt ::= tryelsestmt
365375 stmt ::= tryfinallystmt
366376 stmt ::= with
367- stmt ::= withasstmt
377+ stmt ::= with_as
368378
369379 stmt ::= delete
370380 delete ::= DELETE_FAST
@@ -907,7 +917,7 @@ def python_parser(
907917if __name__ == "__main__" :
908918
909919 def parse_test (co ):
910- from xdis import PYTHON_VERSION_TRIPLE , IS_PYPY
920+ from xdis import IS_PYPY , PYTHON_VERSION_TRIPLE
911921
912922 ast = python_parser (PYTHON_VERSION_TRIPLE , co , showasm = True , is_pypy = IS_PYPY )
913923 print (ast )
0 commit comments