diff --git a/README.md b/README.md index 57333a3..27ee0f7 100644 --- a/README.md +++ b/README.md @@ -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, test.py is written alongside test.hel. 1. Executing `python3 test.py` 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... \ No newline at end of file +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 http://www.metaborg.org/en/latest/source/release/stable.html#command-line-utilities. 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. diff --git a/hel2py b/hel2py new file mode 100755 index 0000000..fda1d8f --- /dev/null +++ b/hel2py @@ -0,0 +1,29 @@ +#!/bin/bash +while [[ $1 = -* ]] +do + case $1 in + -h|--help) + echo + 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 + 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 -" + exit + ;; + -q) + shift + exec 2>/dev/null + ;; + esac +done + +java -jar $SUNSHINE_JAR transform -i $1 -n "Generate Python" -p $HELLOWORLD_PROJECT -l $HELLOWORLD_PROJECT -l "${ECLIPSE_INSTALL}/plugins"