This short guide describes how to execute a Spoofax plugin from the command-line.

1. Compile the project to a jar file

Spoofax compiles the core part of plugins either to a jar file or to a ctree file. If you want to invoke it from outside of Eclipse, it's easiest to work with a jar. The FAQ explains how to configure the project to achieve this: FAQ#jar.

2. Arrrange dependencies

After setting up the project, there are two core jar files for your project: include/yourlang.jar and include/yourlang-java.jar. They have a dependency on strategoxt.jar, which is included with Spoofax. It can be downloaded seperately from the STRJ home page or directly from hydra.nixos.org.

3. Write a main function

The next thing you need is a "main" function in the Spoofax plugin that is called when you invoke it from the command-line. You can add this to the yourlanguage.str file of your project. An example main function is shown below:

main-yourlanguage =
  xtc-input-wrap(
    // Read input
    ?FILE(input);
    prim("SSL_EXT_enable_origins");
    ast                             := <parse-yourlanguage-file> input;

    // Analyze
    (ast', errors, warnings, notes) := <editor-analyze> (ast, input, ".");
    // ...
    
    // Compile
    (output, contents)              := <generate-java> (ast', [], ast, input, ".");
    
    // Write to disk
    handle := <fopen> (output, "w");
    <fputs> (contents, handle);
    fclose
  <+
    // Report any errors
    prim("SSL_stacktrace_get_all_frame_names"); report-failure
  )

Be sure to replace yourlanguage with the name of your language in lowercase letters. The code above makes use of the libstratego-xtc library; make sure you add it to the imports.

4. Run the project

Run the project as follows:

java -cp include/yourlanguage.jar:include/yourlanguage-java:strategoxt.jar run main-yourlanguage

Revision: r1.1 - 11 Feb 2012 - 22:32 - LennartKats
Spoofax > CommandLine
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback