From 167248957647b7fc5707afbc3d184a97f75a70eb Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Tue, 11 Apr 2017 11:49:50 +0200 Subject: [PATCH] handle newlines in string literals --- .../truffle/r/parser/DefaultRParserFactory.java | 2 +- .../oracle/truffle/r/test/ExpectedTestOutput.test | 12 ++++++++++++ .../com/oracle/truffle/r/test/parser/TestParser.java | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/DefaultRParserFactory.java b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/DefaultRParserFactory.java index 38f9cdc524..a058b86051 100644 --- a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/DefaultRParserFactory.java +++ b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/DefaultRParserFactory.java @@ -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 { diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 920e7100ae..b612947eda 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -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: diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/parser/TestParser.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/parser/TestParser.java index b68f29703a..9f4562761f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/parser/TestParser.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/parser/TestParser.java @@ -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)"); -- GitLab