[pypy-commit] pypy default: make the parser only recognize variables when using the reverse debugger
cfbolz
pypy.commits at gmail.com
Tue Jun 5 14:36:29 EDT 2018
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch:
Changeset: r94725:1fc65745ebb4
Date: 2018-06-05 20:35 +0200
http://bitbucket.org/pypy/pypy/changeset/1fc65745ebb4/
Log: make the parser only recognize variables when using the reverse
debugger
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -27,7 +27,7 @@
generator._resolve_block_targets(blocks)
return generator, blocks
-class TestCompiler:
+class BaseTestCompiler:
"""These tests compile snippets of code and check them by
running them with our own interpreter. These are thus not
completely *unit* tests, but given that our interpreter is
@@ -74,6 +74,9 @@
def error_test(self, source, exc_type):
py.test.raises(exc_type, self.simple_test, source, None, None)
+
+class TestCompiler(BaseTestCompiler):
+
def test_issue_713(self):
func = "def f(_=2): return (_ if _ else _) if False else _"
yield self.st, func, "f()", 2
@@ -953,9 +956,11 @@
yield (self.st, "x=(lambda: (-0.0, 0.0), lambda: (0.0, -0.0))[1]()",
'repr(x)', '(0.0, -0.0)')
+class TestCompilerRevDB(BaseTestCompiler):
+ spaceconfig = {"translation.reverse_debugger": True}
+
def test_revdb_metavar(self):
from pypy.interpreter.reverse_debugging import dbstate, setup_revdb
- self.space.config.translation.reverse_debugger = True
self.space.reverse_debugging = True
try:
setup_revdb(self.space)
diff --git a/pypy/interpreter/pyparser/parser.py b/pypy/interpreter/pyparser/parser.py
--- a/pypy/interpreter/pyparser/parser.py
+++ b/pypy/interpreter/pyparser/parser.py
@@ -28,6 +28,7 @@
new.symbol_ids = self.symbol_ids
new.symbols_names = self.symbol_names
new.keyword_ids = self.keyword_ids
+ new.token_to_error_string = self.token_to_error_string
new.dfas = self.dfas
new.labels = self.labels
new.token_ids = self.token_ids
diff --git a/pypy/interpreter/pyparser/pygram.py b/pypy/interpreter/pyparser/pygram.py
--- a/pypy/interpreter/pyparser/pygram.py
+++ b/pypy/interpreter/pyparser/pygram.py
@@ -23,6 +23,17 @@
python_grammar_no_print.keyword_ids = python_grammar_no_print.keyword_ids.copy()
del python_grammar_no_print.keyword_ids["print"]
+python_grammar_revdb = python_grammar.shared_copy()
+python_grammar_no_print_revdb = python_grammar_no_print.shared_copy()
+copied_token_ids = python_grammar.token_ids.copy()
+python_grammar_revdb.token_ids = copied_token_ids
+python_grammar_no_print_revdb.token_ids = copied_token_ids
+
+metavar_token_id = pytoken.python_tokens['REVDBMETAVAR']
+# the following line affects python_grammar_no_print too, since they share the
+# dict
+del python_grammar.token_ids[metavar_token_id]
+
class _Tokens(object):
pass
for tok_name, idx in pytoken.python_tokens.iteritems():
@@ -39,3 +50,16 @@
syms._rev_lookup = rev_lookup # for debugging
del _get_python_grammar, _Tokens, tok_name, sym_name, idx
+
+def choose_grammar(print_function, revdb):
+ if print_function:
+ if revdb:
+ return python_grammar_no_print_revdb
+ else:
+ return python_grammar_no_print
+ else:
+ if revdb:
+ return python_grammar_revdb
+ else:
+ return python_grammar
+
diff --git a/pypy/interpreter/pyparser/pyparse.py b/pypy/interpreter/pyparser/pyparse.py
--- a/pypy/interpreter/pyparser/pyparse.py
+++ b/pypy/interpreter/pyparser/pyparse.py
@@ -160,10 +160,9 @@
compile_info.last_future_import = last_future_import
compile_info.flags |= newflags
- if compile_info.flags & consts.CO_FUTURE_PRINT_FUNCTION:
- self.grammar = pygram.python_grammar_no_print
- else:
- self.grammar = pygram.python_grammar
+ self.grammar = pygram.choose_grammar(
+ print_function=compile_info.flags & consts.CO_FUTURE_PRINT_FUNCTION,
+ revdb=self.space.config.translation.reverse_debugger)
for tp, value, lineno, column, line in tokens:
if self.add_token(tp, value, lineno, column, line):
diff --git a/pypy/interpreter/pyparser/test/test_pyparse.py b/pypy/interpreter/pyparser/test/test_pyparse.py
--- a/pypy/interpreter/pyparser/test/test_pyparse.py
+++ b/pypy/interpreter/pyparser/test/test_pyparse.py
@@ -168,13 +168,11 @@
assert expected_tree == tree
def test_revdb_dollar_num(self):
- self.parse('$0')
- self.parse('$5')
- self.parse('$42')
- self.parse('2+$42.attrname')
- py.test.raises(SyntaxError, self.parse, '$')
- py.test.raises(SyntaxError, self.parse, '$a')
- py.test.raises(SyntaxError, self.parse, '$.5')
+ assert not self.space.config.translation.reverse_debugger
+ py.test.raises(SyntaxError, self.parse, '$0')
+ py.test.raises(SyntaxError, self.parse, '$0 + 5')
+ py.test.raises(SyntaxError, self.parse,
+ "from __future__ import print_function\nx = ($0, print)")
def test_error_forgotten_chars(self):
info = py.test.raises(SyntaxError, self.parse, "if 1\n print 4")
@@ -183,3 +181,18 @@
assert "(expected ':')" in info.value.msg
info = py.test.raises(SyntaxError, self.parse, "def f:\n print 1")
assert "(expected '(')" in info.value.msg
+
+class TestPythonParserRevDB(TestPythonParser):
+ spaceconfig = {"translation.reverse_debugger": True}
+
+ def test_revdb_dollar_num(self):
+ self.parse('$0')
+ self.parse('$5')
+ self.parse('$42')
+ self.parse('2+$42.attrname')
+ self.parse("from __future__ import print_function\nx = ($0, print)")
+ py.test.raises(SyntaxError, self.parse, '$')
+ py.test.raises(SyntaxError, self.parse, '$a')
+ py.test.raises(SyntaxError, self.parse, '$.5')
+
+
More information about the pypy-commit
mailing list