Browse Source

feat: Add command-line compilation

This is performed using the sunshine executable jar, which must be
  separately downloaded, and a bash script in this project, called
  hel2py. Although the process is a bit cumbersome, it
  meets the original goals of this repository, so this will likely
  be the last commit.
Glen Whitney 1 year ago
  1. 4
  2. 29


@ -22,4 +22,6 @@ In the meantime, in case it's of use to me later or to anyone else, I will docum
1. Finally, we need the Editor SerVice to be able to see the generate-python strategy, so we have to include the python module in spoofax_helloworld.str, which seems to serve more or less as the Stratego main program for this language.
1. Now at this point (after building the project) we can visit a test.hel file, select Transform > Generate Python from the menu, and voila, is written alongside test.hel.
1. Executing `python3` from a shell shows that we are now actually able to produce valid greetings as specified by (any one of the four legal) helloworld language programs.
1. But now we'd actually like to be able to "compile" helloworld programs into python without firing up Eclipse, so...
1. But now we'd actually like to be able to "compile" helloworld programs into python without firing up Eclipse, so...
1. ...we create the hel2py script. To use this, you need to download the Spoofax sunshine executable jar, from Then there are a few environment variables that need to be set; these are explained in the output of `hel2py -h`. Once all is set up, you can use the command to translate a helloworld language file to Python, and execute it by piping the result to `python3 -`.
1. The end result isn't really very satisfactory for deploying a helloworld language "transpiler" to Python, as it requires an Eclipse installation which shouldn't really be necessary. But as it does minimally meet the stated goal of this repository, we'll wrap up efforts on the helloworld language here and move on to work on a more interesting language. It will be more worthwhile to investigate a streamlined packaging of a compiler when there's a language it might be worth compiling.


@ -0,0 +1,29 @@
while [[ $1 = -* ]]
case $1 in
echo "To use this script to 'compile' a helloworld program, you must set"
echo "environment variables:"
echo " SUNSHINE_JAR to the full path to the executable sunshine jar downloaded from Metaborg"
echo " ECLIPSE_INSTALL to the directory where your eclipse executable (with Spoofax plugin) resides"
echo " HELLOWORLD_PROJECT to the project directory of this project"
echo "(or of course you could make a copy of this script with those directories hardcoded)."
echo "Usage:"
echo " hel2py [-q] FILE"
echo "You can specify -q to suppress standard error output."
echo "Writes the Python translation of FILE to standard out."
echo "So you can 'execute' the file with"
echo " hel2py -q FILE | python3 -"
exec 2>/dev/null
java -jar $SUNSHINE_JAR transform -i $1 -n "Generate Python" -p $HELLOWORLD_PROJECT -l $HELLOWORLD_PROJECT -l "${ECLIPSE_INSTALL}/plugins"