Skip to content

Commit 5c06f16

Browse files
committed
Implement RubySyntaxError#isExceptionIncompleteSource() for $ polyglot --shell
1 parent 1d8d56c commit 5c06f16

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/org/truffleruby/core/exception/RubySyntaxError.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.core.exception;
1111

1212
import org.truffleruby.core.klass.RubyClass;
13+
import org.truffleruby.language.RubyGuards;
1314
import org.truffleruby.language.backtrace.Backtrace;
1415

1516
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -20,6 +21,7 @@
2021
import com.oracle.truffle.api.library.ExportMessage;
2122
import com.oracle.truffle.api.object.Shape;
2223
import com.oracle.truffle.api.source.SourceSection;
24+
import org.truffleruby.language.library.RubyStringLibrary;
2325

2426
@ExportLibrary(InteropLibrary.class)
2527
public class RubySyntaxError extends RubyException {
@@ -44,9 +46,16 @@ public ExceptionType getExceptionType() {
4446
return ExceptionType.PARSE_ERROR;
4547
}
4648

49+
@TruffleBoundary
4750
@ExportMessage
4851
public boolean isExceptionIncompleteSource() {
49-
return false; // Unknown
52+
if (RubyStringLibrary.getUncached().isRubyString(message)) {
53+
String messageString = RubyGuards.getJavaString(message);
54+
return messageString.endsWith(" unexpected end-of-file") ||
55+
messageString.endsWith(" meets end of file");
56+
} else {
57+
return false;
58+
}
5059
}
5160

5261
@ExportMessage

0 commit comments

Comments
 (0)