[pypy-commit] pypy py3.5: Add fixed gendfa from py3k to py3.5
raffael_t
pypy.commits at gmail.com
Sun May 22 16:16:46 EDT 2016
Author: Raffael Tfirst <raffael.tfirst at gmail.com>
Branch: py3.5
Changeset: r84596:342b00f71058
Date: 2016-05-22 22:16 +0200
http://bitbucket.org/pypy/pypy/changeset/342b00f71058/
Log: Add fixed gendfa from py3k to py3.5
diff --git a/dfa_generated.py b/dfa_generated.py
new file mode 100644
diff --git a/pypy/interpreter/pyparser/gendfa.py b/pypy/interpreter/pyparser/gendfa.py
--- a/pypy/interpreter/pyparser/gendfa.py
+++ b/pypy/interpreter/pyparser/gendfa.py
@@ -202,7 +202,7 @@
newArcPair(states, EMPTY),
pseudoExtras, number, funny, contStr, name))
dfaStates, dfaAccepts = nfaToDfa(states, *pseudoToken)
- return DFA(dfaStates, dfaAccepts)
+ return DFA(dfaStates, dfaAccepts), dfaStates
# ______________________________________________________________________
@@ -216,7 +216,9 @@
newArcPair(states, DEFAULT),
any(states, notGroupStr(states, "'\\")))),
newArcPair(states, "'"))
- singleDFA = DFA(*nfaToDfa(states, *single))
+ states, accepts = nfaToDfa(states, *single)
+ singleDFA = DFA(states, accepts)
+ states_singleDFA = states
states = []
double = chain(states,
any(states, notGroupStr(states, '"\\')),
@@ -226,7 +228,9 @@
newArcPair(states, DEFAULT),
any(states, notGroupStr(states, '"\\')))),
newArcPair(states, '"'))
- doubleDFA = DFA(*nfaToDfa(states, *double))
+ states, accepts = nfaToDfa(states, *double)
+ doubleDFA = DFA(states, accepts)
+ states_doubleDFA = states
states = []
single3 = chain(states,
any(states, notGroupStr(states, "'\\")),
@@ -241,7 +245,9 @@
notChainStr(states, "''"))),
any(states, notGroupStr(states, "'\\")))),
chainStr(states, "'''"))
- single3DFA = NonGreedyDFA(*nfaToDfa(states, *single3))
+ states, accepts = nfaToDfa(states, *single3)
+ single3DFA = NonGreedyDFA(states, accepts)
+ states_single3DFA = states
states = []
double3 = chain(states,
any(states, notGroupStr(states, '"\\')),
@@ -256,27 +262,34 @@
notChainStr(states, '""'))),
any(states, notGroupStr(states, '"\\')))),
chainStr(states, '"""'))
- double3DFA = NonGreedyDFA(*nfaToDfa(states, *double3))
- return {"'" : singleDFA,
- '"' : doubleDFA,
- "'''": single3DFA,
- '"""': double3DFA}
+ states, accepts = nfaToDfa(states, *double3)
+ double3DFA = NonGreedyDFA(states, accepts)
+ states_double3DFA = states
+ return {"'" : (singleDFA, states_singleDFA),
+ '"' : (doubleDFA, states_doubleDFA),
+ "'''": (single3DFA, states_single3DFA),
+ '"""': (double3DFA, states_double3DFA)}
# ______________________________________________________________________
-def output(name, dfa_class, dfa):
+def output(name, dfa_class, dfa, states):
import textwrap
+ lines = []
i = 0
for line in textwrap.wrap(repr(dfa.accepts), width = 50):
if i == 0:
- print "accepts =", line
+ lines.append("accepts = ")
else:
- print " ", line
+ lines.append(" ")
+ lines.append(line)
+ lines.append("\n")
i += 1
import StringIO
- print "states = ["
- for numstate, state in enumerate(dfa.states):
- print " #", numstate
+ lines.append("states = [\n")
+ for numstate, state in enumerate(states):
+ lines.append(" # ")
+ lines.append(str(numstate))
+ lines.append("\n")
s = StringIO.StringIO()
i = 0
for k, v in sorted(state.items()):
@@ -299,13 +312,15 @@
for line in text:
line = line.replace('::', ': ')
if i == 0:
- print ' {' + line
+ lines.append(' {')
else:
- print ' ' + line
+ lines.append(' ')
+ lines.append(line)
+ lines.append('\n')
i += 1
- print " ]"
- print "%s = automata.%s(states, accepts)" % (name, dfa_class)
- print
+ lines.append(" ]\n")
+ lines.append("%s = automata.%s(states, accepts)\n" % (name, dfa_class))
+ return ''.join(lines)
def main ():
print "# THIS FILE IS AUTOMATICALLY GENERATED BY gendfa.py"
@@ -314,13 +329,17 @@
print "# python gendfa.py > dfa_generated.py"
print
print "from pypy.interpreter.pyparser import automata"
- pseudoDFA = makePyPseudoDFA()
- output("pseudoDFA", "DFA", pseudoDFA)
+ pseudoDFA, states_pseudoDFA = makePyPseudoDFA()
+ print output("pseudoDFA", "DFA", pseudoDFA, states_pseudoDFA)
endDFAMap = makePyEndDFAMap()
- output("double3DFA", "NonGreedyDFA", endDFAMap['"""'])
- output("single3DFA", "NonGreedyDFA", endDFAMap["'''"])
- output("singleDFA", "DFA", endDFAMap["'"])
- output("doubleDFA", "DFA", endDFAMap['"'])
+ dfa, states = endDFAMap['"""']
+ print output("double3DFA", "NonGreedyDFA", dfa, states)
+ dfa, states = endDFAMap["'''"]
+ print output("single3DFA", "NonGreedyDFA", dfa, states)
+ dfa, states = endDFAMap["'"]
+ print output("singleDFA", "DFA", dfa, states)
+ dfa, states = endDFAMap['"']
+ print output("doubleDFA", "DFA", dfa, states)
# ______________________________________________________________________
More information about the pypy-commit
mailing list