Skip to content

Instantly share code, notes, and snippets.

@benjaminparnell
Created December 10, 2013 20:39
Show Gist options
  • Save benjaminparnell/7898624 to your computer and use it in GitHub Desktop.
Save benjaminparnell/7898624 to your computer and use it in GitHub Desktop.
ANTLR_PATH=/usr/local/Cellar/antlr/4.2/antlr-4.2-complete.jar
TARGET=pdl
FILE=$1
green="$(tput setaf 2)"
red="$(tput setaf 1)"
magenta="$(tput setaf 5)"
reset="$(tput setaf 7)"
tick="\xE2\x9C\x93"
cross="\xE2\x9C\x98"
echo "\nGenerating into /${magenta}"$TARGET"${reset}"
java -jar $ANTLR_PATH -o $TARGET $TARGET.g4
echo "Compiling using /${magenta}"$TARGET"${reset}"
javac -Xlint:unchecked -cp $ANTLR_PATH $TARGET/*.java
if [ ! -z "$FILE" ] ; then
echo "\nRunning test harness on "$1"...\n"
if [ -f ./$FILE ] ; then
if java -cp $ANTLR_PATH:. org.antlr.v4.runtime.misc.TestRig $TARGET.$TARGET program -tree $FILE; then
echo "\n${green}Finished with with no errors ${tick}${reset}\n"
else
echo "\n${red}"$1" failed the TestRig ${cross}${reset}\n"
exit
fi
else
echo "File "$FILE" not found in current directory.\n"
fi
else
echo "\nNo argument supplied, no tests running."
fi
echo "\nBuilding sample.pdl into sample.js..."
if java pdl.pdl samples.pdl > sample.js && js-beautify -r sample.js; then
echo "\n${green}Finished ${tick}"
else
echo "\n${red}Failed ${cross}"
fi
echo "${reset}\nDone.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment