Skip to content

Commit

Permalink
learn to count newlines correctly in multiline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jun 23, 2013
1 parent f16470a commit 497953f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_parser.py
Expand Up @@ -2751,3 +2751,15 @@ def test_multiline_comments(self, space):

with self.raises(space, 'SyntaxError'):
space.parse("=begin\nbar\n=foo")

def test_multiline_comments_lineno(self, space):
r = space.parse("""
=begin
some
lines
=end
1 + 1
""")
assert r == ast.Main(ast.Block([
ast.Statement(ast.Send(ast.ConstantInt(1), "+", [ast.ConstantInt(1)], None, 6))
]))
1 change: 1 addition & 0 deletions topaz/lexer.py
Expand Up @@ -376,6 +376,7 @@ def multiline_comment(self, ch):
if ch == self.EOF:
self.error("embedded document meets end of file")
if ch in "\r\n":
self.newline(ch)
if (self.read() == "=" and
self.read() == "e" and
self.read() == "n" and
Expand Down

0 comments on commit 497953f

Please sign in to comment.