From 42af39ed53d0d1c501343abbe85cf189f0c90ced Mon Sep 17 00:00:00 2001 From: Felix von Ferey Date: Tue, 21 Jul 2015 05:09:03 +0200 Subject: [PATCH 1/3] Testcase for bug https://github.com/mirah/mirah-parser/issues/25. --- test/test_mirah.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test_mirah.rb b/test/test_mirah.rb index bcff5e3..71ac068 100644 --- a/test/test_mirah.rb +++ b/test/test_mirah.rb @@ -143,6 +143,26 @@ def test_position assert_equal("TestParsing-1", ast.position.source.name) end + def test_position_after_multiline_sstring_literal + ast = parse("SOMECONST = \'\n\n\n\'\n foo ").body.get(1) + assert_equal("foo", ast.name.identifier) + assert_equal(5, ast.position.start_line) + assert_equal(3, ast.position.start_column) + assert_equal(5, ast.position.end_line) + assert_equal(6, ast.position.end_column) + assert_equal("TestParsing-1", ast.position.source.name) + end + + def test_position_after_multiline_dstring_literal + ast = parse("SOMECONST = \"\n\n\n\"\n foo ").body.get(1) + assert_equal("foo", ast.name.identifier) + assert_equal(5, ast.position.start_line) + assert_equal(3, ast.position.start_column) + assert_equal(5, ast.position.end_line) + assert_equal(6, ast.position.end_column) + assert_equal("TestParsing-1", ast.position.source.name) + end + def test_modified_position ast = MirahParser.new.parse( StringCodeSource.new("test_modified_position", "foo", 3, 5)).body.get(0) From a13ebdf6ef86cee588bc4b4cd9c059a45c010808 Mon Sep 17 00:00:00 2001 From: Felix von Ferey Date: Tue, 21 Jul 2015 05:09:51 +0200 Subject: [PATCH 2/3] Fix bug https://github.com/mirah/mirah-parser/issues/25 for SStrings. --- src/mirahparser/impl/MirahLexer.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mirahparser/impl/MirahLexer.java b/src/mirahparser/impl/MirahLexer.java index 9431369..153adeb 100644 --- a/src/mirahparser/impl/MirahLexer.java +++ b/src/mirahparser/impl/MirahLexer.java @@ -203,14 +203,20 @@ public Tokens lex(MirahLexer l, Input i) { if (isEscape(i)) { return Tokens.tEscape; } + break; + case '\n': + l.noteNewline(); } - readRestOfString(i); + readRestOfString(l, i); return Tokens.tStringContent; } - private void readRestOfString(Input i) { + private void readRestOfString(MirahLexer l, Input i) { int c = 0; for (c = i.read(); c != EOF;c = i.read()) { + if (c == '\n') { + l.noteNewline(); + } if (c == '\'') { i.backup(1); break; From a900c10d914a6cd6cb6e8d90ae2287e7dea53c98 Mon Sep 17 00:00:00 2001 From: Felix von Ferey Date: Tue, 21 Jul 2015 05:13:51 +0200 Subject: [PATCH 3/3] Fix bug https://github.com/mirah/mirah-parser/issues/25 for DStrings. --- src/mirahparser/impl/MirahLexer.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mirahparser/impl/MirahLexer.java b/src/mirahparser/impl/MirahLexer.java index 153adeb..cd9a9d5 100644 --- a/src/mirahparser/impl/MirahLexer.java +++ b/src/mirahparser/impl/MirahLexer.java @@ -254,8 +254,12 @@ public Tokens lex(MirahLexer l, Input i) { return Tokens.tStrEvBegin; } i.backup(1); + break; + case '\n': + l.noteNewline(); + break; } - readRestOfString(i); + readRestOfString(l, i); return Tokens.tStringContent; } public Tokens readEndOfString(Input i) { @@ -290,7 +294,7 @@ private void readEscape(Input i) { } } - private void readRestOfString(Input i) { + private void readRestOfString(MirahLexer l, Input i) { int c = 0; for (c = i.read(); c != EOF; c = i.read()) { if (isEndOfString(c)) { @@ -307,6 +311,8 @@ private void readRestOfString(Input i) { } else if (c == '\\') { i.backup(1); break; + } else if (c == '\n') { + l.noteNewline(); } } if ( c == EOF ){