aboutsummaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-15 13:51:03 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-15 14:05:39 +0300
commita0826b4c7cd66c4862d9b61bb7e14d73fcba28f6 (patch)
tree71762fca263967e5803ce803b0a0aa94555e125d /build-aux
parentfd64fa62bc68d8c2e0d693033e874fcc1f023544 (diff)
downloadgrecs-a0826b4c7cd66c4862d9b61bb7e14d73fcba28f6.tar.gz
grecs-a0826b4c7cd66c4862d9b61bb7e14d73fcba28f6.tar.bz2
Provide a framework for multiple parsers. Implement meta1 parser.
* Makefile.am (EXTRA_DIST): Add build-aux/yyrename * am/grecs.m4: New options: parser-meta1 and all-parsers * src/.gitignore: Update. * src/Make.am [GRECS_COND_META1_PARSER]: Set GRECS_PARSER_META1 and GRECS_EXTRA_META1 (GRECS_SRC): Add new files. (EXTRA_DIST): Add GRECS_EXTRA_META1. (LEXCOMPILE,YACCCOMPILE): Redefine * src/grecs-gram.y: Don't include yygrecs.h (grecs_vasprintf,grecs_asprintf): Move to a separate file. (grecs_parse): Rename to grecs_grecs_parser. Actual grecs_parse is defined in parser.c (grecs_gram_trace): Move to parser.c * src/grecs-lex.l: Don't include yygrecs.h Use line_acc functions. * src/grecs.h (grecs_trace_flags): New extern. (GRECS_TRACE_GRAM, GRECS_TRACE_LEX): New flags. (grecs_lex_begin): Change signature. (grecs_grecs_parser,grecs_meta1_parser): New protos. (grecs_line_acc_create) (grecs_line_acc_free,grecs_line_acc_grow_char) (grecs_line_acc_grow_char_unescape) (grecs_line_acc_grow) (grecs_line_acc_grow_unescape_last): New protos. (GRECS_TXTACC_BUFSIZE): New const (grecs_txtacc_create,grecs_txtacc_free) (grecs_txtacc_grow,grecs_txtacc_finish) (grecs_txtacc_free_string): New protos. (grecs_value_match): New proto. * src/wordsplit.c (quote_transtab): Translate \" * src/yygrecs.h: Remove. * src/yytrans: New file. * build-aux/yyrename: New file. * src/asprintf.c: New file. * src/lineacc.c: New file. * src/meta1-gram.y: New file. * src/meta1-lex.l: New file. * src/parser.c: New file. * src/txtacc.c: New file. * doc/grecs_parse.3: Update. * doc/GRECS_SETUP.3: Update.
Diffstat (limited to 'build-aux')
-rwxr-xr-xbuild-aux/yyrename92
1 files changed, 92 insertions, 0 deletions
diff --git a/build-aux/yyrename b/build-aux/yyrename
new file mode 100755
index 0000000..5e7b1db
--- /dev/null
+++ b/build-aux/yyrename
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Rename yy.* identifiers to avoid name clashes. This file is part of Grecs.
+# Copyright (C) 2011 Sergey Poznyakoff
+#
+# Grecs is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Grecs is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+# Usage: yyrename [-f OUTFILE [OUTFILE...]] COMMAND INFILE
+# Makefile.am:
+# LEXCOMPILE = yyrename -f $(LEX_OUTPUT_ROOT).c \
+# '$(LEX) $(LFLAGS) $(AM_LFLAGS)'
+# YACCCOMPILE = yyrename '$(YACC) $(YFLAGS) $(AM_YFLAGS)'
+#
+# This script runs COMMAND with INFILE as its argument and scans
+# OUTFILEs for identifiers starting with 'yy'. These identifiers
+# are renamed by replacing 'yy' with the selected prefix.
+#
+# The prefix is looked up in the file yytrans, located in the INFILE's
+# directory. If this file does not exist, the prefix is constructed
+# by concatenating the string 'grecs_' and the ``root name''. The root
+# name is build by removing '-lex.l' or '-gram.y' from the base name.
+# If the latter does not end in any of these, the root name
+# is constructed by removing the suffix from the base name.
+#
+# The yytrans file is a line-oriented lookup table. Empty lines are
+# ignored, usual UNIX comment lines are honored. The remaining lines
+# must consist of two words separated by any amount of whitespace.
+# The first word is a look-up key, the second one provides a translation
+# (yy replacement) for that key.
+#
+# Two look-ups are tried: first the base name and then the root name.
+# If both result in a non-empty replacement, the former is preferred
+# over the latter.
+#
+# The -f option supplies a list of output file names generated by COMMAND.
+# If not supplied, the following defaults are used: y.tab.c and y.tab.h, if
+# INFILE ends in '.y', and yy.lex.c, if it ends in '.l'. If INFILE does not
+# end in any of these suffixes, error is reported.
+#
+# BUGS: Any occurrence of 'yy' is replaced, not only 'yy' prefixes.
+#
+case $1 in
+-f) files=$2
+ shift
+ shift
+esac
+
+base=`expr "$2" : '.*/\(.*\)\.[ly]'`
+dir=`dirname "$2"`
+case $2 in
+*.y) test -z "$files" && files="y.tab.c y.tab.h"
+ root=`expr "$2" : '.*/\(.*\)-gram\.y'`;;
+*.l) test -z "$files" && files=lex.yy.c
+ root=`expr "$2" : '.*/\(.*\)-lex\.l'`;;
+*) if test -z "$files"; then
+ echo >&2 "$0: suffix unknown, files must be given (use -f)"
+ exit 1
+ fi
+ root=$base
+esac
+
+if test -f $dir/yytrans; then
+ pfx=`awk '
+{ sub(/#.*$/,"") }
+NF == 2 && $1=="'$base'" { exact=$2 }
+NF == 2 && $1=="'$root'" { root=$2 }
+{ next }
+END { print exact ? exact : root ? root : "" }' $dir/yytrans`
+else
+ pfx=
+fi
+if test -z "$pfx"; then
+ pfx=grecs_`echo $root | tr .- __`
+fi
+
+eval $* || exit $?
+
+for file in $files
+do
+ mv $file ${file}.tmp
+ sed "s/yy/$pfx/g" ${file}.tmp > $file
+done

Return to:

Send suggestions and report system problems to the System administrator.