[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ylwrap proposition & fix
From: |
Sergey Poznyakoff |
Subject: |
ylwrap proposition & fix |
Date: |
Fri, 08 Jun 2001 13:41:32 +0300 |
Hi!
I would propose to add an option to ylwrap specifying the replacement
sequence for yy prefix in identifiers. For example if you'd run:
sh ylwrap bison gram.y y.tab.c gram.c y.tab.h gram.h -- -yy foo_ -d
then all the yy.* identifiers in output files gram.c and gram.h would
become: foo_.*, so that yyparse would become foo_parse, etc. This
will simplify including multiple grammars in a program. The aproach
seems to be more convenient than `#define yyparse c_parse' approach
proposed by automake.info. Of course the same functionality can
be achieved by -p option to bison, but some yaccs don't understand
it ...
The patch below implements this and also fixes an inconsistency in
handling `#line ' statements, due to which `#line 54 "/src/gram.y'
became `#line 54 "/gram.y"' (leading slash confuses gdb).
Regards,
Sergey Poznyakoff
Index: ylwrap
===================================================================
RCS file: /cvs/automake/lib/ylwrap,v
retrieving revision 1.16
diff -p -u -w -b -r1.16 ylwrap
--- ylwrap 2001/05/15 03:33:20 1.16
+++ ylwrap 2001/06/08 10:19:37
@@ -18,12 +18,13 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Usage:
-# ylwrap PROGRAM [ARGS] INPUT [OUTPUT DESIRED]... -- [ARGS]...
+# ylwrap PROGRAM [ARGS] INPUT [OUTPUT DESIRED]... -- [-yy repl] [ARGS]...
# * PROGRAM is program to run; options can follow but must start with `-'.
# * INPUT is the input file
# * OUTPUT is file PROG generates
# * DESIRED is file we actually want
# * ARGS are passed to PROG
+# * Optional -yy introduces the sequence to replace yy prefixes with.
# Any number of OUTPUT,DESIRED pairs may be used.
# The program to run.
@@ -81,6 +82,18 @@ while test "$#" -ne 0; do
shift
done
+if [ $# -ne 0 ]; then
+ if [ "x$1" = "x-yy" ]; then
+ shift
+ if [ $# -eq 0 ]; then
+ echo "ylwrap: -yy requires an argument"
+ exit 1
+ fi
+ YYREPL=$1
+ shift
+ fi
+fi
+
# FIXME: add hostname here for parallel makes that run commands on
# other machines. But that might take us over the 14-char limit.
dirname=ylwrap$$
@@ -128,7 +141,11 @@ if test $status -eq 0; then
# resulting debug information to point at an absolute srcdir;
# it is better for it to just mention the .y file with no
# path.
- sed -e "/^#/ s,$input_rx,," "$from" > "$target" || status=$?
+ EXPR="/^#/ s,$input_rx/,,"
+ if [ ! -z "$YYREPL" ]; then
+ EXPR="$EXPR;s/yy/$YYREPL/g"
+ fi
+ sed -e "$EXPR" "$from" > "$target" || status=$?
else
# A missing file is only an error for the first file. This
# is a blatant hack to let us support using "yacc -d". If -d
- ylwrap proposition & fix,
Sergey Poznyakoff <=