From be2bb639757a723d44809678d0c21cd429a321cd Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 13 Jul 2012 14:32:22 +0200 Subject: [PATCH] ylwrap: rename header inclusion in generated parsers Some types of Bison parsers, such as the GLR ones, generate a header file that they include. ylwrap, which renames the generated files, does not rename the included file. Fix this shortcoming, reported for instance here: . Fixes t/yacc-bison-skeleton.sh, see Automake bug#7648 and PR automake/491. * lib/ylwrap (quote_for_sed): Accept arguments. Catch more special characters. (rename_sed): New. Improve the previous renaming sed commands using quote_for_sed. Suggested by Stefano Lattarini here: . (main loop): Use rename_sed to rename the dependencies to other files. * t/yacc-d-basic.sh: Exercise this case, even if bison/yacc was not issuing such an include. * t/list-of-tests.mk (XFAIL_TESTS): Adjust. --- lib/ylwrap | 19 +++++++++++++++---- t/list-of-tests.mk | 1 - t/yacc-d-basic.sh | 9 ++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/ylwrap b/lib/ylwrap index 8a9f2b0..8e02e9a 100755 --- a/lib/ylwrap +++ b/lib/ylwrap @@ -1,7 +1,7 @@ #! /bin/sh # ylwrap - wrapper for lex/yacc invocations. -scriptversion=2012-07-13.10; # UTC +scriptversion=2012-07-13.14; # UTC # Copyright (C) 1996-2012 Free Software Foundation, Inc. # @@ -48,10 +48,16 @@ guard() -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' } +# quote_for_sed [STRING] +# ---------------------- +# Return STRING (or stdin) quoted to be used as a sed pattern. quote_for_sed () { - # FIXME: really we should care about more than '.' and '\'. - sed -e 's,[\\.],\\&,g' + case $# in + 0) cat;; + 1) printf '%s\n' "$1";; + esac \ + | sed -e 's|[][\\.*]|\\&|g' } case "$1" in @@ -113,6 +119,10 @@ fi # The list of file to rename: FROM TO... pairlist= +# A sed program to s/FROM/TO/g for all the FROM/TO so that, for +# instance, we rename #include "y.tab.h" into #include "parse.h" +# during the conversion from y.tab.c to parse.c. +rename_sed= while test "$#" -ne 0; do if test "$1" = "--"; then shift @@ -130,6 +140,7 @@ while test "$#" -ne 0; do to=$1 shift pairlist="$pairlist $from $to" + rename_sed="${rename_sed}s|"`quote_for_sed "$from"`"|$to|g;" done # The program to run. @@ -196,7 +207,7 @@ if test $ret -eq 0; then FROM=`guard "$from"` TARGET=`guard "$to"` - sed -e "/^#/!b" -e "s,$input_rx,$input_sub_rx," -e "s,$from,$to," \ + sed -e "/^#/!b" -e "s,$input_rx,$input_sub_rx," -e "$rename_sed" \ -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$? # Check whether header files must be updated. diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk index 78d7d9b..9f0e123 100644 --- a/t/list-of-tests.mk +++ b/t/list-of-tests.mk @@ -31,7 +31,6 @@ t/pm/Version3.pl XFAIL_TESTS = \ t/all.sh \ t/yacc-bison-skeleton-cxx.sh \ -t/yacc-bison-skeleton.sh \ t/cond17.sh \ t/gcj6.sh \ t/override-conditional-2.sh \ diff --git a/t/yacc-d-basic.sh b/t/yacc-d-basic.sh index 91fbc62..72872f2 100755 --- a/t/yacc-d-basic.sh +++ b/t/yacc-d-basic.sh @@ -54,7 +54,14 @@ void yyerror (char *s) {} x : 'x' {}; %% END -cp foo/parse.y bar/parse.y +# Using ylwrap, we actually generate y.tab.[ch]. Unfortunately, we +# forgot to rename #include "y.tab.h" into #include "parse.h" during +# the conversion from y.tab.c to parse.c. This was OK when Bison was +# not issuing such an #include (up to 2.6). +# +# To make sure that we perform this conversion, in bar/parse.y, use +# y.tab.h instead of parse.c. +sed -e 's/parse\.h/y.tab.h/' bar/parse.y cat > foo/main.c << 'END' #include "parse.h" -- 2.7.4