1
0
forked from VimPlug/jedi

some parser end positions changed

This commit is contained in:
David Halter
2013-04-15 10:22:27 +04:30
parent bafb17001b
commit b08390c136
5 changed files with 14 additions and 5 deletions

View File

@@ -85,7 +85,7 @@ class NoErrorTokenizer(object):
if self.closed: if self.closed:
raise MultiLevelStopIteration() raise MultiLevelStopIteration()
try: try:
last_previous = self.previous self.last_previous = self.previous
self.previous = self.current self.previous = self.current
self.current = next(self.gen) self.current = next(self.gen)
except tokenize.TokenError: except tokenize.TokenError:
@@ -112,7 +112,7 @@ class NoErrorTokenizer(object):
if c[0] == tokenize.ENDMARKER: if c[0] == tokenize.ENDMARKER:
self.current = self.previous self.current = self.previous
self.previous = last_previous self.previous = self.last_previous
raise MultiLevelStopIteration() raise MultiLevelStopIteration()
# this is exactly the same check as in fast_parser, but this time with # this is exactly the same check as in fast_parser, but this time with
@@ -155,6 +155,9 @@ class NoErrorTokenizer(object):
if tok in FLOWS or tok in breaks: if tok in FLOWS or tok in breaks:
self.in_flow = tok in FLOWS self.in_flow = tok in FLOWS
if not self.is_decorator and not self.in_flow: if not self.is_decorator and not self.in_flow:
print tok, c
if 6230 < c[2][0] < 6290:
print tok, c
close() close()
self.is_decorator = '@' == tok self.is_decorator = '@' == tok
if not self.is_decorator: if not self.is_decorator:

View File

@@ -373,6 +373,7 @@ def find_name(scope, name_str, position=None, search_global=False,
comparison_func = lambda name: (name.start_pos) comparison_func = lambda name: (name.start_pos)
for nscope, name_list in scope_generator: for nscope, name_list in scope_generator:
print nscope, name_list
break_scopes = [] break_scopes = []
# here is the position stuff happening (sorting of variables) # here is the position stuff happening (sorting of variables)
for name in sorted(name_list, key=comparison_func, reverse=True): for name in sorted(name_list, key=comparison_func, reverse=True):

View File

@@ -317,7 +317,7 @@ class FastParser(use_metaclass(CachedFastParser)):
is_first = True is_first = True
for code_part in parts: for code_part in parts:
lines = code_part.count('\n') + 1 lines = code_part.count('\n') + 1
if is_first or self._line_offset >= p.end_pos[0] - 1: if is_first or self._line_offset >= p.end_pos[0]:
indent = len(re.match(r'[ \t]*', code_part).group(0)) indent = len(re.match(r'[ \t]*', code_part).group(0))
if is_first and self.current_node is not None: if is_first and self.current_node is not None:
nodes = [self.current_node] nodes = [self.current_node]
@@ -330,6 +330,7 @@ class FastParser(use_metaclass(CachedFastParser)):
nodes += self.current_node._old_children nodes += self.current_node._old_children
# check if code_part has already been parsed # check if code_part has already been parsed
print '#'*45,self._line_offset, p and p.end_pos, '\n', code_part
p, node = self._get_parser(code_part, nodes) p, node = self._get_parser(code_part, nodes)
if is_first: if is_first:
@@ -347,11 +348,13 @@ class FastParser(use_metaclass(CachedFastParser)):
self.parsers.append(p) self.parsers.append(p)
is_first = False is_first = False
else:
print '#'*45, self._line_offset, p.end_pos, 'theheck\n', code_part
self._line_offset += lines self._line_offset += lines
self._start += len(code_part) + 1 # +1 for newline self._start += len(code_part) + 1 # +1 for newline
#print(self.parsers[0].module.get_code()) print(self.parsers[0].module.get_code())
#for p in self.parsers: #for p in self.parsers:
# print(p.module.get_code()) # print(p.module.get_code())
# print(p.module.start_pos, p.module.end_pos) # print(p.module.start_pos, p.module.end_pos)

View File

@@ -80,6 +80,8 @@ class Parser(object):
if self.current[0] in (tokenize.NL, tokenize.NEWLINE): if self.current[0] in (tokenize.NL, tokenize.NEWLINE):
# we added a newline before, so we need to "remove" it again. # we added a newline before, so we need to "remove" it again.
self.end_pos = self._gen.previous[2] self.end_pos = self._gen.previous[2]
if self.current[0] == tokenize.INDENT:
self.end_pos = self._gen.last_previous[2]
self.start_pos = self.module.start_pos self.start_pos = self.module.start_pos
self.module.end_pos = self.end_pos self.module.end_pos = self.end_pos

View File

@@ -454,7 +454,7 @@ class Function(Scope):
string += "def %s(%s):\n" % (self.name, params) string += "def %s(%s):\n" % (self.name, params)
string += super(Function, self).get_code(True, indention) string += super(Function, self).get_code(True, indention)
if self.is_empty(): if self.is_empty():
string += "pass\n" string += indention + 'pass\n'
return string return string
def is_empty(self): def is_empty(self):