#! /bin/sh -e

STRATEGO_DIR=
CZT="java -jar czt.jar"

if [ -e "$1" ]
then
  echo "Processing $1 ..."
else
  echo "File $1 doesn't exist.";
  exit
fi

example=${1%.*}

echo Parsing and typechecking example file using CZT
${CZT} -o $example.aterm $1

echo Transforming example
./tools/czt2alloy -i $example.aterm -o $example.alloy

echo Validating transformed example for debugging purposes
${STRATEGO_DIR}format-check --rtg syn/Zoy.rtg -i $example.alloy

echo Parenthesizing and printing
./built/parenthesize -i $example.alloy | ${STRATEGO_DIR}ast2abox -p built/Zoy.pp | ${STRATEGO_DIR}abox2text > $example.als

echo Output has been written fo file $example.als.