Skip to content
Snippets Groups Projects
Commit 8f6e70b2 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

[GR-3608] Handle newlines in string literals.

parents 7d928644 16724895
Branches
No related tags found
No related merge requests found
......@@ -90,7 +90,7 @@ public class DefaultRParserFactory extends RParserFactory {
String line = e.line <= source.getLineCount() ? source.getCode(e.line) : "";
String substring = line.substring(0, Math.min(line.length(), e.charPositionInLine + 1));
String token = e.token == null ? (substring.length() == 0 ? "" : substring.substring(substring.length() - 1)) : e.token.getText();
if (e.token != null && e.token.getType() == Token.EOF && (e instanceof NoViableAltException || e instanceof MismatchedTokenException)) {
if (e.getUnexpectedType() == Token.EOF && (e instanceof NoViableAltException || e instanceof MismatchedTokenException)) {
// the parser got stuck at the eof, request another line
throw new IncompleteSourceException(e, source, token, substring, e.line);
} else {
......
......@@ -144093,6 +144093,18 @@ Error: unexpected input in "%0"
#10^2^2
[1] 10000
 
##com.oracle.truffle.r.test.parser.TestParser.testNewLinesInLiterals#
#"foo<<<NEWLINE>>>baraz"
[1] "foo\nbar\baz"
##com.oracle.truffle.r.test.parser.TestParser.testNewLinesInLiterals#
#'foo<<<NEWLINE>>>baraz'
[1] "foo\nbar\baz"
##com.oracle.truffle.r.test.parser.TestParser.testNewLinesInLiterals#
#`asdf<<<NEWLINE>>>asdf` <- 1; `asdf<<<NEWLINE>>>asdf`
[1] 1
##com.oracle.truffle.r.test.parser.TestParser.testNewLinesNesting#Output.IgnoreErrorMessage#
#a <- 1:100; y <- 2; z <- 5; x <- (a[[{y <<<NEWLINE>>> * z}]])
Error: unexpected '*' in:
......@@ -105,6 +105,13 @@ public class TestParser extends TestBase {
assertEval(Output.IgnoreErrorMessage, "a <- 1:100; y <- 2; z <- 5; x <- (a[[{y \n * z}]])");
}
@Test
public void testNewLinesInLiterals() {
assertEval("`asdf\nasdf` <- 1; `asdf\nasdf`");
assertEval("'foo\nbar\baz'");
assertEval("\"foo\nbar\baz\"");
}
@Test
public void testEmptySymbols() {
assertEval("names(e)");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment