Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: pyparser-improvements-3 Changeset: r94729:37acacd15a8b Date: 2018-06-06 14:27 +0200 http://bitbucket.org/pypy/pypy/changeset/37acacd15a8b/
Log: merge default 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 @@ -165,10 +165,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) try: for token in tokens: 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') + + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit