Skip to content
Snippets Groups Projects
Commit b857754e authored by Florian Angerer's avatar Florian Angerer
Browse files

Set URI und file name including line info if file option given.

parent 07cd8e48
No related branches found
No related tags found
No related merge requests found
......@@ -170,7 +170,14 @@ public class RCommand {
consoleHandler.setContext(context);
StartupTiming.timestamp("VM Created");
StartupTiming.printSummary();
return readEvalPrint(context, consoleHandler);
File srcFile = null;
String fileOption = options.getString(RCmdOption.FILE);
if (fileOption != null) {
srcFile = new File(fileOption);
}
return readEvalPrint(context, consoleHandler, srcFile);
}
}
......@@ -239,6 +246,10 @@ public class RCommand {
private static final Source GET_PROMPT = Source.newBuilder("R", ".Internal(getOption('prompt'))", "<prompt>").internal(true).buildLiteral();
private static final Source GET_CONTINUE_PROMPT = Source.newBuilder("R", ".Internal(getOption('continue'))", "<continue-prompt>").internal(true).buildLiteral();
public static int readEvalPrint(Context context, ConsoleHandler consoleHandler) {
return readEvalPrint(context, consoleHandler, null);
}
/**
* The read-eval-print loop, which can take input from a console, command line expression or a
* file. There are two ways the repl can terminate:
......@@ -249,8 +260,9 @@ public class RCommand {
* In case 2, we must implicitly execute a {@code quit("default, 0L, TRUE} command before
* exiting. So,in either case, we never return.
*/
public static int readEvalPrint(Context context, ConsoleHandler consoleHandler) {
public static int readEvalPrint(Context context, ConsoleHandler consoleHandler, File srcFile) {
int lastStatus = 0;
int line = 0;
try {
while (true) { // processing inputs
boolean doEcho = doEcho(context);
......@@ -260,6 +272,7 @@ public class RCommand {
if (input == null) {
throw new EOFException();
}
line++;
String trInput = input.trim();
if (trInput.equals("") || trInput.charAt(0) == '#') {
// nothing to parse
......@@ -271,7 +284,13 @@ public class RCommand {
while (true) { // processing subsequent lines while input is incomplete
lastStatus = 0;
try {
context.eval(Source.newBuilder("R", sb.toString(), "<REPL>").interactive(true).buildLiteral());
Source src;
if (srcFile != null) {
src = Source.newBuilder("R", sb.toString(), srcFile.getName() + "#" + line).interactive(true).uri(srcFile.toURI()).buildLiteral();
} else {
src = Source.newBuilder("R", sb.toString(), "<REPL>").interactive(true).buildLiteral();
}
context.eval(src);
} catch (PolyglotException e) {
if (continuePrompt == null) {
continuePrompt = doEcho ? getContinuePrompt(context) : null;
......
......@@ -22,6 +22,7 @@
*/
package com.oracle.truffle.r.launcher;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
......@@ -140,7 +141,8 @@ public class RscriptCommand {
try (Context context = Context.newBuilder().allowHostAccess(useJVM).options(polyglotOptions).arguments("R", arguments).in(consoleHandler.createInputStream()).out(outStream).err(
errStream).build()) {
consoleHandler.setContext(context);
return RCommand.readEvalPrint(context, consoleHandler);
String fileOption = options.getString(RCmdOption.FILE);
return RCommand.readEvalPrint(context, consoleHandler, new File(fileOption));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment