[pypy-svn] r66118 - in pypy/branch/parser-compiler/pypy/interpreter/pyparser: . test
benjamin at codespeak.net
benjamin at codespeak.net
Sat Jul 4 15:55:44 CEST 2009
Author: benjamin
Date: Sat Jul 4 15:55:41 2009
New Revision: 66118
Modified:
pypy/branch/parser-compiler/pypy/interpreter/pyparser/metaparser.py
pypy/branch/parser-compiler/pypy/interpreter/pyparser/parser.py
pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_metaparser.py
Log:
represent an accepting state with the second field on the state tuple
Modified: pypy/branch/parser-compiler/pypy/interpreter/pyparser/metaparser.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/pyparser/metaparser.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/pyparser/metaparser.py Sat Jul 4 15:55:41 2009
@@ -140,9 +140,7 @@
arcs = []
for label, next in state.arcs.iteritems():
arcs.append((self.make_label(gram, label), dfa.index(next)))
- if state.is_final:
- arcs.append((0, state_index))
- states.append(arcs)
+ states.append((arcs, state.is_final))
our_id = gram.symbol_ids[name]
gram.dfas[our_id] = (states, self.make_first(gram, name))
gram.start = gram.symbol_ids[self.start_symbol]
Modified: pypy/branch/parser-compiler/pypy/interpreter/pyparser/parser.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/pyparser/parser.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/pyparser/parser.py Sat Jul 4 15:55:41 2009
@@ -87,18 +87,18 @@
while True:
dfa, state_index, node = self.stack[-1]
states, first = dfa
- arcs = states[state_index]
+ arcs, is_accepting = states[state_index]
for i, next_state in arcs:
sym_id = self.grammar.labels[i]
if label_index == i:
self.shift(next_state, token_type, value, lineno, column)
- state_index = next_state
- while states[state_index] == [(0, state_index)]:
+ state = states[next_state]
+ while state[1] and not state[0]:
self.pop()
if not self.stack:
return True
dfa, state_index, node = self.stack[-1]
- states = dfa[0]
+ state = dfa[0][state_index]
return False
elif sym_id >= 256:
sub_node_dfa = self.grammar.dfas[sym_id]
@@ -107,7 +107,7 @@
column)
break
else:
- if (0, state_index) in arcs:
+ if is_accepting:
self.pop()
if not self.stack:
raise ParseError("too much input", token_type, value,
Modified: pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_metaparser.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_metaparser.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_metaparser.py Sat Jul 4 15:55:41 2009
@@ -36,7 +36,7 @@
assert eval_sym in g.dfas
assert g.start == eval_sym
states, first = g.dfas[eval_sym]
- assert states == [[(1, 1)], [(0, 1)]]
+ assert states == [([(1, 1)], False), ([], True)]
assert g.labels[0] == 0
def test_load_python_grammars(self):
@@ -53,10 +53,10 @@
g = self.gram_for("foo: NAME STRING OP '+'")
assert len(g.dfas) == 1
states = g.dfas[g.symbol_ids["foo"]][0]
- last = states[0][0][1]
+ last = states[0][0][0][1]
for state in states[1:-1]:
- assert last < state[0][1]
- last = state[0][1]
+ assert last < state[0][0][1]
+ last = state[0][0][1]
def test_alternatives(self):
g = self.gram_for("foo: STRING | OP")
More information about the Pypy-commit
mailing list