diff options
author | Tomek Mrugalski <tomek@isc.org> | 2021-06-21 18:07:02 +0200 |
---|---|---|
committer | Tomek Mrugalski <tomek@isc.org> | 2021-06-23 12:04:18 +0200 |
commit | 54b02254cac37862caa2ba1817f6646f97ee79eb (patch) | |
tree | 66d642cd46f290f2e55f651903dcdea26f3681f1 /tools/extract_bnf.sh.in | |
parent | [#1653] add ChangeLog entry (diff) | |
download | kea-54b02254cac37862caa2ba1817f6646f97ee79eb.tar.xz kea-54b02254cac37862caa2ba1817f6646f97ee79eb.zip |
[#745] BNF notation can now be extracted
- rebased to June 2021
Diffstat (limited to 'tools/extract_bnf.sh.in')
-rwxr-xr-x | tools/extract_bnf.sh.in | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/extract_bnf.sh.in b/tools/extract_bnf.sh.in new file mode 100755 index 0000000000..523f2ada6b --- /dev/null +++ b/tools/extract_bnf.sh.in @@ -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 |