add_custom_rules -> customize_grammar_rules

This commit is contained in:
rocky
2017-12-13 17:25:19 -05:00
parent c5be656320
commit f82edae5a1
17 changed files with 33 additions and 30 deletions

View File

@@ -6,6 +6,9 @@ FULLVERSION=$(pyenv local)
PYVERSION=${FULLVERSION%.*} PYVERSION=${FULLVERSION%.*}
MINOR=${FULLVERSION##?.?.} MINOR=${FULLVERSION##?.?.}
# DECOMPILER=uncompyle2
DECOMPILER="$fulldir/../../bin/uncompyle6"
typeset -i STOP_ONERROR=1 typeset -i STOP_ONERROR=1
typeset -A SKIP_TESTS typeset -A SKIP_TESTS
@@ -162,7 +165,7 @@ for file in $files; do
$fulldir/compile-file.py $file && \ $fulldir/compile-file.py $file && \
mv $file{,.orig} && \ mv $file{,.orig} && \
echo ========== $(date +%X) Decompiling $file =========== echo ========== $(date +%X) Decompiling $file ===========
$fulldir/../../bin/uncompyle6 $decompiled_file > $file $DECOMPILER $decompiled_file > $file
rc=$? rc=$?
if (( rc == 0 )) ; then if (( rc == 0 )) ; then
echo ========== $(date +%X) Running $file =========== echo ========== $(date +%X) Running $file ===========

View File

@@ -551,7 +551,7 @@ class PythonParser(GenericASTBuilder):
def parse(p, tokens, customize): def parse(p, tokens, customize):
p.add_custom_rules(tokens, customize) p.customize_grammar_rules(tokens, customize)
ast = p.parse(tokens) ast = p.parse(tokens)
# p.cleanup() # p.cleanup()
return ast return ast

View File

@@ -218,7 +218,7 @@ class Python2Parser(PythonParser):
binary_op ::= BINARY_DIVIDE binary_op ::= BINARY_DIVIDE
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
"""The base grammar we start out for a Python version even with the """The base grammar we start out for a Python version even with the
subclassing is, well, is pretty base. And we want it that way: lean and subclassing is, well, is pretty base. And we want it that way: lean and
mean so that parsing will go faster. mean so that parsing will go faster.

View File

@@ -20,8 +20,8 @@ class Python22Parser(Python23Parser):
COME_FROM POP_TOP COME_FROM COME_FROM POP_TOP COME_FROM
''' '''
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
super(Python22Parser, self).add_custom_rules(tokens, customize) super(Python22Parser, self).customize_grammar_rules(tokens, customize)
self.remove_rules(""" self.remove_rules("""
kvlist ::= kvlist kv2 kvlist ::= kvlist kv2
""") """)

View File

@@ -52,8 +52,8 @@ class Python23Parser(Python24Parser):
conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM
''' '''
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
super(Python23Parser, self).add_custom_rules(tokens, customize) super(Python23Parser, self).customize_grammar_rules(tokens, customize)
def reduce_is_invalid(self, rule, ast, tokens, first, last): def reduce_is_invalid(self, rule, ast, tokens, first, last):
invalid = super(Python24Parser, invalid = super(Python24Parser,

View File

@@ -52,7 +52,7 @@ class Python24Parser(Python25Parser):
kv2 ::= DUP_TOP expr expr ROT_THREE STORE_SUBSCR kv2 ::= DUP_TOP expr expr ROT_THREE STORE_SUBSCR
''' '''
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
self.remove_rules(""" self.remove_rules("""
gen_comp_body ::= expr YIELD_VALUE POP_TOP gen_comp_body ::= expr YIELD_VALUE POP_TOP
kvlist ::= kvlist kv3 kvlist ::= kvlist kv3
@@ -67,7 +67,7 @@ class Python24Parser(Python25Parser):
stmt ::= withstmt stmt ::= withstmt
stmt ::= withasstmt stmt ::= withasstmt
""") """)
super(Python24Parser, self).add_custom_rules(tokens, customize) super(Python24Parser, self).customize_grammar_rules(tokens, customize)
if self.version == 2.4: if self.version == 2.4:
self.check_reduce['nop_stmt'] = 'tokens' self.check_reduce['nop_stmt'] = 'tokens'

View File

@@ -48,7 +48,7 @@ class Python25Parser(Python26Parser):
kv ::= DUP_TOP expr ROT_TWO expr STORE_SUBSCR kv ::= DUP_TOP expr ROT_TWO expr STORE_SUBSCR
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
# Remove grammar rules inherited from Python 2.6 or Python 2 # Remove grammar rules inherited from Python 2.6 or Python 2
self.remove_rules(""" self.remove_rules("""
setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP
@@ -77,7 +77,7 @@ class Python25Parser(Python26Parser):
conditional_lambda ::= expr jmp_false_then expr return_if_lambda conditional_lambda ::= expr jmp_false_then expr return_if_lambda
return_stmt_lambda LAMBDA_MARKER return_stmt_lambda LAMBDA_MARKER
""") """)
super(Python25Parser, self).add_custom_rules(tokens, customize) super(Python25Parser, self).customize_grammar_rules(tokens, customize)
if self.version == 2.5: if self.version == 2.5:
self.check_reduce['tryelsestmt'] = 'tokens' self.check_reduce['tryelsestmt'] = 'tokens'

View File

@@ -298,13 +298,13 @@ class Python26Parser(Python2Parser):
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
self.remove_rules(""" self.remove_rules("""
withasstmt ::= expr SETUP_WITH store suite_stmts_opt withasstmt ::= expr SETUP_WITH store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_WITH POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY WITH_CLEANUP END_FINALLY
""") """)
super(Python26Parser, self).add_custom_rules(tokens, customize) super(Python26Parser, self).customize_grammar_rules(tokens, customize)
self.check_reduce['and'] = 'AST' self.check_reduce['and'] = 'AST'
self.check_reduce['list_for'] = 'AST' self.check_reduce['list_for'] = 'AST'

View File

@@ -138,14 +138,14 @@ class Python27Parser(Python2Parser):
kv3 ::= expr expr STORE_MAP kv3 ::= expr expr STORE_MAP
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
# 2.7 changes COME_FROM to COME_FROM_FINALLY # 2.7 changes COME_FROM to COME_FROM_FINALLY
self.remove_rules(""" self.remove_rules("""
while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM suite_stmts_opt END_FINALLY tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM suite_stmts_opt END_FINALLY
""") """)
super(Python27Parser, self).add_custom_rules(tokens, customize) super(Python27Parser, self).customize_grammar_rules(tokens, customize)
self.check_reduce['and'] = 'AST' self.check_reduce['and'] = 'AST'
return return

View File

@@ -528,7 +528,7 @@ class Python3Parser(PythonParser):
return args_pos, args_kw return args_pos, args_kw
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
"""The base grammar we start out for a Python version even with the """The base grammar we start out for a Python version even with the
subclassing is, well, is pretty base. And we want it that way: lean and subclassing is, well, is pretty base. And we want it that way: lean and
mean so that parsing will go faster. mean so that parsing will go faster.

View File

@@ -44,8 +44,8 @@ class Python30Parser(Python31Parser):
setup_finally ::= STORE_FAST SETUP_FINALLY LOAD_FAST DELETE_FAST setup_finally ::= STORE_FAST SETUP_FINALLY LOAD_FAST DELETE_FAST
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
super(Python30Parser, self).add_custom_rules(tokens, customize) super(Python30Parser, self).customize_grammar_rules(tokens, customize)
return return
pass pass

View File

@@ -33,8 +33,8 @@ class Python31Parser(Python32Parser):
load ::= LOAD_NAME load ::= LOAD_NAME
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
super(Python31Parser, self).add_custom_rules(tokens, customize) super(Python31Parser, self).customize_grammar_rules(tokens, customize)
return return
pass pass

View File

@@ -58,7 +58,7 @@ class Python32Parser(Python3Parser):
""" """
pass pass
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
self.remove_rules(""" self.remove_rules("""
except_handler ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY COME_FROM except_handler ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY COME_FROM
except_handler ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY COME_FROM_EXCEPT except_handler ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY COME_FROM_EXCEPT
@@ -68,7 +68,7 @@ class Python32Parser(Python3Parser):
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP
""") """)
super(Python32Parser, self).add_custom_rules(tokens, customize) super(Python32Parser, self).customize_grammar_rules(tokens, customize)
for i, token in enumerate(tokens): for i, token in enumerate(tokens):
opname = token.kind opname = token.kind
if opname.startswith('MAKE_FUNCTION_A'): if opname.startswith('MAKE_FUNCTION_A'):

View File

@@ -26,13 +26,13 @@ class Python33Parser(Python32Parser):
jump_excepts come_from_except_clauses jump_excepts come_from_except_clauses
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
self.remove_rules(""" self.remove_rules("""
# 3.3+ adds POP_BLOCKS # 3.3+ adds POP_BLOCKS
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP
""") """)
super(Python33Parser, self).add_custom_rules(tokens, customize) super(Python33Parser, self).customize_grammar_rules(tokens, customize)
return return
class Python33ParserSingle(Python33Parser, PythonParserSingle): class Python33ParserSingle(Python33Parser, PythonParserSingle):

View File

@@ -29,10 +29,10 @@ class Python34Parser(Python33Parser):
yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
# self.remove_rules(""" # self.remove_rules("""
# """) # """)
super(Python34Parser, self).add_custom_rules(tokens, customize) super(Python34Parser, self).customize_grammar_rules(tokens, customize)
return return
class Python34ParserSingle(Python34Parser, PythonParserSingle): class Python34ParserSingle(Python34Parser, PythonParserSingle):

View File

@@ -114,7 +114,7 @@ class Python35Parser(Python34Parser):
yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
self.remove_rules(""" self.remove_rules("""
yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM
yield_from ::= expr expr YIELD_FROM yield_from ::= expr expr YIELD_FROM
@@ -125,7 +125,7 @@ class Python35Parser(Python34Parser):
POP_BLOCK LOAD_CONST COME_FROM_WITH POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY WITH_CLEANUP END_FINALLY
""") """)
super(Python35Parser, self).add_custom_rules(tokens, customize) super(Python35Parser, self).customize_grammar_rules(tokens, customize)
for i, token in enumerate(tokens): for i, token in enumerate(tokens):
opname = token.kind opname = token.kind
if opname == 'BUILD_MAP_UNPACK_WITH_CALL': if opname == 'BUILD_MAP_UNPACK_WITH_CALL':

View File

@@ -52,8 +52,8 @@ class Python36Parser(Python35Parser):
try_except36 ::= SETUP_EXCEPT return_stmts except_handler36 opt_come_from_except try_except36 ::= SETUP_EXCEPT return_stmts except_handler36 opt_come_from_except
""" """
def add_custom_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
super(Python36Parser, self).add_custom_rules(tokens, customize) super(Python36Parser, self).customize_grammar_rules(tokens, customize)
for i, token in enumerate(tokens): for i, token in enumerate(tokens):
opname = token.kind opname = token.kind