summaryrefslogtreecommitdiffstats
path: root/tools/extract_bnf.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'tools/extract_bnf.sh.in')
-rwxr-xr-xtools/extract_bnf.sh.in32
1 files changed, 27 insertions, 5 deletions
diff --git a/tools/extract_bnf.sh.in b/tools/extract_bnf.sh.in
index d4f6c97a86..383283a438 100755
--- a/tools/extract_bnf.sh.in
+++ b/tools/extract_bnf.sh.in
@@ -7,13 +7,26 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Get BNF grammars from bison files
+#
+# This script takes 1 or 2 parameters:
+#
+# Basic usage:
+# ./extract_bnf.sh <bison-file-base-name> - will generate BNF notation in plain text
+#
+# Markdown:
+# ./extract_bnf.sh <bison-file-base-name> --markdown
-# Check if there is one argument only
-if [ $# -ne 1 ]; then
- echo "extract_bnf.sh <bison-file-base-name>"
+# Check if there are one or two arguments
+if [ $# -ne 1 ] && [ $# -ne 2 ]; then
+ echo "extract_bnf.sh <bison-file-base-name> [--markdown]"
exit 1
fi
+markdown=0
+if [ $# -eq 2 ] && [ "$2" = "--markdown" ]; then
+ markdown=1
+fi
+
# Get the output file
base=$1
output=
@@ -21,7 +34,7 @@ output=
if [ -f "${base}.output" ]; then
output="${base}.output"
elif [ -f "${base}.yy" ]; then
- @YACC@ -v "${base}.yy" -o output
+ /usr/bin/bison -v "${base}.yy" -o output
rm -f output output.h *.hh
mv output.output /tmp/output
output=/tmp/output
@@ -55,4 +68,13 @@ cat $output |\
@AWK@ '// { gsub("\"end of file\"", "EOF"); print }' |\
@AWK@ '// { gsub("%empty", ""); print }' |\
@AWK@ '// { gsub(": ", " ::= "); print }' |\
-cat -s
+cat -s > $output.2
+
+if [ "$markdown" -eq 1 ]; then
+ echo ".. code-block:: BNF" > $output.3
+ echo " :linenos:" >> $output.3
+ cat $output.2 | @AWK@ '/^.+$/ { print " ",$0 }; /^$/ { print } ' >> $output.3
+ cat $output.3
+else
+ cat $output.2
+fi