mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +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 parse_tree(self, strip_literals=False):
|
||||||
def process(which):
|
def process(which):
|
||||||
try:
|
try:
|
||||||
which = which.parse_tree
|
which = which.parse_tree()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
if strip_literals and isinstance(which, pr.Literal):
|
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):
|
def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
left = _get_number(iterator, priority)
|
left = _get_number(iterator, priority)
|
||||||
|
except StopIteration:
|
||||||
|
_syntax_error(iterator.current, 'SyntaxError operand missing')
|
||||||
|
return None
|
||||||
|
|
||||||
for el in iterator:
|
for el in iterator:
|
||||||
if not isinstance(el, pr.Operator):
|
if not isinstance(el, pr.Operator):
|
||||||
_syntax_error(el)
|
_syntax_error(el)
|
||||||
@@ -127,5 +132,7 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
|||||||
if operator is None:
|
if operator is None:
|
||||||
_syntax_error(el)
|
_syntax_error(el)
|
||||||
continue
|
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
|
return left
|
||||||
|
|||||||
@@ -581,7 +581,7 @@ class Parser(object):
|
|||||||
continue
|
continue
|
||||||
# default
|
# default
|
||||||
elif token_type in (tokenize.NAME, tokenize.STRING,
|
elif token_type in (tokenize.NAME, tokenize.STRING,
|
||||||
tokenize.NUMBER) \
|
tokenize.NUMBER, tokenize.OP) \
|
||||||
or tok_str in statement_toks:
|
or tok_str in statement_toks:
|
||||||
# this is the main part - a name can be a function or a
|
# this is the main part - a name can be a function or a
|
||||||
# normal var, which can follow anything. but this is done
|
# normal var, which can follow anything. but this is done
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ def parse_tree(statement_string):
|
|||||||
if isinstance(pr, precedence.Precedence):
|
if isinstance(pr, precedence.Precedence):
|
||||||
return pr.parse_tree(strip_literals=True)
|
return pr.parse_tree(strip_literals=True)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
return pr.value # Literal
|
||||||
|
except AttributeError:
|
||||||
return pr
|
return pr
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user