josh
josh

Reputation: 1554

Running a Rascal program from outside the REPL

I'd really like to be able to run some Rascal's program from outside the REPL (e.g. as part of a script, or called from another program). What I'm using Rascal for is and intermediate stage in a larger framework so I am wondering what the best way to go about integrating executing the Rascal code from another program.

Upvotes: 2

Views: 397

Answers (2)

ThomasH
ThomasH

Reputation: 23516

As I was pondering the same question, this is the (maybe trivial) answer I came up with:

java -jar /path/to/rascal-shell-stable.jar path/to/myProgram.rsc

You have to be aware that Rascal calculates module names from the current directory (don't know if it supports something like Java's CLASS_PATH), so in the above example myProgram.rsc should have a module declaration of module path::to::myProgram. Calculated and declared module name have to match.

Upvotes: 1

Jurgen Vinju
Jurgen Vinju

Reputation: 6696

Right now the best way is to package your code together with the Rascal shell executable jar. There is a convenience class JavaToRascal for calling into Rascal code. Sometimes it requires some thinking to add your own modules to the Rascal search path using IRascalSearchPathContributors, but if you include a RASCAL.MF file with the right properties it all should go automatically.

If you are thinking of an Eclipse plugin, then the best way is to let your plugin depend on the rascal-eclipse plugin and use ProjectEvaluatorFactory to get access to the interpreter.

Caveat: since we are moving to a compiled system, the code you write for this kind of integration will change. This is the reason we haven't documented the API for calling Rascal from Java yet.

Upvotes: 4

Related Questions