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.
This commit is contained in:
parent
cd5f02603b
commit
04ad85ee38
@ -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. 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. 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. 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...
|
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.
|
||||||
|
29
hel2py
Executable file
29
hel2py
Executable file
@ -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"
|
Loading…
Reference in New Issue
Block a user