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 38f9cdc524a0b9f5edf2b7d81e6dba286ce9eb1e..a058b86051debe14e79acfd5306b94d49ad5916b 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 920e7100ae864646a8afa9054cb51aaf328275bb..b612947eda43f38e2abceae2556c11b0d781adef 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 b68f29703af3cd8971f6bab78b1da0d13c00efee..9f4562761fefaee3fadc06f56cb08e1c1cb54aa8 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)");