mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 02:27:06 +08:00
to the power of precedences
This commit is contained in:
@@ -113,7 +113,9 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
||||
operator = None
|
||||
for check_prio, check in enumerate(PythonGrammar.ORDER):
|
||||
if check_prio >= priority:
|
||||
break # respect priorities.
|
||||
# respect priorities.
|
||||
iterator.push_back(el)
|
||||
return left
|
||||
|
||||
try:
|
||||
match_index = check.index(el)
|
||||
@@ -137,6 +139,8 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
||||
_syntax_error(el)
|
||||
continue
|
||||
|
||||
if operator == '**':
|
||||
check_prio += 1 # to the power of is right-associative
|
||||
right = _check_operator(iterator, check_prio)
|
||||
if right is not None:
|
||||
left = Precedence(left, str(operator), right)
|
||||
|
||||
@@ -19,6 +19,7 @@ def parse_tree(statement_string):
|
||||
def test_simple():
|
||||
assert parse_tree('1+2') == (1, '+', 2)
|
||||
assert parse_tree('+2') == (None, '+', 2)
|
||||
assert parse_tree('1+2-3') == ((1, '+', 2), '-', 3)
|
||||
|
||||
|
||||
def test_prefixed():
|
||||
@@ -38,8 +39,15 @@ def test_invalid():
|
||||
assert parse_tree('1 not - 1') == (1, '-', 1)
|
||||
assert parse_tree('1 - not ~1') == (1, '-', (None, '~', 1))
|
||||
|
||||
# not not allowed
|
||||
assert parse_tree('1 is not not 1') == (1, 'is not', 1)
|
||||
|
||||
|
||||
def test_multi_part():
|
||||
assert parse_tree('1 not in 2') == (1, 'not in', 2)
|
||||
assert parse_tree('1 is not -1') == (1, 'is not', (None, '-', 1))
|
||||
assert parse_tree('1 is 1') == (1, 'is', 1)
|
||||
|
||||
|
||||
def test_power():
|
||||
assert parse_tree('2 ** 3 ** 4') == (2, '**', (3, '**', 4))
|
||||
|
||||
Reference in New Issue
Block a user