flow syntax errors should still make it possible to add them to the parser (otherwise parser doesn't include all the code

This commit is contained in:
Dave Halter
2014-01-17 01:15:36 +01:00
parent 3337d638d1
commit e5d40c3685

View File

@@ -593,8 +593,7 @@ class Parser(object):
# multiple inputs because of with # multiple inputs because of with
inputs = [] inputs = []
first = True first = True
while first or command == 'with' \ while first or command == 'with' and tok not in [':', '\n']:
and tok not in [':', '\n']:
statement, tok = \ statement, tok = \
self._parse_statement(added_breaks=added_breaks) self._parse_statement(added_breaks=added_breaks)
if command == 'except' and tok == ',': if command == 'except' and tok == ',':
@@ -608,25 +607,21 @@ class Parser(object):
inputs.append(statement) inputs.append(statement)
first = False first = False
if tok == ':': f = pr.Flow(self.module, command, inputs, first_pos)
f = pr.Flow(self.module, command, inputs, first_pos) if command in extended_flow:
if command in extended_flow: # the last statement has to be another part of
# the last statement has to be another part of # the flow statement, because a dedent releases the
# the flow statement, because a dedent releases the # main scope, so just take the last statement.
# main scope, so just take the last statement. try:
try: s = self._scope.statements[-1].set_next(f)
s = self._scope.statements[-1].set_next(f) except (AttributeError, IndexError):
except (AttributeError, IndexError): # If set_next doesn't exist, just add it.
# If set_next doesn't exist, just add it.
s = self._scope.add_statement(f)
else:
s = self._scope.add_statement(f) s = self._scope.add_statement(f)
self._scope = s
else: else:
for i in inputs: s = self._scope.add_statement(f)
i.parent = use_as_parent_scope self._scope = s
debug.warning('syntax err, flow started @%s', if tok != ':':
self.start_pos[0]) debug.warning('syntax err, flow started @%s', self.start_pos[0])
# returns # returns
elif tok in ['return', 'yield']: elif tok in ['return', 'yield']:
s = self.start_pos s = self.start_pos