mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
Get invalid INDENTs working.
The following DEDENT's are removed.
This commit is contained in:
@@ -431,7 +431,6 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
yield self.names_dict
|
yield self.names_dict
|
||||||
else:
|
else:
|
||||||
for scope in self.py__mro__(self._evaluator):
|
for scope in self.py__mro__(self._evaluator):
|
||||||
print(scope.names_dict)
|
|
||||||
if isinstance(scope, compiled.CompiledObject):
|
if isinstance(scope, compiled.CompiledObject):
|
||||||
yield scope.names_dicts(False, is_instance)[0]
|
yield scope.names_dicts(False, is_instance)[0]
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ class Parser(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.global_names = []
|
self.global_names = []
|
||||||
|
self._omit_dedent = 0
|
||||||
|
|
||||||
print('start')
|
|
||||||
# TODO do print absolute import detection here.
|
# TODO do print absolute import detection here.
|
||||||
#try:
|
#try:
|
||||||
# del python_grammar_no_print_statement.keywords["print"]
|
# del python_grammar_no_print_statement.keywords["print"]
|
||||||
@@ -231,6 +231,11 @@ class Parser(object):
|
|||||||
|
|
||||||
#print('err', token.tok_name[typ], repr(value), start_pos, len(stack), index)
|
#print('err', token.tok_name[typ], repr(value), start_pos, len(stack), index)
|
||||||
self._stack_removal(grammar, stack, index + 1, value, start_pos)
|
self._stack_removal(grammar, stack, index + 1, value, start_pos)
|
||||||
|
if typ == token.INDENT:
|
||||||
|
# For every deleted INDENT we got to delete a DEDENT as well.
|
||||||
|
# Otherwise the parser will get into trouble and DEDENT too early.
|
||||||
|
self._omit_dedent += 1
|
||||||
|
|
||||||
if value in ('import', 'from', 'class', 'def', 'try', 'while', 'return'):
|
if value in ('import', 'from', 'class', 'def', 'try', 'while', 'return'):
|
||||||
# Those can always be new statements.
|
# Those can always be new statements.
|
||||||
add_token_callback(typ, value, prefix, start_pos)
|
add_token_callback(typ, value, prefix, start_pos)
|
||||||
@@ -280,6 +285,10 @@ class Parser(object):
|
|||||||
|
|
||||||
def _tokenize(self, tokenizer):
|
def _tokenize(self, tokenizer):
|
||||||
for typ, value, start_pos, prefix in tokenizer:
|
for typ, value, start_pos, prefix in tokenizer:
|
||||||
|
if self._omit_dedent and typ == token.DEDENT:
|
||||||
|
self._omit_dedent -= 1
|
||||||
|
continue
|
||||||
|
|
||||||
if typ == token.OP:
|
if typ == token.OP:
|
||||||
typ = token.opmap[value]
|
typ = token.opmap[value]
|
||||||
yield typ, value, prefix, start_pos
|
yield typ, value, prefix, start_pos
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ def wrong_indents():
|
|||||||
asdf = 3
|
asdf = 3
|
||||||
asdf
|
asdf
|
||||||
asdf(
|
asdf(
|
||||||
# doesn't work because of the indent issues.
|
#? int()
|
||||||
#? str()
|
|
||||||
asdf
|
asdf
|
||||||
def openbrace():
|
def openbrace():
|
||||||
asdf = 3
|
asdf = 3
|
||||||
@@ -104,6 +103,7 @@ try:
|
|||||||
#? str()
|
#? str()
|
||||||
""
|
""
|
||||||
|
|
||||||
|
def break(): pass
|
||||||
# wrong ternary expression
|
# wrong ternary expression
|
||||||
a = ''
|
a = ''
|
||||||
a = 1 if
|
a = 1 if
|
||||||
|
|||||||
Reference in New Issue
Block a user