Skip to content
Permalink
Browse files

Merge pull request #735 from morphyn/master

Fix #700 multiline ternary operator causes SyntaxError
  • Loading branch information
alex committed May 29, 2013
2 parents 4e8b936 + ab846fc commit c6df052a641c8434c8020762f0996c7eeeeeeb88
Showing with 30 additions and 1 deletion.
  1. +27 −0 tests/test_parser.py
  2. +3 −1 topaz/lexer.py
@@ -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()))
]))
@@ -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()
@@ -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("""
@@ -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

0 comments on commit c6df052

Please sign in to comment.