[pypy-svn] r36332 - in pypy/dist/pypy/interpreter: pyparser pyparser/test stablecompiler test
ac at codespeak.net
ac at codespeak.net
Tue Jan 9 12:08:44 CET 2007
Author: ac
Date: Tue Jan 9 12:08:43 2007
New Revision: 36332
Modified:
pypy/dist/pypy/interpreter/pyparser/astbuilder.py
pypy/dist/pypy/interpreter/pyparser/ebnfparse.py
pypy/dist/pypy/interpreter/pyparser/pysymbol.py
pypy/dist/pypy/interpreter/pyparser/pythonparse.py
pypy/dist/pypy/interpreter/pyparser/symbol.py
pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
pypy/dist/pypy/interpreter/stablecompiler/transformer.py
pypy/dist/pypy/interpreter/test/test_syntax.py
Log:
Stick to Python 2.4 syntax!
Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py Tue Jan 9 12:08:43 2007
@@ -778,13 +778,18 @@
def build_test(builder, nb):
atoms = get_atoms(builder, nb)
- if len(atoms) == 1:
+ l = len(atoms)
+ if l == 1:
builder.push(atoms[0])
- elif len(atoms) == 5:
+ elif l == 5 and atoms[1].get_value() == 'if':
builder.push(
ast.CondExpr(atoms[2], atoms[0], atoms[4], atoms[1].lineno))
else:
- assert False, "invalid number of atoms for rule 'test'"
+ lineno = atoms[1].lineno
+ items = []
+ for i in range(0,l,2): # this is atoms not 1
+ items.append(atoms[i])
+ builder.push(ast.Or(items, lineno))
# Note: we do not include a build_old_test() because it does not need to do
# anything.
@@ -1542,7 +1547,7 @@
# Build two almost identical ASTRULES dictionaries
ASTRULES = dict([(sym[key], value) for (key, value) in
- ASTRULES_Template.iteritems()])
+ ASTRULES_Template.iteritems() if key in sym])
del ASTRULES_Template
## Stack elements definitions ###################################
Modified: pypy/dist/pypy/interpreter/pyparser/ebnfparse.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/ebnfparse.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/ebnfparse.py Tue Jan 9 12:08:43 2007
@@ -261,7 +261,7 @@
from pprint import pprint
if __name__ == "__main__":
- grambuild = parse_grammar(file('data/Grammar2.5a'))
+ grambuild = parse_grammar(file('data/Grammar2.4'))
for i,r in enumerate(grambuild.items):
print "% 3d : %s" % (i, r)
pprint(grambuild.terminals.keys())
Modified: pypy/dist/pypy/interpreter/pyparser/pysymbol.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pysymbol.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/pysymbol.py Tue Jan 9 12:08:43 2007
@@ -45,6 +45,10 @@
"""NOT RPYTHON"""
assert type(sym)==str
return self.sym_values[ sym ]
+
+ def __contains__(self, sym):
+ """NOT RPYTHON"""
+ return sym in self.sym_values
_cpython_symbols = SymbolMapper( symbol.sym_name )
Modified: pypy/dist/pypy/interpreter/pyparser/pythonparse.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonparse.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonparse.py Tue Jan 9 12:08:43 2007
@@ -132,7 +132,7 @@
# unfortunately the command line options are not parsed yet, so it cannot
# be made configurable yet
-PYTHON_GRAMMAR, PYPY_VERSION = get_grammar_file("2.5a")
+PYTHON_GRAMMAR, PYPY_VERSION = get_grammar_file("2.4")
def python_grammar(fname):
"""returns a PythonParser build from the specified grammar file"""
Modified: pypy/dist/pypy/interpreter/pyparser/symbol.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/symbol.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/symbol.py Tue Jan 9 12:08:43 2007
@@ -82,10 +82,6 @@
gen_if = 331
testlist1 = 332
encoding_decl = 333
-old_test = 334
-or_test = 335
-old_lambdef = 336
-with_stmt = 337
# Generate sym_name
Modified: pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py Tue Jan 9 12:08:43 2007
@@ -210,8 +210,8 @@
# We do not export the following tests because we would have to implement 2.5
# features in the stable compiler (other than just building the AST).
expressions_inbetweenversions = expressions + [
- "1 if True else 2",
- "1 if False else 2",
+ #"1 if True else 2", # Disabled 2.5 syntax
+ #"1 if False else 2",
]
EXPECTED["k[v,]"] = ("Module(None, Stmt([Discard(Subscript(Name('k'), 2, "
@@ -794,7 +794,7 @@
]
def test_snippets():
- for snippet_name in SNIPPETS + NEW_GRAMMAR_SNIPPETS:
+ for snippet_name in SNIPPETS: # + NEW_GRAMMAR_SNIPPETS: # Disabled 2.5 syntax
filepath = os.path.join(os.path.dirname(__file__), 'samples', snippet_name)
source = file(filepath).read()
# To avoid using the stable compiler we pull an explicit AST out of the snippet
Modified: pypy/dist/pypy/interpreter/stablecompiler/transformer.py
==============================================================================
--- pypy/dist/pypy/interpreter/stablecompiler/transformer.py (original)
+++ pypy/dist/pypy/interpreter/stablecompiler/transformer.py Tue Jan 9 12:08:43 2007
@@ -616,10 +616,12 @@
else:
# Normal or-expression
return self.com_node(nodelist[0])
- else:
+ elif len(nodelist) == 5 and nodelist[1][0] =='if':
# Here we implement conditional expressions
return ast.CondExpr(nodelist[2], nodelist[0], nodelist[4],
nodelist[1].lineno)
+ else:
+ return self.com_binary(Or, nodelist)
def and_test(self, nodelist):
# not_test ('and' not_test)*
Modified: pypy/dist/pypy/interpreter/test/test_syntax.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_syntax.py (original)
+++ pypy/dist/pypy/interpreter/test/test_syntax.py Tue Jan 9 12:08:43 2007
@@ -256,15 +256,24 @@
raise
-class AppTestCondExpr:
+class Py25AppTest:
+ def setup_class(self):
+ space = self.space
+ w_globals = space.newdict([])
+ space.exec_('import sys; not_25 = sys.version_info < (2,5)',
+ w_globals, w_globals)
+ not_25 = space.is_true(space.getitem(w_globals, space.wrap('not_25')))
+ if not_25:
+ py.test.skip('Needs python 2.5 grammar')
+class AppTestCondExpr(Py25AppTest):
def test_condexpr(self):
for s, expected in [("x = 1 if True else 2", 1),
("x = 1 if False else 2", 2)]:
exec s
assert x == expected
-class AppTestWith:
+class AppTestWith(Py25AppTest):
def test_with_simple(self):
s = """from __future__ import with_statement
More information about the pypy-svn
mailing list