Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/org/rascalmpl/debug/DebugHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.function.IntSupplier;

import org.rascalmpl.ast.AbstractAST;
import org.rascalmpl.ast.Command;
import org.rascalmpl.debug.IDebugMessage.Detail;
import org.rascalmpl.interpreter.Evaluator;
import org.rascalmpl.interpreter.control_exceptions.InterruptException;
Expand All @@ -32,17 +33,29 @@
import org.rascalmpl.repl.output.ICommandOutput;
import org.rascalmpl.repl.rascal.RascalValuePrinter;
import org.rascalmpl.values.functions.IFunction;
import org.rascalmpl.values.parsetrees.ITree;

import java.util.function.Function;
import org.rascalmpl.exceptions.RascalStackOverflowError;
import org.rascalmpl.interpreter.staticErrors.StaticError;
import org.rascalmpl.exceptions.Throw;
import org.rascalmpl.parser.ASTBuilder;
import org.rascalmpl.parser.Parser;
import org.rascalmpl.parser.gtd.exception.ParseError;
import org.rascalmpl.parser.gtd.result.action.IActionExecutor;
import org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener;
import org.rascalmpl.parser.gtd.result.out.INodeFlattener;
import org.rascalmpl.parser.uptr.UPTRNodeFactory;
import org.rascalmpl.parser.uptr.action.NoActionExecutor;
import org.rascalmpl.interpreter.utils.ReadEvalPrintDialogMessages;
import org.rascalmpl.library.lang.rascal.syntax.RascalParser;

import io.usethesource.vallang.io.StandardTextWriter;
import java.io.StringWriter;
import java.io.PrintWriter;
import org.rascalmpl.repl.output.impl.PrinterErrorCommandOutput;

import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.ISourceLocation;
import org.rascalmpl.uri.URIUtil;
import io.usethesource.vallang.IValue;
Expand Down Expand Up @@ -309,6 +322,20 @@ public void setEvaluator(Evaluator evaluator) {
this.evaluator = evaluator;
}

public Result<IValue> importModule(String command){
IActionExecutor<ITree> actionExecutor = new NoActionExecutor();
ITree tree = new RascalParser().parse(Parser.START_COMMAND, DEBUGGER_PROMPT_LOCATION.getURI(), command.toCharArray(), INodeFlattener.UNLIMITED_AMB_DEPTH, actionExecutor, new DefaultNodeFlattener<IConstructor, ITree, ISourceLocation>(), new UPTRNodeFactory(false));
Command stat = new ASTBuilder().buildCommand(tree);
if (!stat.isImport()) {
return null;
}
Environment oldEnvironment = evaluator.getCurrentEnvt();
evaluator.setCurrentEnvt(evaluator.__getRootScope()); // For import we set the current module to the root to reload modules properly
Result<IValue> result = evaluator.eval(evaluator.getMonitor(), command, DEBUGGER_PROMPT_LOCATION);
evaluator.setCurrentEnvt(oldEnvironment);
return result;
Comment on lines +326 to +336
Copy link
Member

@DavyLandman DavyLandman Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure that ParseError exceptions are caught, so that if something is not a command, it doesn't bubble up as an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is called inside the evaluate function that catch and display nicely ParseErrror, this is already the case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was: now the following if body (that does evaluator.eval(...)) will never run. Which will most likely not happen, as it also parses the string in the same way. lets add a comment or something? it smells a bit fishy that we just assume line 327 is the same parse as the one inside Evaluator::eval

}

/**
* Evaluate the given command in the provided environment and return both a
* printable {@link ICommandOutput} and the raw {@link Result} (if any).
Expand Down Expand Up @@ -343,8 +370,10 @@ protected Function<IValue, IValue> liftProviderFunction(IFunction func) {
evaluator.removeSuspendTriggerListener(this);
evaluator.setEventTrigger(AbstractInterpreterEventTrigger.newNullEventTrigger());
evaluator.setCurrentEnvt(evalEnv);

Result<IValue> result = evaluator.eval(evaluator.getMonitor(), command, DEBUGGER_PROMPT_LOCATION);
Result<IValue> result = importModule(command);
if(result == null) {
result = evaluator.eval(evaluator.getMonitor(), command, DEBUGGER_PROMPT_LOCATION);
}

ICommandOutput out = printer.outputResult((org.rascalmpl.interpreter.result.IRascalResult) result);
return new EvalResult(result, out);
Expand Down
Loading