Skip to content

Commit

Permalink
Merge pull request #735 from morphyn/master
Browse files Browse the repository at this point in the history
Fix #700 multiline ternary operator causes SyntaxError
  • Loading branch information
alex committed May 29, 2013
2 parents 4e8b936 + ab846fc commit c6df052
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,15 @@ def test_def(self, space):
ast.Statement(ast.Function(None, "f", [], None, None, ast.Nil()))
]))

r = space.parse("""
def
f
end
""")
assert r == ast.Main(ast.Block([
ast.Statement(ast.Function(None, "f", [], None, None, ast.Nil()))
]))

assert space.parse("def []; end") == ast.Main(ast.Block([
ast.Statement(ast.Function(None, "[]", [], None, None, ast.Nil()))
]))
Expand Down Expand Up @@ -1242,6 +1251,14 @@ class X
ast.Statement(ast.Class(ast.Scope(2), "X", None, ast.Nil()))
]))

r = space.parse("""
class
X
end""")
assert r == ast.Main(ast.Block([
ast.Statement(ast.Class(ast.Scope(3), "X", None, ast.Nil()))
]))

r = space.parse("""
class X
def f()
Expand Down Expand Up @@ -2388,6 +2405,16 @@ def test_ternary_operator(self, space):
ast.ConstantInt(0),
))
]))
r = space.parse("""
0 ?
(0) : 0
""")
assert r == ast.Main(ast.Block([
ast.Statement(ast.If(ast.ConstantInt(0),
ast.Block([ast.Statement(ast.ConstantInt(0))]),
ast.ConstantInt(0),
))
]))

def test_case(self, space):
r = space.parse("""
Expand Down
4 changes: 3 additions & 1 deletion topaz/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def tokenize(self):
elif ch in "\r\n":
space_seen = newline_seen = True
self.newline(ch)
if self.state not in [self.EXPR_BEG, self.EXPR_DOT]:
if self.state not in [self.EXPR_BEG, self.EXPR_DOT,
self.EXPR_VALUE, self.EXPR_FNAME,
self.EXPR_CLASS]:
self.add("\n")
self.command_start = True
self.state = self.EXPR_BEG
Expand Down

0 comments on commit c6df052

Please sign in to comment.