Skip to content

Commit

Permalink
Fix parsing for if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
dlorch committed May 5, 2016
1 parent ec1d74e commit 75c01e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pycep/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,11 @@ def _if_stmt(tokens):
result.append(tokens.accept(token.OP, ":", result_token=token.COLON))
result.append(_suite(tokens))

if tokens.check(token.NAME, "elif"):
raise NotImplementedError
while tokens.check(token.NAME, "elif"):
result.append(tokens.accept(token.NAME, "elif"))
result.append(_test(tokens))
result.append(tokens.accept(token.OP, ":", result_token=token.COLON))
result.append(_suite(tokens))

if tokens.check(token.NAME, "else"):
result.append(tokens.accept(token.NAME, "else"))
Expand Down
10 changes: 10 additions & 0 deletions pycep/tests/snippets/pos/astrein.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class decorated_class():
continue
print "Found a number", num

if x < 0:
x = 0
print 'Negative changed to zero'
elif x == 0:
print 'Zero'
elif x == 1:
print 'Single'
else:
print 'More'

for x in [1, 2, 3]:
pass
del x
Expand Down

0 comments on commit 75c01e7

Please sign in to comment.