Skip to content

Commit

Permalink
Merge pull request #26 from felixvf/fix_bug_mirah-parser_25
Browse files Browse the repository at this point in the history
Fix bug #25.
  • Loading branch information
felixvf committed Jul 21, 2015
2 parents 7a1fd3a + a900c10 commit 95dfce8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/mirahparser/impl/MirahLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -248,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) {
Expand Down Expand Up @@ -284,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)) {
Expand All @@ -301,6 +311,8 @@ private void readRestOfString(Input i) {
} else if (c == '\\') {
i.backup(1);
break;
} else if (c == '\n') {
l.noteNewline();
}
}
if ( c == EOF ){
Expand Down
20 changes: 20 additions & 0 deletions test/test_mirah.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 95dfce8

Please sign in to comment.