]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#745] BNF notation can now be extracted
authorTomek Mrugalski <tomek@isc.org>
Mon, 21 Jun 2021 16:07:02 +0000 (18:07 +0200)
committerTomek Mrugalski <tomek@isc.org>
Wed, 23 Jun 2021 10:04:18 +0000 (12:04 +0200)
 - rebased to June 2021

configure.ac
tools/.gitignore
tools/extract_bnf.sh.in [new file with mode: 0755]

index 65efde9407dcf47b65a7729689fde4885f81d6e0..b590e0cd8635f7ce428127837754b648973da03f 100644 (file)
@@ -1927,6 +1927,9 @@ AC_CONFIG_FILES([src/share/yang/modules/Makefile])
 AC_CONFIG_FILES([tools/Makefile])
 AC_CONFIG_FILES([tools/path_replacer.sh],
                 [chmod +x tools/path_replacer.sh])
+AC_CONFIG_FILES([tools/extract_bnf.sh],
+                [chmod +x tools/extract_bnf.sh])
+
 
 AC_OUTPUT
 
index 02b2be3e95eef63a98e84aaafc25fd2254aee540..22040ce2d3a7ed0dafe2ebe6c0e14177685920bc 100644 (file)
@@ -1 +1,2 @@
+/extract_bnf.sh
 /path_replacer.sh
diff --git a/tools/extract_bnf.sh.in b/tools/extract_bnf.sh.in
new file mode 100755 (executable)
index 0000000..523f2ad
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Get BNF grammars from bison files
+
+# Check if there is one argument only
+if [ $# -ne 1]; then
+    echo "extract_bnf.sh <bison-file-base-name>"
+    exit 1
+fi
+
+# Get the output file
+base=$1
+output=
+
+if [ -f "${base}.output" ]; then
+    output="${base}.output"
+elif [ -f "${base}.yy" ]; then
+    @YACC@ -v "${base}.yy" -o output
+    rm -f output output.h *.hh
+    mv output.output /tmp/output
+    output=/tmp/output
+else
+    echo "cannot find ${base}.yy"
+    exit 1
+fi
+
+# Process the output file
+#  - extract the grammar part
+#  - remove line numbers
+#  - remove intermediate productions
+#  - remove intermediate non-terminals
+#  - squeeze multiple blank lines
+
+cat $output |\
+@AWK@ '/^Terminal/ { exit }; // { print }' |\
+@AWK@ '// { gsub("^ +[0-9]+ ", ""); print }' |\
+@AWK@ '/^\$@[0-9]+:/ { next }; // { print }' |\
+@AWK@ '// { gsub(" \\$@[0-9]+ ", " ") ; print }' |\
+cat -s