Python 2.6 parsing bugs ..

and some parser list nonterminal cleanup
This commit is contained in:
rocky
2017-02-25 04:45:10 -05:00
parent 0a6c8ba909
commit 2fbbc728b1
2 changed files with 17 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2015-2016 Rocky Bernstein # Copyright (c) 2015-2017 Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org> # Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com> # Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright (c) 1999 John Aycock # Copyright (c) 1999 John Aycock
@@ -28,6 +28,16 @@ nop_func = lambda self, args: None
class PythonParser(GenericASTBuilder): class PythonParser(GenericASTBuilder):
def __init__(self, AST, start, debug):
super(PythonParser, self).__init__(AST, start, debug)
self.collect = frozenset(
['stmts', 'except_stmts', '_stmts',
'exprlist', 'kvlist', 'kwargs', 'come_froms',
# Python < 3
'print_items',
# PyPy:
'kvlist_n'])
def add_unique_rule(self, rule, opname, count, customize): def add_unique_rule(self, rule, opname, count, customize):
"""Add rule to grammar, but only if it hasn't been added previously """Add rule to grammar, but only if it hasn't been added previously
opname and count are used in the customize() semantic the actions opname and count are used in the customize() semantic the actions
@@ -115,11 +125,7 @@ class PythonParser(GenericASTBuilder):
return token.type return token.type
def nonterminal(self, nt, args): def nonterminal(self, nt, args):
collect = ('stmts', 'exprlist', 'kvlist', '_stmts', 'print_items', 'kwargs', if nt in self.collect and len(args) > 1:
# PYPY:
'kvlist_n')
if nt in collect and len(args) > 1:
# #
# Collect iterated thingies together. That is rather than # Collect iterated thingies together. That is rather than
# stmts -> stmts stmt -> stmts stmt -> ... # stmts -> stmts stmt -> stmts stmt -> ...

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2016 Rocky Bernstein # Copyright (c) 2017 Rocky Bernstein
""" """
spark grammar differences over Python2 for Python 2.6. spark grammar differences over Python2 for Python 2.6.
""" """
@@ -22,7 +22,10 @@ class Python26Parser(Python2Parser):
JUMP_IF_FALSE POP_TOP POP_TOP designator POP_TOP JUMP_IF_FALSE POP_TOP POP_TOP designator POP_TOP
try_middle ::= JUMP_FORWARD COME_FROM except_stmts try_middle ::= JUMP_FORWARD COME_FROM except_stmts
come_from_pop END_FINALLY COME_FROM come_from_pop END_FINALLY come_froms
try_middle ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY
come_froms
try_middle ::= jmp_abs COME_FROM except_stmts try_middle ::= jmp_abs COME_FROM except_stmts
POP_TOP END_FINALLY POP_TOP END_FINALLY