]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#745] extract_bnf can now support .md
authorTomek Mrugalski <tomek@isc.org>
Tue, 22 Jun 2021 13:23:17 +0000 (15:23 +0200)
committerTomek Mrugalski <tomek@isc.org>
Wed, 23 Jun 2021 10:04:18 +0000 (12:04 +0200)
tools/extract_bnf.sh.in

index d4f6c97a8653c9ee6eef1f92e709d34b97f99559..383283a438e0e104d168ef024f774f55625dede4 100755 (executable)
@@ -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