NT designatore -> store to match AST

This commit is contained in:
rocky
2017-11-29 05:05:15 -05:00
parent c81b4df8b7
commit 43c3154a55
18 changed files with 168 additions and 168 deletions

View File

@@ -22,7 +22,7 @@ def test_grammar():
'unpack',])
expect_right_recursive = frozenset([('designList',
('designator', 'DUP_TOP', 'designList'))])
('store', 'DUP_TOP', 'designList'))])
if PYTHON3:
expect_lhs.add('load_genexpr')

View File

@@ -284,9 +284,9 @@ class PythonParser(GenericASTBuilder):
def p_funcdef(self, args):
'''
stmt ::= funcdef
funcdef ::= mkfunc designator
funcdef ::= mkfunc store
stmt ::= funcdefdeco
funcdefdeco ::= mkfuncdeco designator
funcdefdeco ::= mkfuncdeco store
mkfuncdeco ::= expr mkfuncdeco CALL_FUNCTION_1
mkfuncdeco ::= expr mkfuncdeco0 CALL_FUNCTION_1
mkfuncdeco0 ::= mkfunc
@@ -299,7 +299,7 @@ class PythonParser(GenericASTBuilder):
expr ::= generator_exp
stmt ::= genexpr_func
genexpr_func ::= LOAD_FAST FOR_ITER designator comp_iter JUMP_BACK
genexpr_func ::= LOAD_FAST FOR_ITER store comp_iter JUMP_BACK
'''
def p_jump(self, args):
@@ -323,9 +323,9 @@ class PythonParser(GenericASTBuilder):
stmt ::= augassign2
# This is odd in that other augassign1's have only 3 slots
# The designator isn't used as that's supposed to be also
# The store isn't used as that's supposed to be also
# indicated in the first expr
augassign1 ::= expr expr inplace_op designator
augassign1 ::= expr expr inplace_op store
augassign1 ::= expr expr inplace_op ROT_THREE STORE_SUBSCR
augassign2 ::= expr DUP_TOP LOAD_ATTR expr
@@ -349,12 +349,12 @@ class PythonParser(GenericASTBuilder):
'''
stmt ::= assign
assign ::= expr DUP_TOP designList
assign ::= expr designator
assign ::= expr store
stmt ::= assign2
stmt ::= assign3
assign2 ::= expr expr ROT_TWO designator designator
assign3 ::= expr expr expr ROT_THREE ROT_TWO designator designator designator
assign2 ::= expr expr ROT_TWO store store
assign3 ::= expr expr expr ROT_THREE ROT_TWO store store store
'''
def p_forstmt(self, args):
@@ -363,16 +363,16 @@ class PythonParser(GenericASTBuilder):
for_block ::= l_stmts_opt _come_from JUMP_BACK
forstmt ::= SETUP_LOOP expr _for designator
forstmt ::= SETUP_LOOP expr _for store
for_block POP_BLOCK _come_from
forelsestmt ::= SETUP_LOOP expr _for designator
forelsestmt ::= SETUP_LOOP expr _for store
for_block POP_BLOCK else_suite _come_from
forelselaststmt ::= SETUP_LOOP expr _for designator
forelselaststmt ::= SETUP_LOOP expr _for store
for_block POP_BLOCK else_suitec _come_from
forelselaststmtl ::= SETUP_LOOP expr _for designator
forelselaststmtl ::= SETUP_LOOP expr _for store
for_block POP_BLOCK else_suitel _come_from
"""
@@ -385,8 +385,8 @@ class PythonParser(GenericASTBuilder):
importlist ::= importlist import_as
importlist ::= import_as
import_as ::= IMPORT_NAME designator
import_as ::= IMPORT_FROM designator
import_as ::= IMPORT_NAME store
import_as ::= IMPORT_FROM store
importstmt ::= LOAD_CONST LOAD_CONST import_as
importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME IMPORT_STAR
@@ -513,27 +513,27 @@ class PythonParser(GenericASTBuilder):
expr1024 ::= expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32 expr32
'''
def p_designator(self, args):
def p_store(self, args):
'''
# Note. The below is right-recursive:
designList ::= designator designator
designList ::= designator DUP_TOP designList
designList ::= store store
designList ::= store DUP_TOP designList
## Can we replace with left-recursive, and redo with:
##
## designList ::= designLists designator designator
## designLists ::= designLists designator DUP_TOP
## designList ::= designLists store store
## designLists ::= designLists store DUP_TOP
## designLists ::=
## Will need to redo semantic actiion
designator ::= STORE_FAST
designator ::= STORE_NAME
designator ::= STORE_GLOBAL
designator ::= STORE_DEREF
designator ::= expr STORE_ATTR
designator ::= store_subscr
store ::= STORE_FAST
store ::= STORE_NAME
store ::= STORE_GLOBAL
store ::= STORE_DEREF
store ::= expr STORE_ATTR
store ::= store_subscr
store_subscr ::= expr expr STORE_SUBSCR
designator ::= unpack
store ::= unpack
'''

View File

@@ -104,13 +104,13 @@ class Python2Parser(PythonParser):
mapexpr ::= BUILD_MAP kvlist
classdef ::= buildclass designator
classdef ::= buildclass store
buildclass ::= LOAD_CONST expr mkfunc
CALL_FUNCTION_0 BUILD_CLASS
stmt ::= classdefdeco
classdefdeco ::= classdefdeco1 designator
classdefdeco ::= classdefdeco1 store
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
classdefdeco2 ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS
@@ -194,10 +194,10 @@ class Python2Parser(PythonParser):
def p_slice2(self, args):
"""
designator ::= expr STORE_SLICE+0
designator ::= expr expr STORE_SLICE+1
designator ::= expr expr STORE_SLICE+2
designator ::= expr expr expr STORE_SLICE+3
store ::= expr STORE_SLICE+0
store ::= expr expr STORE_SLICE+1
store ::= expr expr STORE_SLICE+2
store ::= expr expr expr STORE_SLICE+3
augassign1 ::= expr expr inplace_op ROT_FOUR STORE_SLICE+3
augassign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+1
@@ -250,9 +250,9 @@ class Python2Parser(PythonParser):
self.addRule("""
stmt ::= assign3_pypy
stmt ::= assign2_pypy
assign3_pypy ::= expr expr expr designator designator designator
assign2_pypy ::= expr expr designator designator
list_compr ::= expr BUILD_LIST_FROM_ARG _for designator list_iter
assign3_pypy ::= expr expr expr store store store
assign2_pypy ::= expr expr store store
list_compr ::= expr BUILD_LIST_FROM_ARG _for store list_iter
JUMP_BACK
""", nop_func)
for i, token in enumerate(tokens):
@@ -288,7 +288,7 @@ class Python2Parser(PythonParser):
], customize)
if self.version >= 2.7:
self.add_unique_rule(
'dictcomp_func ::= BUILD_MAP_n LOAD_FAST FOR_ITER designator '
'dictcomp_func ::= BUILD_MAP_n LOAD_FAST FOR_ITER store '
'comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST',
'dictcomp_func', 0, customize)
@@ -422,9 +422,9 @@ class Python2Parser(PythonParser):
], customize)
continue
elif opname_base in ('UNPACK_TUPLE', 'UNPACK_SEQUENCE'):
rule = 'unpack ::= ' + opname + ' designator'*v
rule = 'unpack ::= ' + opname + ' store'*v
elif opname_base == 'UNPACK_LIST':
rule = 'unpack_list ::= ' + opname + ' designator'*v
rule = 'unpack_list ::= ' + opname + ' store'*v
else:
raise Exception('unknown customize token %s' % opname)
self.add_unique_rule(rule, opname_base, v, customize)

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016 Rocky Bernstein
# Copyright (c) 2016-2017 Rocky Bernstein
# Copyright (c) 2000-2002 by hartmut Goebel <hartmut@goebel.noris.de>
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
@@ -14,10 +14,10 @@ class Python21Parser(Python22Parser):
def p_forstmt21(self, args):
"""
_for ::= LOAD_CONST FOR_LOOP
forstmt ::= SETUP_LOOP expr _for designator
forstmt ::= SETUP_LOOP expr _for store
return_stmts
POP_BLOCK COME_FROM
forstmt ::= SETUP_LOOP expr _for designator
forstmt ::= SETUP_LOOP expr _for store
l_stmts_opt _jump_back
POP_BLOCK COME_FROM
@@ -27,7 +27,7 @@ class Python21Parser(Python22Parser):
def p_import21(self, args):
'''
import_as ::= IMPORT_NAME_CONT designator
import_as ::= IMPORT_NAME_CONT store
'''
class Python21ParserSingle(Python22Parser, PythonParserSingle):

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016 Rocky Bernstein
# Copyright (c) 2016-2017 Rocky Bernstein
# Copyright (c) 2000-2002 by hartmut Goebel <hartmut@goebel.noris.de>
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
@@ -16,7 +16,7 @@ class Python22Parser(Python23Parser):
_for ::= LOAD_CONST FOR_LOOP
list_iter ::= list_if JUMP_FORWARD
COME_FROM POP_TOP COME_FROM
list_for ::= expr _for designator list_iter CONTINUE JUMP_FORWARD
list_for ::= expr _for store list_iter CONTINUE JUMP_FORWARD
COME_FROM POP_TOP COME_FROM
'''

View File

@@ -35,8 +35,8 @@ class Python23Parser(Python24Parser):
while1stmt ::= _while1test l_stmts_opt JUMP_BACK
COME_FROM POP_TOP POP_BLOCK COME_FROM
list_compr ::= BUILD_LIST_0 DUP_TOP LOAD_ATTR designator list_iter del_stmt
list_for ::= expr _for designator list_iter JUMP_BACK come_froms POP_TOP JUMP_BACK
list_compr ::= BUILD_LIST_0 DUP_TOP LOAD_ATTR store list_iter del_stmt
list_for ::= expr _for store list_iter JUMP_BACK come_froms POP_TOP JUMP_BACK
lc_body ::= LOAD_NAME expr CALL_FUNCTION_1 POP_TOP
lc_body ::= LOAD_FAST expr CALL_FUNCTION_1 POP_TOP
@@ -48,7 +48,7 @@ class Python23Parser(Python24Parser):
expr ::= and2
and2 ::= _jump jmp_false COME_FROM expr COME_FROM
import_as ::= IMPORT_NAME load_attrs designator
import_as ::= IMPORT_NAME load_attrs store
load_attrs ::= LOAD_ATTR+
conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016 Rocky Bernstein
# Copyright (c) 2016-2017 Rocky Bernstein
"""
spark grammar differences over Python2.5 for Python 2.4.
"""
@@ -62,7 +62,7 @@ class Python24Parser(Python25Parser):
whilestmt ::= SETUP_LOOP testexpr return_stmts POP_BLOCK COME_FROM
with_cleanup ::= LOAD_FAST DELETE_FAST WITH_CLEANUP END_FINALLY
with_cleanup ::= LOAD_NAME DELETE_NAME WITH_CLEANUP END_FINALLY
withasstmt ::= expr setupwithas designator suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM with_cleanup
withasstmt ::= expr setupwithas store suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM with_cleanup
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM with_cleanup
stmt ::= withstmt
stmt ::= withasstmt

View File

@@ -37,7 +37,7 @@ class Python25Parser(Python26Parser):
# Python 2.6 omits the LOAD_FAST DELETE_FAST below
# withas is allowed as a "from future" in 2.5
withasstmt ::= expr setupwithas designator suite_stmts_opt
withasstmt ::= expr setupwithas store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM
with_cleanup
@@ -55,10 +55,10 @@ class Python25Parser(Python26Parser):
setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
withasstmt ::= expr setupwithas designator suite_stmts_opt
withasstmt ::= expr setupwithas store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
classdefdeco ::= classdefdeco1 designator
classdefdeco ::= classdefdeco1 store
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
classdefdeco2 ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS

View File

@@ -19,7 +19,7 @@ class Python26Parser(Python2Parser):
except_cond1 ::= DUP_TOP expr COMPARE_OP
JUMP_IF_FALSE POP_TOP POP_TOP POP_TOP POP_TOP
except_cond3 ::= DUP_TOP expr COMPARE_OP
JUMP_IF_FALSE POP_TOP POP_TOP designator POP_TOP
JUMP_IF_FALSE POP_TOP POP_TOP store POP_TOP
try_middle ::= JUMP_FORWARD COME_FROM except_stmts
come_from_pop END_FINALLY come_froms
@@ -122,8 +122,8 @@ class Python26Parser(Python2Parser):
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
# Semantic actions want designator to be at index 2
withasstmt ::= expr setupwithas designator suite_stmts_opt
# Semantic actions want store to be at index 2
withasstmt ::= expr setupwithas store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
# This is truly weird. 2.7 does this (not including POP_TOP) with
@@ -184,25 +184,25 @@ class Python26Parser(Python2Parser):
def p_comp26(self, args):
'''
list_for ::= expr _for designator list_iter JUMP_BACK come_froms POP_TOP
list_for ::= expr _for store list_iter JUMP_BACK come_froms POP_TOP
# The JUMP FORWARD below jumps to the JUMP BACK. It seems to happen
# in rare cases that may have to with length of code
list_for ::= expr _for designator list_iter JUMP_FORWARD come_froms POP_TOP
list_for ::= expr _for store list_iter JUMP_FORWARD come_froms POP_TOP
COME_FROM JUMP_BACK
list_for ::= expr _for designator list_iter jb_cont
list_for ::= expr _for store list_iter jb_cont
list_iter ::= list_if JUMP_BACK
list_iter ::= list_if JUMP_BACK COME_FROM POP_TOP
list_compr ::= BUILD_LIST_0 DUP_TOP
designator list_iter del_stmt
store list_iter del_stmt
list_compr ::= BUILD_LIST_0 DUP_TOP
designator list_iter JUMP_BACK del_stmt
store list_iter JUMP_BACK del_stmt
lc_body ::= LOAD_NAME expr LIST_APPEND
lc_body ::= LOAD_FAST expr LIST_APPEND
comp_for ::= SETUP_LOOP expr _for designator comp_iter jb_bp_come_from
comp_for ::= SETUP_LOOP expr _for store comp_iter jb_bp_come_from
comp_body ::= gen_comp_body
@@ -210,8 +210,8 @@ class Python26Parser(Python2Parser):
# Make sure we keep indices the same as 2.7
setup_loop_lf ::= SETUP_LOOP LOAD_FAST
genexpr_func ::= setup_loop_lf FOR_ITER designator comp_iter jb_bp_come_from
genexpr_func ::= setup_loop_lf FOR_ITER designator comp_iter JUMP_BACK come_from_pop
genexpr_func ::= setup_loop_lf FOR_ITER store comp_iter jb_bp_come_from
genexpr_func ::= setup_loop_lf FOR_ITER store comp_iter JUMP_BACK come_from_pop
jb_bp_come_from
generator_exp ::= LOAD_GENEXPR MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1 COME_FROM
list_if ::= list_if ::= expr jmp_false_then list_iter
@@ -254,7 +254,7 @@ class Python26Parser(Python2Parser):
def add_custom_rules(self, tokens, customize):
self.remove_rules("""
withasstmt ::= expr SETUP_WITH designator suite_stmts_opt
withasstmt ::= expr SETUP_WITH store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY
""")

View File

@@ -14,7 +14,7 @@ class Python27Parser(Python2Parser):
def p_comprehension27(self, args):
"""
list_for ::= expr _for designator list_iter JUMP_BACK
list_for ::= expr _for store list_iter JUMP_BACK
list_compr ::= BUILD_LIST_0 list_iter
lc_body ::= expr LIST_APPEND
@@ -23,17 +23,17 @@ class Python27Parser(Python2Parser):
# Dictionary and set comprehensions were added in Python 2.7
expr ::= dictcomp
stmt ::= dictcomp_func
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER designator
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
dictcomp ::= LOAD_DICTCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER designator comp_iter
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
comp_body ::= dict_comp_body
comp_body ::= set_comp_body
comp_for ::= expr _for designator comp_iter JUMP_BACK
comp_for ::= expr _for store comp_iter JUMP_BACK
dict_comp_body ::= expr expr MAP_ADD
set_comp_body ::= expr SET_ADD
@@ -56,7 +56,7 @@ class Python27Parser(Python2Parser):
jmp_false POP_TOP POP_TOP POP_TOP
except_cond2 ::= DUP_TOP expr COMPARE_OP
jmp_false POP_TOP designator POP_TOP
jmp_false POP_TOP store POP_TOP
"""
def p_jump27(self, args):
@@ -107,7 +107,7 @@ class Python27Parser(Python2Parser):
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY
withasstmt ::= expr SETUP_WITH designator suite_stmts_opt
withasstmt ::= expr SETUP_WITH store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY

View File

@@ -41,10 +41,10 @@ class Python3Parser(PythonParser):
# one may be a continue - sometimes classifies a JUMP_BACK
# as a CONTINUE. The two are kind of the same in a comprehension.
comp_for ::= expr _for designator comp_iter CONTINUE
comp_for ::= expr _for designator comp_iter JUMP_BACK
comp_for ::= expr _for store comp_iter CONTINUE
comp_for ::= expr _for store comp_iter JUMP_BACK
list_for ::= expr FOR_ITER designator list_iter jb_or_c
list_for ::= expr FOR_ITER store list_iter jb_or_c
# This is seen in PyPy, but possibly it appears on other Python 3?
list_if ::= expr jmp_false list_iter COME_FROM
@@ -55,10 +55,10 @@ class Python3Parser(PythonParser):
stmt ::= setcomp_func
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER designator comp_iter
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER designator comp_iter
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
comp_body ::= dict_comp_body
@@ -73,7 +73,7 @@ class Python3Parser(PythonParser):
""""
expr ::= dictcomp
stmt ::= dictcomp_func
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER designator
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
dictcomp ::= LOAD_DICTCOMP LOAD_CONST MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
"""
@@ -115,14 +115,14 @@ class Python3Parser(PythonParser):
kwarg ::= LOAD_CONST expr
kwargs ::= kwarg*
classdef ::= build_class designator
classdef ::= build_class store
# Python3 introduced LOAD_BUILD_CLASS
# Other definitions are in a custom rule
build_class ::= LOAD_BUILD_CLASS mkfunc expr call CALL_FUNCTION_3
stmt ::= classdefdeco
classdefdeco ::= classdefdeco1 designator
classdefdeco ::= classdefdeco1 store
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
@@ -236,7 +236,7 @@ class Python3Parser(PythonParser):
END_FINALLY _jump
except_var_finalize ::= POP_BLOCK POP_EXCEPT LOAD_CONST come_from_or_finally
LOAD_CONST designator del_stmt
LOAD_CONST store del_stmt
except_suite ::= return_stmts
@@ -244,7 +244,7 @@ class Python3Parser(PythonParser):
jmp_false POP_TOP POP_TOP POP_TOP
except_cond2 ::= DUP_TOP expr COMPARE_OP
jmp_false POP_TOP designator POP_TOP
jmp_false POP_TOP store POP_TOP
except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt POP_EXCEPT _jump
except ::= POP_TOP POP_TOP POP_TOP return_stmts
@@ -256,7 +256,7 @@ class Python3Parser(PythonParser):
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY
withasstmt ::= expr SETUP_WITH designator suite_stmts_opt
withasstmt ::= expr SETUP_WITH store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY
@@ -289,7 +289,7 @@ class Python3Parser(PythonParser):
"""
# Annotated functions
stmt ::= funcdef_annotate
funcdef_annotate ::= mkfunc_annotate designator
funcdef_annotate ::= mkfunc_annotate store
mkfuncdeco0 ::= mkfunc_annotate
@@ -355,16 +355,16 @@ class Python3Parser(PythonParser):
def p_loop_stmt3(self, args):
"""
forstmt ::= SETUP_LOOP expr _for designator for_block POP_BLOCK
forstmt ::= SETUP_LOOP expr _for store for_block POP_BLOCK
opt_come_from_loop
forelsestmt ::= SETUP_LOOP expr _for designator for_block POP_BLOCK else_suite
forelsestmt ::= SETUP_LOOP expr _for store for_block POP_BLOCK else_suite
COME_FROM_LOOP
forelselaststmt ::= SETUP_LOOP expr _for designator for_block POP_BLOCK else_suitec
forelselaststmt ::= SETUP_LOOP expr _for store for_block POP_BLOCK else_suitec
COME_FROM_LOOP
forelselaststmtl ::= SETUP_LOOP expr _for designator for_block POP_BLOCK else_suitel
forelselaststmtl ::= SETUP_LOOP expr _for store for_block POP_BLOCK else_suitel
COME_FROM_LOOP
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
@@ -404,7 +404,7 @@ class Python3Parser(PythonParser):
COME_FROM_LOOP
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP
COME_FROM_LOOP
forstmt ::= SETUP_LOOP expr _for designator for_block POP_BLOCK NOP
forstmt ::= SETUP_LOOP expr _for store for_block POP_BLOCK NOP
COME_FROM_LOOP
"""
@@ -639,8 +639,8 @@ class Python3Parser(PythonParser):
self.addRule("""
stmt ::= assign3_pypy
stmt ::= assign2_pypy
assign3_pypy ::= expr expr expr designator designator designator
assign2_pypy ::= expr expr designator designator
assign3_pypy ::= expr expr expr store store store
assign2_pypy ::= expr expr store store
""", nop_func)
has_get_iter_call_function1 = False
@@ -679,7 +679,7 @@ class Python3Parser(PythonParser):
kvlist_n = "kvlist_%s" % token.attr
if opname == 'BUILD_MAP_n':
# PyPy sometimes has no count. Sigh.
rule = ('dictcomp_func ::= BUILD_MAP_n LOAD_FAST FOR_ITER designator '
rule = ('dictcomp_func ::= BUILD_MAP_n LOAD_FAST FOR_ITER store '
'comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST')
self.add_unique_rule(rule, 'dictomp_func', 1, customize)
@@ -970,13 +970,13 @@ class Python3Parser(PythonParser):
self.add_unique_rule(rule, opname, token.attr, customize)
elif opname_base in ('UNPACK_EX',):
before_count, after_count = token.attr
rule = 'unpack ::= ' + opname + ' designator' * (before_count + after_count + 1)
rule = 'unpack ::= ' + opname + ' store' * (before_count + after_count + 1)
self.add_unique_rule(rule, opname, token.attr, customize)
elif opname_base in ('UNPACK_TUPLE', 'UNPACK_SEQUENCE'):
rule = 'unpack ::= ' + opname + ' designator' * token.attr
rule = 'unpack ::= ' + opname + ' store' * token.attr
self.add_unique_rule(rule, opname, token.attr, customize)
elif opname_base == 'UNPACK_LIST':
rule = 'unpack_list ::= ' + opname + ' designator' * token.attr
rule = 'unpack_list ::= ' + opname + ' store' * token.attr
self.check_reduce['augassign1'] = 'AST'
self.check_reduce['augassign2'] = 'AST'
self.check_reduce['while1stmt'] = 'noAST'

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016 Rocky Bernstein
# Copyright (c) 2016-2017 Rocky Bernstein
"""
spark grammar differences over Python 3.1 for Python 3.0.
"""
@@ -37,7 +37,7 @@ class Python30Parser(Python31Parser):
ifelsestmtl ::= testexpr c_stmts_opt jb_pop_top else_suitel
withasstmt ::= expr setupwithas designator suite_stmts_opt
withasstmt ::= expr setupwithas store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_FINALLY
LOAD_FAST DELETE_FAST WITH_CLEANUP END_FINALLY
setupwithas ::= DUP_TOP LOAD_ATTR STORE_FAST LOAD_ATTR CALL_FUNCTION_0 setup_finally

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016 Rocky Bernstein
# Copyright (c) 2016-2017 Rocky Bernstein
"""
spark grammar differences over Python 3.2 for Python 3.1.
"""
@@ -23,7 +23,7 @@ class Python31Parser(Python32Parser):
# Keeps Python 3.1 withas desigator in the same position as it is in other version
setupwithas31 ::= setupwithas SETUP_FINALLY load del_stmt
withasstmt ::= expr setupwithas31 designator
withasstmt ::= expr setupwithas31 store
suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_FINALLY
load del_stmt WITH_CLEANUP END_FINALLY

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016 Rocky Bernstein
# Copyright (c) 2016-2017 Rocky Bernstein
"""
spark grammar differences over Python 3.4 for Python 3.5.
"""
@@ -55,7 +55,7 @@ class Python35Parser(Python34Parser):
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
withasstmt ::= expr
SETUP_WITH designator suite_stmts_opt
SETUP_WITH store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
@@ -74,7 +74,7 @@ class Python35Parser(Python34Parser):
stmt ::= async_with_as_stmt
async_with_as_stmt ::= expr
BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM
SETUP_ASYNC_WITH designator suite_stmts_opt
SETUP_ASYNC_WITH store suite_stmts_opt
POP_BLOCK LOAD_CONST
WITH_CLEANUP_START
GET_AWAITABLE LOAD_CONST YIELD_FROM
@@ -85,7 +85,7 @@ class Python35Parser(Python34Parser):
GET_AITER
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST
YIELD_FROM
designator
store
POP_BLOCK jump_except COME_FROM_EXCEPT DUP_TOP
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_FALSE
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_BLOCK
@@ -97,7 +97,7 @@ class Python35Parser(Python34Parser):
GET_AITER
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST
YIELD_FROM
designator
store
POP_BLOCK jump_except COME_FROM_EXCEPT DUP_TOP
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_FALSE
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_BLOCK
@@ -110,7 +110,7 @@ class Python35Parser(Python34Parser):
GET_AITER
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST
YIELD_FROM
designator
store
POP_BLOCK JUMP_FORWARD COME_FROM_EXCEPT DUP_TOP
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_FALSE
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_BLOCK

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016 Rocky Bernstein
# Copyright (c) 2016-2017 Rocky Bernstein
"""
spark grammar differences over Python 3.5 for Python 3.6.
"""
@@ -40,7 +40,7 @@ class Python36Parser(Python35Parser):
# FIXME: remove corresponding rule for 3.5?
async_with_as_stmt ::= expr
BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM
SETUP_ASYNC_WITH designator
SETUP_ASYNC_WITH store
suite_stmts_opt
POP_BLOCK LOAD_CONST
COME_FROM_ASYNC_WITH

View File

@@ -38,14 +38,14 @@ ASSIGN_DOC_STRING = lambda doc_string: \
AST('stmt',
[ AST('assign',
[ AST('expr', [ Token('LOAD_CONST', pattr=doc_string) ]),
AST('designator', [ Token('STORE_NAME', pattr='__doc__')])
AST('store', [ Token('STORE_NAME', pattr='__doc__')])
])])
NAME_MODULE = AST('stmt',
[ AST('assign',
[ AST('expr',
[Token('LOAD_NAME', pattr='__name__', offset=0, has_arg=True)]),
AST('designator',
AST('store',
[ Token('STORE_NAME', pattr='__module__', offset=3, has_arg=True)])
])])
@@ -174,7 +174,7 @@ TABLE_DIRECT = {
'assign': ( '%|%c = %p\n', -1, (0, 200) ),
# The 2nd parameter should have a = suffix.
# There is a rule with a 4th parameter "designator"
# There is a rule with a 4th parameter "store"
# which we don't use here.
'augassign1': ( '%|%c %c %c\n', 0, 2, 1),
@@ -287,10 +287,10 @@ MAP_R0 = (TABLE_R0, -1, 0)
MAP_R = (TABLE_R, -1)
MAP = {
'stmt': MAP_R,
'stmt': MAP_R,
'call': MAP_R,
'del_stmt': MAP_R,
'designator': MAP_R,
'store': MAP_R,
'exprlist': MAP_R0,
}

View File

@@ -609,8 +609,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.preorder(n[0])
self.write(' for ')
start = len(self.f.getvalue())
designator = ast[iter_index-1]
self.preorder(designator)
store = ast[iter_index-1]
self.preorder(store)
self.set_pos_info(ast[iter_index-1], start, len(self.f.getvalue()))
self.write(' in ')
start = len(self.f.getvalue())
@@ -640,7 +640,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.customize(code._customize)
# skip over stmts sstmt smt
ast = ast[0][0][0]
designator = None
store = None
if ast in ['setcomp_func', 'dictcomp_func']:
# Offset 0: BUILD_SET should have the span
# of '{'
@@ -648,8 +648,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
for k in ast:
if k == 'comp_iter':
n = k
elif k == 'designator':
designator = k
elif k == 'store':
store = k
pass
pass
pass
@@ -663,23 +663,23 @@ class FragmentsWalker(pysource.SourceWalker, object):
# find innermost node
if_node = None
comp_for = None
comp_designator = None
comp_store = None
if n == 'comp_iter':
comp_for = n
comp_designator = ast[3]
comp_store = ast[3]
have_not = False
while n in ('list_iter', 'comp_iter'):
n = n[0] # recurse one step
if n == 'list_for':
if n[2] == 'designator':
designator = n[2]
if n[2] == 'store':
store = n[2]
n = n[3]
elif n in ['list_if', 'list_if_not', 'comp_if']:
have_not = n in ('list_if_not', 'comp_ifnot')
if_node = n[0]
if n[1] == 'designator':
designator = n[1]
if n[1] == 'store':
store = n[1]
n = n[2]
pass
pass
@@ -687,7 +687,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
# Python 2.7+ starts including set_comp_body
# Python 3.5+ starts including setcomp_func
assert n.kind in ('lc_body', 'comp_body', 'setcomp_func', 'set_comp_body'), ast
assert designator, "Couldn't find designator in list/set comprehension"
assert store, "Couldn't find store in list/set comprehension"
old_name = self.name
self.name = code_name
@@ -695,8 +695,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
gen_start = len(self.f.getvalue()) + 1
self.write(' for ')
start = len(self.f.getvalue())
self.preorder(designator)
self.set_pos_info(designator, start, len(self.f.getvalue()))
self.preorder(store)
self.set_pos_info(store, start, len(self.f.getvalue()))
self.write(' in ')
start = len(self.f.getvalue())
node[-3].parent = node
@@ -704,7 +704,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
fin = len(self.f.getvalue())
self.set_pos_info(node[-3], start, fin, old_name)
if comp_designator:
if comp_store:
self.preorder(comp_for)
elif if_node:
self.write(' if ')
@@ -738,7 +738,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
while n == 'list_iter':
n = n[0] # recurse one step
if n == 'list_for':
designator = n[2]
store = n[2]
n = n[3]
elif n in ('list_if', 'list_if_not'):
# FIXME: just a guess
@@ -755,8 +755,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.preorder(n[0])
self.write(' for ')
start = len(self.f.getvalue())
self.preorder(designator)
self.set_pos_info(designator, start, len(self.f.getvalue()))
self.preorder(store)
self.set_pos_info(store, start, len(self.f.getvalue()))
self.write(' in ')
start = len(self.f.getvalue())
node[-3].parent = node
@@ -806,17 +806,17 @@ class FragmentsWalker(pysource.SourceWalker, object):
start = len(self.f.getvalue())
assert node[0].kind.startswith('BUILD_SET')
self.set_pos_info(node[0], start-1, start)
designator = node[3]
assert designator == 'designator'
store = node[3]
assert store == 'store'
start = len(self.f.getvalue())
self.preorder(designator)
self.preorder(store)
fin = len(self.f.getvalue())
self.set_pos_info(designator, start, fin)
self.set_pos_info(store, start, fin)
for_iter_node = node[2]
assert for_iter_node.kind == 'FOR_ITER'
self.set_pos_info(for_iter_node, start, fin)
self.write(" for ")
self.preorder(designator)
self.preorder(store)
self.write(" in ")
self.preorder(param_node)
start = len(self.f.getvalue())
@@ -861,7 +861,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
ast = self.build_ast(code._tokens, code._customize)
self.customize(code._customize)
ast = ast[0][0][0]
designator = ast[3]
store = ast[3]
collection = node[collection_index]
n = ast[4]
@@ -873,7 +873,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
n = n[0] # recurse one step
# FIXME: adjust for set comprehension
if n == 'list_for':
designator = n[2]
store = n[2]
n = n[3]
elif n in ('list_if', 'list_if_not', 'comp_if', 'comp_if_not'):
# FIXME: just a guess
@@ -890,8 +890,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.preorder(n[0])
self.write(' for ')
start = len(self.f.getvalue())
self.preorder(designator)
self.set_pos_info(designator, start, len(self.f.getvalue()))
self.preorder(store)
self.set_pos_info(store, start, len(self.f.getvalue()))
self.write(' in ')
start = len(self.f.getvalue())
self.preorder(collection)

View File

@@ -297,7 +297,7 @@ class SourceWalker(GenericASTTraversal, object):
[ AST('expr',
[Token('LOAD_GLOBAL', pattr='__name__',
offset=0, has_arg=True)]),
AST('designator',
AST('store',
[ Token('STORE_NAME', pattr='__module__',
offset=3, has_arg=True)])
])])
@@ -992,13 +992,13 @@ class SourceWalker(GenericASTTraversal, object):
def n_import_as(self, node):
if self.version <= 2.1:
if len(node) == 2:
designator = node[1]
assert designator == 'designator'
if designator[0].pattr == node[0].pattr:
store = node[1]
assert store == 'store'
if store[0].pattr == node[0].pattr:
self.write("import %s\n" % node[0].pattr)
else:
self.write("import %s as %s\n" %
(node[0].pattr, designator[0].pattr))
(node[0].pattr, store[0].pattr))
pass
pass
self.prune() # stop recursing
@@ -1124,12 +1124,12 @@ class SourceWalker(GenericASTTraversal, object):
list_expr = node[1]
if len(node) >= 3:
designator = node[3]
store = node[3]
elif self.is_pypy and n[0] == 'list_for':
designator = n[0][2]
store = n[0][2]
assert n == 'list_iter'
assert designator == 'designator'
assert store == 'store'
# find innermost node
while n == 'list_iter':
@@ -1256,13 +1256,13 @@ class SourceWalker(GenericASTTraversal, object):
self.customize(code._customize)
# skip over stmts sstmt smt
ast = ast[0][0][0]
designator = None
store = None
if ast in ['setcomp_func', 'dictcomp_func']:
for k in ast:
if k == 'comp_iter':
n = k
elif k == 'designator':
designator = k
elif k == 'store':
store = k
pass
pass
pass
@@ -1276,23 +1276,23 @@ class SourceWalker(GenericASTTraversal, object):
# find innermost node
if_node = None
comp_for = None
comp_designator = None
comp_store = None
if n == 'comp_iter':
comp_for = n
comp_designator = ast[3]
comp_store = ast[3]
have_not = False
while n in ('list_iter', 'comp_iter'):
n = n[0] # recurse one step
if n in ('list_for', 'comp_for'):
if n[2] == 'designator':
designator = n[2]
if n[2] == 'store':
store = n[2]
n = n[3]
elif n in ('list_if', 'list_if_not', 'comp_if', 'comp_ifnot'):
have_not = n in ('list_if_not', 'comp_ifnot')
if_node = n[0]
if n[1] == 'designator':
designator = n[1]
if n[1] == 'store':
store = n[1]
n = n[2]
pass
pass
@@ -1300,18 +1300,18 @@ class SourceWalker(GenericASTTraversal, object):
# Python 2.7+ starts including set_comp_body
# Python 3.5+ starts including setcomp_func
assert n.kind in ('lc_body', 'comp_body', 'setcomp_func', 'set_comp_body'), ast
assert designator, "Couldn't find designator in list/set comprehension"
assert store, "Couldn't find store in list/set comprehension"
self.preorder(n[0])
self.write(' for ')
if comp_designator:
self.preorder(comp_designator)
if comp_store:
self.preorder(comp_store)
else:
self.preorder(designator)
self.preorder(store)
self.write(' in ')
self.preorder(node[-3])
if comp_designator:
if comp_store:
self.preorder(comp_for)
elif if_node:
self.write(' if ')
@@ -1345,7 +1345,7 @@ class SourceWalker(GenericASTTraversal, object):
while n == 'list_iter':
n = n[0] # recurse one step
if n == 'list_for':
designator = n[2]
store = n[2]
n = n[3]
elif n in ('list_if', 'list_if_not'):
# FIXME: just a guess
@@ -1361,7 +1361,7 @@ class SourceWalker(GenericASTTraversal, object):
self.preorder(n[0])
self.write(' for ')
self.preorder(designator)
self.preorder(store)
self.write(' in ')
self.preorder(collection)
if list_if:
@@ -1391,7 +1391,7 @@ class SourceWalker(GenericASTTraversal, object):
ast = self.build_ast(code._tokens, code._customize)
self.customize(code._customize)
ast = ast[0][0][0]
designator = ast[3]
store = ast[3]
collection = node[collection_index]
n = ast[4]
@@ -1403,7 +1403,7 @@ class SourceWalker(GenericASTTraversal, object):
n = n[0] # recurse one step
# FIXME: adjust for set comprehension
if n == 'list_for':
designator = n[2]
store = n[2]
n = n[3]
elif n in ('list_if', 'list_if_not', 'comp_if', 'comp_if_not'):
# FIXME: just a guess
@@ -1419,7 +1419,7 @@ class SourceWalker(GenericASTTraversal, object):
self.preorder(n[0])
self.write(' for ')
self.preorder(designator)
self.preorder(store)
self.write(' in ')
self.preorder(collection)
if list_if:
@@ -2088,7 +2088,7 @@ class SourceWalker(GenericASTTraversal, object):
# walk lhs; this
# returns a tuple of identifiers as used
# within the function definition
assert node[1] == 'designator'
assert node[1] == 'store'
# if lhs is not a UNPACK_TUPLE (or equiv.),
# add parenteses to make this a tuple
# if node[1][0] not in ('unpack', 'unpack_list'):
@@ -2135,7 +2135,7 @@ class SourceWalker(GenericASTTraversal, object):
QUAL_NAME = AST('stmt',
[ AST('assign',
[ AST('expr', [Token('LOAD_CONST', pattr=qualname)]),
AST('designator', [ Token('STORE_NAME', pattr='__qualname__')])
AST('store', [ Token('STORE_NAME', pattr='__qualname__')])
])])
have_qualname = (ast[0][0] == QUAL_NAME)
else:
@@ -2144,7 +2144,7 @@ class SourceWalker(GenericASTTraversal, object):
try:
if (first_stmt[0] == 'assign' and
first_stmt[0][0][0] == 'LOAD_CONST' and
first_stmt[0][1] == 'designator' and
first_stmt[0][1] == 'store' and
first_stmt[0][1][0] == Token('STORE_NAME', pattr='__qualname__')):
have_qualname = True
except: