You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
withasstmt -> with_as
This matches Python's AST naamae better. Some linting and sorting of dictionary keys done as well.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2015-2023 Rocky Bernstein
|
||||
# Copyright (c) 2015-2024 Rocky Bernstein
|
||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||
# Copyright (c) 1999 John Aycock
|
||||
@@ -21,10 +21,11 @@ Common uncompyle6 parser routines.
|
||||
|
||||
import sys
|
||||
|
||||
from spark_parser import GenericASTBuilder, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
from uncompyle6.show import maybe_show_asm
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG, GenericASTBuilder
|
||||
from xdis import iscode
|
||||
|
||||
from uncompyle6.show import maybe_show_asm
|
||||
|
||||
|
||||
class ParserError(Exception):
|
||||
def __init__(self, token, offset, debug=PARSER_DEFAULT_DEBUG):
|
||||
@@ -91,7 +92,14 @@ class PythonParser(GenericASTBuilder):
|
||||
# singleton reduction that we can simplify. It also happens to be optional
|
||||
# in its other derivation
|
||||
self.optional_nt |= frozenset(
|
||||
("come_froms", "suite_stmts", "l_stmts_opt", "c_stmts_opt", "stmts_opt", "stmt")
|
||||
(
|
||||
"come_froms",
|
||||
"suite_stmts",
|
||||
"l_stmts_opt",
|
||||
"c_stmts_opt",
|
||||
"stmts_opt",
|
||||
"stmt",
|
||||
)
|
||||
)
|
||||
|
||||
# Reduce singleton reductions in these nonterminals:
|
||||
@@ -113,10 +121,10 @@ class PythonParser(GenericASTBuilder):
|
||||
|
||||
def add_unique_rule(self, rule, opname, arg_count, customize):
|
||||
"""Add rule to grammar, but only if it hasn't been added previously
|
||||
opname and stack_count are used in the customize() semantic
|
||||
the actions to add the semantic action rule. Stack_count is
|
||||
used in custom opcodes like MAKE_FUNCTION to indicate how
|
||||
many arguments it has. Often it is not used.
|
||||
opname and stack_count are used in the customize() semantic
|
||||
the actions to add the semantic action rule. Stack_count is
|
||||
used in custom opcodes like MAKE_FUNCTION to indicate how
|
||||
many arguments it has. Often it is not used.
|
||||
"""
|
||||
if rule not in self.new_rules:
|
||||
# print("XXX ", rule) # debug
|
||||
@@ -223,7 +231,9 @@ class PythonParser(GenericASTBuilder):
|
||||
"""
|
||||
# Low byte indicates number of positional parameters,
|
||||
# high byte number of keyword parameters
|
||||
assert token.kind.startswith("CALL_FUNCTION") or token.kind.startswith("CALL_METHOD")
|
||||
assert token.kind.startswith("CALL_FUNCTION") or token.kind.startswith(
|
||||
"CALL_METHOD"
|
||||
)
|
||||
args_pos = token.attr & 0xFF
|
||||
args_kw = (token.attr >> 8) & 0xFF
|
||||
return args_pos, args_kw
|
||||
@@ -364,7 +374,7 @@ class PythonParser(GenericASTBuilder):
|
||||
stmt ::= tryelsestmt
|
||||
stmt ::= tryfinallystmt
|
||||
stmt ::= with
|
||||
stmt ::= withasstmt
|
||||
stmt ::= with_as
|
||||
|
||||
stmt ::= delete
|
||||
delete ::= DELETE_FAST
|
||||
@@ -907,7 +917,7 @@ def python_parser(
|
||||
if __name__ == "__main__":
|
||||
|
||||
def parse_test(co):
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
from xdis import IS_PYPY, PYTHON_VERSION_TRIPLE
|
||||
|
||||
ast = python_parser(PYTHON_VERSION_TRIPLE, co, showasm=True, is_pypy=IS_PYPY)
|
||||
print(ast)
|
||||
|
Reference in New Issue
Block a user