mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
precedence working for some simple cases (and invalid statements)
This commit is contained in:
@@ -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):
|
||||
"""
|
||||
"""
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -10,6 +10,9 @@ def parse_tree(statement_string):
|
||||
if isinstance(pr, precedence.Precedence):
|
||||
return pr.parse_tree(strip_literals=True)
|
||||
else:
|
||||
try:
|
||||
return pr.value # Literal
|
||||
except AttributeError:
|
||||
return pr
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user