[pypy-svn] r35172 - in pypy/dist/pypy/rlib/parsing: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Nov 30 17:05:22 CET 2006
Author: cfbolz
Date: Thu Nov 30 17:05:21 2006
New Revision: 35172
Modified:
pypy/dist/pypy/rlib/parsing/parsing.py
pypy/dist/pypy/rlib/parsing/test/test_parse.py
pypy/dist/pypy/rlib/parsing/tree.py
Log:
allow a nonterminal to be replaced by nothing
Modified: pypy/dist/pypy/rlib/parsing/parsing.py
==============================================================================
--- pypy/dist/pypy/rlib/parsing/parsing.py (original)
+++ pypy/dist/pypy/rlib/parsing/parsing.py Thu Nov 30 17:05:21 2006
@@ -1,5 +1,5 @@
import py
-from pypy.rlib.parsing.tree import Node, Symbol, Nonterminal, Epsilon
+from pypy.rlib.parsing.tree import Node, Symbol, Nonterminal
class Rule(object):
def __init__(self, nonterminal, expansions):
@@ -119,15 +119,11 @@
if node is None:
error = combine_errors(error, error2)
break
- if not isinstance(node, Epsilon):
- children.append(node)
+ children.append(node)
curr = next
else:
- if children:
- result = (Nonterminal(symbol, children), curr, error)
- else:
- assert expansion == []
- result = (Epsilon(), curr, error)
+ assert len(expansion) == len(children)
+ result = (Nonterminal(symbol, children), curr, error)
self.matched[i, symbol] = result
return result
self.matched[i, symbol] = None, 0, error
@@ -304,7 +300,7 @@
if expansionindex == %s:""" % (expansionindex, ))
if not expansion:
code.append("""\
- result = (Epsilon(), i)
+ result = (Nonterminal(symbol, []), i)
self.matched_nonterminals%(number)s[i] = result
return result""" % vars())
continue
@@ -323,8 +319,6 @@
last_failed_position = next
expansionindex = %(nextindex)s
continue
- if not isinstance(node, Epsilon):
- children.append(node)
curr = next""" % vars())
code.append("""\
result = (Nonterminal(%(symbol)r, children), curr)
Modified: pypy/dist/pypy/rlib/parsing/test/test_parse.py
==============================================================================
--- pypy/dist/pypy/rlib/parsing/test/test_parse.py (original)
+++ pypy/dist/pypy/rlib/parsing/test/test_parse.py Thu Nov 30 17:05:21 2006
@@ -74,6 +74,4 @@
p = PackratParser([r1], "S")
assert p.parse([(c, i) for i, c, in enumerate("xyx")]) is not None
assert p.parse([(c, i) for i, c, in enumerate("xx")]) is not None
-
-
-
+ t = p.parse([(c, i) for i, c, in enumerate("xxxxxx")])
Modified: pypy/dist/pypy/rlib/parsing/tree.py
==============================================================================
--- pypy/dist/pypy/rlib/parsing/tree.py (original)
+++ pypy/dist/pypy/rlib/parsing/tree.py Thu Nov 30 17:05:21 2006
@@ -22,8 +22,9 @@
def dot(self):
addinfo = str(self.additional_info).replace('"', "'") or "_"
- yield ('"%s" [label="%r%r"];' % (
- id(self), self.symbol, addinfo)).replace("\\", "\\\\")
+ yield ('"%s" [shape=box,label="%s\\n%s"];' % (
+ id(self), self.symbol.replace("\\", "\\\\"),
+ repr(addinfo).replace("\\", "\\\\")))
def visit(self, visitor):
"NOT_RPYTHON"
@@ -66,9 +67,6 @@
else:
return specific(self)
-class Epsilon(Node):
- pass
-
class VisitError(Exception):
def __init__(self, node):
self.node = node
More information about the Pypy-commit
mailing list