commit 0419693b04b930fc1f17127a29588e4401f63eb2
Author: Philippe PITTOLI
Date: Wed Jul 24 05:26:14 2019 +0200
initial commit: test grammars + tooling
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ca02e8d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+test-grammars/*.json
+test-grammars/*.dot
+test-grammars/*.pdf
+test-grammars/*.png
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..33023bb
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# recipies parser
+
+Parsing grammars requires the `pegasus` software: https://github.com/DanilaFe/pegasus
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..b5105cd
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,44 @@
+#/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 creating a dot file"
+${BINDIR}/pegasus-dot < "${tokenfile}.json" > "${tokenfile}.dot"
+# echo VAL RET $?
+on_error "cannot create the dot file"
+
+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"
diff --git a/test-grammars/graph-this.sh b/test-grammars/graph-this.sh
new file mode 100755
index 0000000..5752b68
--- /dev/null
+++ b/test-grammars/graph-this.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+if [ "$FONT" = "" ]
+then
+ FONT=/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf
+fi
+
+echo "font : $FONT"
+
+# $1 = program, $2 = filename extension
+function graphit()
+{
+ PROG=$1
+ FNEXT=$2
+ ls *.$FNEXT 2>/dev/null 1>&2
+ if [ $? -eq 0 ]; then
+ for i in *\.$FNEXT
+ do
+ PDF=$(echo ${i} | sed "s/$FNEXT$/pdf/")
+ if [ ! -f ${PDF} ] || [ $(stat -c "%X" ${PDF}) -lt $(stat -c "%X" ${i}) ]
+ then
+
+ PROGOPT="-Tpdf"
+ case $PROG in
+ "seqdiag" | "packetdiag" | "nwdiag")
+ PROGOPT="$PROGOPT -a -f $FONT"
+ echo ${PROG} ${PROGOPT} ${i}
+ ${PROG} ${PROGOPT} ${i}
+ ;;
+ "dot")
+ echo "${PROG} ${PROGOPT} ${i} > ${PDF}"
+ ${PROG} ${PROGOPT} ${i} > ${PDF}
+ ;;
+ esac
+
+ echo touch ${PDF}
+ touch ${PDF}
+ fi
+ done
+ fi
+}
+
+graphit "seqdiag" "diag"
+graphit "packetdiag" "pktdiag"
+graphit "nwdiag" "nwdiag"
+graphit "dot" "dot"
diff --git a/test-grammars/tokens b/test-grammars/tokens
new file mode 100644
index 0000000..a6b357d
--- /dev/null
+++ b/test-grammars/tokens
@@ -0,0 +1,11 @@
+token cr = /\n/;
+token eq = /=/;
+token space = /[ \t]+/;
+token recipiename = /@[a-zA-Z0-9\.\-]+/;
+token actionname = /(build|version|depends)/;
+token actionvalue = /"[a-zA-Z0-9 \-_]+"/;
+
+rule document = recipe cr document | recipe | cr;
+rule recipe = recipiename cr myrules;
+rule myrules = myrule cr myrules | cr;
+rule myrule = actionname eq actionvalue;
diff --git a/test-grammars/tokens.example b/test-grammars/tokens.example
new file mode 100644
index 0000000..bf8493e
--- /dev/null
+++ b/test-grammars/tokens.example
@@ -0,0 +1,4 @@
+@test1234
+build="the thing to do"
+version="1"
+depends="nothing"