mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
moved PushBackIterator to parsing
This commit is contained in:
36
evaluate.py
36
evaluate.py
@@ -565,7 +565,7 @@ class Execution(Executable):
|
|||||||
for key, value in var_arg_iterator:
|
for key, value in var_arg_iterator:
|
||||||
# Iterate until a key argument is found.
|
# Iterate until a key argument is found.
|
||||||
if key:
|
if key:
|
||||||
var_arg_iterator.push_back(key, value)
|
var_arg_iterator.push_back((key, value))
|
||||||
break
|
break
|
||||||
values.append(value)
|
values.append(value)
|
||||||
elif assignment[0] == '**':
|
elif assignment[0] == '**':
|
||||||
@@ -630,28 +630,7 @@ class Execution(Executable):
|
|||||||
else:
|
else:
|
||||||
yield None, var_arg
|
yield None, var_arg
|
||||||
|
|
||||||
class PushBackIterator(object):
|
return iter(parsing.PushBackIterator(iterate()))
|
||||||
def __init__(self, iterator):
|
|
||||||
self.pushes = []
|
|
||||||
self.iterator = iterator
|
|
||||||
|
|
||||||
def push_back(self, key, value):
|
|
||||||
self.pushes.append((key, value))
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def next(self):
|
|
||||||
""" Python 2 Compatibility """
|
|
||||||
return self.__next__()
|
|
||||||
|
|
||||||
def __next__(self):
|
|
||||||
try:
|
|
||||||
return self.pushes.pop()
|
|
||||||
except IndexError:
|
|
||||||
return next(self.iterator)
|
|
||||||
|
|
||||||
return iter(PushBackIterator(iterate()))
|
|
||||||
|
|
||||||
def get_set_vars(self):
|
def get_set_vars(self):
|
||||||
return self.get_defined_names()
|
return self.get_defined_names()
|
||||||
@@ -1198,6 +1177,9 @@ def follow_call_list(call_list):
|
|||||||
It is used to evaluate a two dimensional object, that has calls, arrays and
|
It is used to evaluate a two dimensional object, that has calls, arrays and
|
||||||
operators in it.
|
operators in it.
|
||||||
"""
|
"""
|
||||||
|
def evaluate_list_comprehension(self, call_list):
|
||||||
|
for a in call_list:
|
||||||
|
pass
|
||||||
if parsing.Array.is_type(call_list, parsing.Array.TUPLE,
|
if parsing.Array.is_type(call_list, parsing.Array.TUPLE,
|
||||||
parsing.Array.DICT):
|
parsing.Array.DICT):
|
||||||
# Tuples can stand just alone without any braces. These would be
|
# Tuples can stand just alone without any braces. These would be
|
||||||
@@ -1217,9 +1199,11 @@ def follow_call_list(call_list):
|
|||||||
result.append(call)
|
result.append(call)
|
||||||
# The string tokens are just operations (+, -, etc.)
|
# The string tokens are just operations (+, -, etc.)
|
||||||
elif not isinstance(call, str):
|
elif not isinstance(call, str):
|
||||||
#if str(call.name) == 'for': <--- list comprehensions
|
if str(call.name) == 'for':
|
||||||
# print '\n\ndini mueter'
|
# list comprehensions
|
||||||
if str(call.name) == 'if':
|
print '\n\ndini mueter', call_list
|
||||||
|
return []
|
||||||
|
elif str(call.name) == 'if':
|
||||||
# Ternary operators.
|
# Ternary operators.
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|||||||
35
parsing.py
35
parsing.py
@@ -54,6 +54,28 @@ def indent_block(text, indention=" "):
|
|||||||
return '\n'.join(map(lambda s: indention + s, lines)) + temp
|
return '\n'.join(map(lambda s: indention + s, lines)) + temp
|
||||||
|
|
||||||
|
|
||||||
|
class PushBackIterator(object):
|
||||||
|
def __init__(self, iterator):
|
||||||
|
self.pushes = []
|
||||||
|
self.iterator = iterator
|
||||||
|
|
||||||
|
def push_back(self, value):
|
||||||
|
self.pushes.append(value)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
""" Python 2 Compatibility """
|
||||||
|
return self.__next__()
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
if self.pushes:
|
||||||
|
return self.pushes.pop()
|
||||||
|
else:
|
||||||
|
return next(self.iterator)
|
||||||
|
|
||||||
|
|
||||||
class Base(object):
|
class Base(object):
|
||||||
"""
|
"""
|
||||||
This is just here to have an isinstance check, which is also used on
|
This is just here to have an isinstance check, which is also used on
|
||||||
@@ -1208,7 +1230,7 @@ class PyFuzzyParser(object):
|
|||||||
return Class(cname, super, first_pos)
|
return Class(cname, super, first_pos)
|
||||||
|
|
||||||
def _parse_statement(self, pre_used_token=None, added_breaks=None,
|
def _parse_statement(self, pre_used_token=None, added_breaks=None,
|
||||||
stmt_class=Statement):
|
stmt_class=Statement, list_comp=False):
|
||||||
"""
|
"""
|
||||||
Parses statements like:
|
Parses statements like:
|
||||||
|
|
||||||
@@ -1293,7 +1315,8 @@ class PyFuzzyParser(object):
|
|||||||
continue
|
continue
|
||||||
#token_type, tok = self.next()
|
#token_type, tok = self.next()
|
||||||
b = [')', ']']
|
b = [')', ']']
|
||||||
in_clause, tok = self._parse_statement(added_breaks=b)
|
in_clause, tok = self._parse_statement(added_breaks=b,
|
||||||
|
list_comp=True)
|
||||||
if tok not in b:
|
if tok not in b:
|
||||||
debug.warning('list comprehension brackets %s@%s' %
|
debug.warning('list comprehension brackets %s@%s' %
|
||||||
(tok, self.start_pos[0]))
|
(tok, self.start_pos[0]))
|
||||||
@@ -1374,12 +1397,16 @@ class PyFuzzyParser(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
debug.warning('return in non-function')
|
debug.warning('return in non-function')
|
||||||
|
|
||||||
|
if list_comp:
|
||||||
|
self.gen.push_back(self._current_full)
|
||||||
|
|
||||||
return stmt, tok
|
return stmt, tok
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
""" Generate the next tokenize pattern. """
|
""" Generate the next tokenize pattern. """
|
||||||
|
self._current_full = next(self.gen)
|
||||||
type, tok, self._tokenize_start_pos, self._tokenize_end_pos, \
|
type, tok, self._tokenize_start_pos, self._tokenize_end_pos, \
|
||||||
self.parserline = next(self.gen)
|
self.parserline = self._current_full
|
||||||
if self.user_position and self.start_pos[0] == self.user_position[0]:
|
if self.user_position and self.start_pos[0] == self.user_position[0]:
|
||||||
debug.dbg('user scope found [%s] = %s' % \
|
debug.dbg('user scope found [%s] = %s' % \
|
||||||
(self.parserline.replace('\n', ''), repr(self.scope)))
|
(self.parserline.replace('\n', ''), repr(self.scope)))
|
||||||
@@ -1400,7 +1427,7 @@ class PyFuzzyParser(object):
|
|||||||
:raises: IndentationError
|
:raises: IndentationError
|
||||||
"""
|
"""
|
||||||
buf = BytesIO(self.code)
|
buf = BytesIO(self.code)
|
||||||
self.gen = tokenize_func(buf.readline)
|
self.gen = PushBackIterator(tokenize_func(buf.readline))
|
||||||
|
|
||||||
extended_flow = ['else', 'elif', 'except', 'finally']
|
extended_flow = ['else', 'elif', 'except', 'finally']
|
||||||
statement_toks = ['{', '[', '(', '`']
|
statement_toks = ['{', '[', '(', '`']
|
||||||
|
|||||||
Reference in New Issue
Block a user