From: Tomek Mrugalski Date: Tue, 22 Jun 2021 13:23:17 +0000 (+0200) Subject: [#745] extract_bnf can now support .md X-Git-Tag: Kea-1.9.9~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1dbf1c82328c8ab4abe40207d807f83649d01fd7;p=thirdparty%2Fkea.git [#745] extract_bnf can now support .md --- 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 - will generate BNF notation in plain text +# +# Markdown: +# ./extract_bnf.sh --markdown -# Check if there is one argument only -if [ $# -ne 1 ]; then - echo "extract_bnf.sh " +# Check if there are one or two arguments +if [ $# -ne 1 ] && [ $# -ne 2 ]; then + echo "extract_bnf.sh [--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