3
0
Fork 0
This repository has been archived on 2022-01-17. You can view files and clone it, but cannot push or open issues/pull-requests.
recipes-parser/build.sh

45 lines
901 B
Bash
Executable File

#/bin/sh
BINDIR=../pegasus/bin/
tokenfile=$1
TMPERRORFILE="/tmp/TMPERRORFILE$$"
on_error()
{
if [ $? -ne 0 ]; then
err=$1
echo $err
cat ${TMPERRORFILE}
rm ${TMPERRORFILE}
exit 1
fi
val=`wc -l ${TMPERRORFILE} | cut -d ' ' -f 1`
if [ ${val} -ne 0 ]; then
echo $err
cat ${TMPERRORFILE}
rm ${TMPERRORFILE}
exit 1
fi
}
if [ $# -eq 0 ]
then
echo "usage $0 token-and-rules-file"
exit 1
fi
echo "pegasus reading the grammar"
${BINDIR}/pegasus < "${tokenfile}" > "${tokenfile}.json" 2>${TMPERRORFILE}
on_error "cannot read the grammar"
echo "pegasus trying an example on the generated parser"
cat "${tokenfile}.example" | ${BINDIR}/pegasus-sim -i "${tokenfile}.json"
# echo VAL RET $?
on_error "cannot parse the example"
echo "pegasus creating a dot file"
${BINDIR}/pegasus-dot < "${tokenfile}.json" > "${tokenfile}.dot"
# echo VAL RET $?
on_error "cannot create the dot file"