diff --git a/jedi/evaluate/precedence.py b/jedi/evaluate/precedence.py index b96d80d6..22527c30 100644 --- a/jedi/evaluate/precedence.py +++ b/jedi/evaluate/precedence.py @@ -31,7 +31,7 @@ class PythonGrammar(object): EXPR = '|', COMPARISON = ('<', '>', '==', '>=', '<=', '!=', 'in', - MultiPart('not', 'in'), MultiPart('is', 'not')), 'is' + MultiPart('not', 'in'), MultiPart('is', 'not')), 'is' NOT_TEST = 'not', AND_TEST = 'and', @@ -58,7 +58,7 @@ class Precedence(object): def parse_tree(self, strip_literals=False): def process(which): try: - which = which.parse_tree + which = which.parse_tree() except AttributeError: pass if strip_literals and isinstance(which, pr.Literal): @@ -98,7 +98,12 @@ def _get_number(iterator, priority=PythonGrammar.LOWEST_PRIORITY): def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY): """ """ - left = _get_number(iterator, priority) + try: + left = _get_number(iterator, priority) + except StopIteration: + _syntax_error(iterator.current, 'SyntaxError operand missing') + return None + for el in iterator: if not isinstance(el, pr.Operator): _syntax_error(el) @@ -127,5 +132,7 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY): if operator is None: _syntax_error(el) continue - left = Precedence(left, operator, _check_operator(iterator, check_prio)) + right = _check_operator(iterator, check_prio) + if right is not None: + left = Precedence(left, operator, right) return left diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index bf3db210..5c2b6e51 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -581,7 +581,7 @@ class Parser(object): continue # default elif token_type in (tokenize.NAME, tokenize.STRING, - tokenize.NUMBER) \ + tokenize.NUMBER, tokenize.OP) \ or tok_str in statement_toks: # this is the main part - a name can be a function or a # normal var, which can follow anything. but this is done diff --git a/test/test_evaluate/test_precedence.py b/test/test_evaluate/test_precedence.py index 7b1eb414..65c3e1a4 100644 --- a/test/test_evaluate/test_precedence.py +++ b/test/test_evaluate/test_precedence.py @@ -10,7 +10,10 @@ def parse_tree(statement_string): if isinstance(pr, precedence.Precedence): return pr.parse_tree(strip_literals=True) else: - return pr + try: + return pr.value # Literal + except AttributeError: + return pr def test_simple():