Get invalid INDENTs working.

The following DEDENT's are removed.
This commit is contained in:
Dave Halter
2015-01-12 12:22:57 +01:00
parent ef72f4fb6c
commit 582b9b01af
3 changed files with 12 additions and 4 deletions

View File

@@ -431,7 +431,6 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)):
yield self.names_dict
else:
for scope in self.py__mro__(self._evaluator):
print(scope.names_dict)
if isinstance(scope, compiled.CompiledObject):
yield scope.names_dicts(False, is_instance)[0]
else:

View File

@@ -106,8 +106,8 @@ class Parser(object):
}
self.global_names = []
self._omit_dedent = 0
print('start')
# TODO do print absolute import detection here.
#try:
# 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)
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'):
# Those can always be new statements.
add_token_callback(typ, value, prefix, start_pos)
@@ -280,6 +285,10 @@ class Parser(object):
def _tokenize(self, 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:
typ = token.opmap[value]
yield typ, value, prefix, start_pos

View File

@@ -31,8 +31,7 @@ def wrong_indents():
asdf = 3
asdf
asdf(
# doesn't work because of the indent issues.
#? str()
#? int()
asdf
def openbrace():
asdf = 3
@@ -104,6 +103,7 @@ try:
#? str()
""
def break(): pass
# wrong ternary expression
a = ''
a = 1 if