2

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.

josh
  • 1,544
  • 2
  • 16
  • 27

2 Answers2

4

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.

Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26
1

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.

ThomasH
  • 22,276
  • 13
  • 61
  • 62
  • 1
    if you start the REPL like you did in a directory where `META-INF/RASCAL.MF` can be found (also by moving up the directory tree), then the interpreter will configure itself with the right search paths. Caveat; you have to provide any libraries other than the stdlib on the JVM's classpath using `-cp`. So the `-jar` option won't work then. You need to pass the main class `org.rascalmpl.shell.RascalShell` along with the `-cp` classpath then. If you have a `mvn` project, this stuff is automated for you in the coming stable release using `mvn rascal:console`. – Jurgen Vinju Feb 10 '20 at 10:42
  • 1
    all this configuring of the interpreter is temporary until we finally switch to the compiled-mode of Rascal (which will still have the old REPL interface too), but from then on we will lift on the JVM's classpath w.r.t. distribution, linking and loading. – Jurgen Vinju Feb 10 '20 at 10:45