diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-15 13:51:03 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-15 14:05:39 +0300 |
commit | a0826b4c7cd66c4862d9b61bb7e14d73fcba28f6 (patch) | |
tree | 71762fca263967e5803ce803b0a0aa94555e125d | |
parent | fd64fa62bc68d8c2e0d693033e874fcc1f023544 (diff) | |
download | grecs-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.
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | am/grecs.m4 | 7 | ||||
-rwxr-xr-x | build-aux/yyrename | 92 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | doc/GRECS_SETUP.3 | 8 | ||||
-rw-r--r-- | doc/grecs_parse.3 | 8 | ||||
-rw-r--r-- | src/.gitignore | 4 | ||||
-rw-r--r-- | src/Make.am | 19 | ||||
-rw-r--r-- | src/asprintf.c | 85 | ||||
-rw-r--r-- | src/grecs-gram.y | 80 | ||||
-rw-r--r-- | src/grecs-lex.l | 133 | ||||
-rw-r--r-- | src/grecs.h | 35 | ||||
-rw-r--r-- | src/lineacc.c | 82 | ||||
-rw-r--r-- | src/meta1-gram.y | 217 | ||||
-rw-r--r-- | src/meta1-lex.l | 114 | ||||
-rw-r--r-- | src/parser.c | 60 | ||||
-rw-r--r-- | src/txtacc.c | 187 | ||||
-rw-r--r-- | src/wordsplit.c | 2 | ||||
-rw-r--r-- | src/yygrecs.h | 28 | ||||
-rw-r--r-- | src/yytrans | 20 |
20 files changed, 944 insertions, 241 deletions
diff --git a/Makefile.am b/Makefile.am index d614a25..0696c72 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | ACLOCAL_AMFLAGS = -I am | 17 | ACLOCAL_AMFLAGS = -I am |
18 | SUBDIRS=. src @GRECS_TESTDIR@ @GRECS_DOCDIR@ | 18 | SUBDIRS=. src @GRECS_TESTDIR@ @GRECS_DOCDIR@ |
19 | EXTRA_DIST=@GRECS_BUILD_AUX@ gitid.h | 19 | EXTRA_DIST=build-aux/yyrename @GRECS_BUILD_AUX@ gitid.h |
20 | 20 | ||
21 | noinst_HEADERS = gitid.h | 21 | noinst_HEADERS = gitid.h |
22 | BUILT_SOURCES = gitid.h README | 22 | BUILT_SOURCES = gitid.h README |
diff --git a/am/grecs.m4 b/am/grecs.m4 index 0d1b03d..8f4868b 100644 --- a/am/grecs.m4 +++ b/am/grecs.m4 | |||
@@ -148,7 +148,11 @@ AC_DEFUN([GRECS_SETUP],[ | |||
148 | GRECS_BUILD_AUX="build-aux/getopt.m4" | 148 | GRECS_BUILD_AUX="build-aux/getopt.m4" |
149 | ]) | 149 | ]) |
150 | _GRECS_IF_OPTION_SET([git2chg],[GRECS_BUILD_AUX="$GRECS_BUILD_AUX build-aux/git2chg.awk"]) | 150 | _GRECS_IF_OPTION_SET([git2chg],[GRECS_BUILD_AUX="$GRECS_BUILD_AUX build-aux/git2chg.awk"]) |
151 | 151 | AM_CONDITIONAL([GRECS_COND_META1_PARSER], | |
152 | _GRECS_OPTION_SWITCH([parser-meta1],[true], | ||
153 | [all-parsers],[true], | ||
154 | [false])) | ||
155 | |||
152 | AC_SUBST([GRECS_SRCDIR],$1) | 156 | AC_SUBST([GRECS_SRCDIR],$1) |
153 | AC_SUBST([GRECS_BUILD_AUX]) | 157 | AC_SUBST([GRECS_BUILD_AUX]) |
154 | AC_SUBST([GRECS_INCLUDES]) | 158 | AC_SUBST([GRECS_INCLUDES]) |
@@ -160,6 +164,7 @@ AC_DEFUN([GRECS_SETUP],[ | |||
160 | AC_SUBST([GRECS_README]) | 164 | AC_SUBST([GRECS_README]) |
161 | AC_SUBST([GRECS_INCLUDES],['-I$(top_srcdir)/]grecsdir[src]') | 165 | AC_SUBST([GRECS_INCLUDES],['-I$(top_srcdir)/]grecsdir[src]') |
162 | AC_SUBST([GRECS_HOST_PROJECT_INCLUDES]) | 166 | AC_SUBST([GRECS_HOST_PROJECT_INCLUDES]) |
167 | |||
163 | _GRECS_OPTION_SWITCH([install],[ | 168 | _GRECS_OPTION_SWITCH([install],[ |
164 | LT_INIT | 169 | LT_INIT |
165 | GRECS_LDADD=['$(top_builddir)/]grecsdir[src/libgrecs.la'] | 170 | GRECS_LDADD=['$(top_builddir)/]grecsdir[src/libgrecs.la'] |
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 @@ | |||
1 | #! /bin/sh | ||
2 | # Rename yy.* identifiers to avoid name clashes. This file is part of Grecs. | ||
3 | # Copyright (C) 2011 Sergey Poznyakoff | ||
4 | # | ||
5 | # Grecs is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published by | ||
7 | # the Free Software Foundation; either version 3, or (at your option) | ||
8 | # any later version. | ||
9 | # | ||
10 | # Grecs is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | # GNU General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with Grecs. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | # Usage: yyrename [-f OUTFILE [OUTFILE...]] COMMAND INFILE | ||
19 | # Makefile.am: | ||
20 | # LEXCOMPILE = yyrename -f $(LEX_OUTPUT_ROOT).c \ | ||
21 | # '$(LEX) $(LFLAGS) $(AM_LFLAGS)' | ||
22 | # YACCCOMPILE = yyrename '$(YACC) $(YFLAGS) $(AM_YFLAGS)' | ||
23 | # | ||
24 | # This script runs COMMAND with INFILE as its argument and scans | ||
25 | # OUTFILEs for identifiers starting with 'yy'. These identifiers | ||
26 | # are renamed by replacing 'yy' with the selected prefix. | ||
27 | # | ||
28 | # The prefix is looked up in the file yytrans, located in the INFILE's | ||
29 | # directory. If this file does not exist, the prefix is constructed | ||
30 | # by concatenating the string 'grecs_' and the ``root name''. The root | ||
31 | # name is build by removing '-lex.l' or '-gram.y' from the base name. | ||
32 | # If the latter does not end in any of these, the root name | ||
33 | # is constructed by removing the suffix from the base name. | ||
34 | # | ||
35 | # The yytrans file is a line-oriented lookup table. Empty lines are | ||
36 | # ignored, usual UNIX comment lines are honored. The remaining lines | ||
37 | # must consist of two words separated by any amount of whitespace. | ||
38 | # The first word is a look-up key, the second one provides a translation | ||
39 | # (yy replacement) for that key. | ||
40 | # | ||
41 | # Two look-ups are tried: first the base name and then the root name. | ||
42 | # If both result in a non-empty replacement, the former is preferred | ||
43 | # over the latter. | ||
44 | # | ||
45 | # The -f option supplies a list of output file names generated by COMMAND. | ||
46 | # If not supplied, the following defaults are used: y.tab.c and y.tab.h, if | ||
47 | # INFILE ends in '.y', and yy.lex.c, if it ends in '.l'. If INFILE does not | ||
48 | # end in any of these suffixes, error is reported. | ||
49 | # | ||
50 | # BUGS: Any occurrence of 'yy' is replaced, not only 'yy' prefixes. | ||
51 | # | ||
52 | case $1 in | ||
53 | -f) files=$2 | ||
54 | shift | ||
55 | shift | ||
56 | esac | ||
57 | |||
58 | base=`expr "$2" : '.*/\(.*\)\.[ly]'` | ||
59 | dir=`dirname "$2"` | ||
60 | case $2 in | ||
61 | *.y) test -z "$files" && files="y.tab.c y.tab.h" | ||
62 | root=`expr "$2" : '.*/\(.*\)-gram\.y'`;; | ||
63 | *.l) test -z "$files" && files=lex.yy.c | ||
64 | root=`expr "$2" : '.*/\(.*\)-lex\.l'`;; | ||
65 | *) if test -z "$files"; then | ||
66 | echo >&2 "$0: suffix unknown, files must be given (use -f)" | ||
67 | exit 1 | ||
68 | fi | ||
69 | root=$base | ||
70 | esac | ||
71 | |||
72 | if test -f $dir/yytrans; then | ||
73 | pfx=`awk ' | ||
74 | { sub(/#.*$/,"") } | ||
75 | NF == 2 && $1=="'$base'" { exact=$2 } | ||
76 | NF == 2 && $1=="'$root'" { root=$2 } | ||
77 | { next } | ||
78 | END { print exact ? exact : root ? root : "" }' $dir/yytrans` | ||
79 | else | ||
80 | pfx= | ||
81 | fi | ||
82 | if test -z "$pfx"; then | ||
83 | pfx=grecs_`echo $root | tr .- __` | ||
84 | fi | ||
85 | |||
86 | eval $* || exit $? | ||
87 | |||
88 | for file in $files | ||
89 | do | ||
90 | mv $file ${file}.tmp | ||
91 | sed "s/yy/$pfx/g" ${file}.tmp > $file | ||
92 | done | ||
diff --git a/configure.ac b/configure.ac index 980c713..816de11 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -37,6 +37,6 @@ AC_HEADER_STDC | |||
37 | 37 | ||
38 | # Grecs subsystem | 38 | # Grecs subsystem |
39 | 39 | ||
40 | GRECS_SETUP(., [install tests git2chg]) | 40 | GRECS_SETUP(., [install tests git2chg all-parsers]) |
41 | 41 | ||
42 | AC_OUTPUT | 42 | AC_OUTPUT |
diff --git a/doc/GRECS_SETUP.3 b/doc/GRECS_SETUP.3 index c24399e..13b568e 100644 --- a/doc/GRECS_SETUP.3 +++ b/doc/GRECS_SETUP.3 | |||
@@ -14,7 +14,7 @@ | |||
14 | .\" You should have received a copy of the GNU General Public License | 14 | .\" You should have received a copy of the GNU General Public License |
15 | .\" along with Grecs. If not, see <http://www.gnu.org/licenses/>. | 15 | .\" along with Grecs. If not, see <http://www.gnu.org/licenses/>. |
16 | .\" | 16 | .\" |
17 | .TH GRECS_SETUP 3 "May 8, 2011" "GRECS" "Grecs User Reference" | 17 | .TH GRECS_SETUP 3 "May 15, 2011" "GRECS" "Grecs User Reference" |
18 | .SH NAME | 18 | .SH NAME |
19 | GRECS_SETUP \- Initialize \fBgrecs\fR submodule. | 19 | GRECS_SETUP \- Initialize \fBgrecs\fR submodule. |
20 | .SH SYNOPSIS | 20 | .SH SYNOPSIS |
@@ -44,6 +44,12 @@ The | |||
44 | argument is a space-separated list of options. The following options | 44 | argument is a space-separated list of options. The following options |
45 | are understood: | 45 | are understood: |
46 | .TP | 46 | .TP |
47 | .B all-parsers | ||
48 | Compile all available parsers. | ||
49 | .TP | ||
50 | .B parser-meta1 | ||
51 | Build the parser for MeTA1 configuration files. | ||
52 | .TP | ||
47 | .B no-preproc | 53 | .B no-preproc |
48 | Disable the use of preprocessor. | 54 | Disable the use of preprocessor. |
49 | .TP | 55 | .TP |
diff --git a/doc/grecs_parse.3 b/doc/grecs_parse.3 index 2abc417..dff6759 100644 --- a/doc/grecs_parse.3 +++ b/doc/grecs_parse.3 | |||
@@ -149,13 +149,11 @@ screen: | |||
149 | int | 149 | int |
150 | main(int argc, char **argv) | 150 | main(int argc, char **argv) |
151 | { | 151 | { |
152 | struct grecs_node *tree, *node; | 152 | struct grecs_node *tree; |
153 | 153 | ||
154 | tree = grecs_parse(argv[1]); | 154 | tree = grecs_parse(argv[1]); |
155 | for (node = tree; node; node = node->next) { | 155 | grecs_format_node(tree, GRECS_NODE_FLAG_DEFAULT, stdout); |
156 | grecs_format_node(node, GRECS_NODE_FLAG_DEFAULT, stdout); | 156 | fputc('\\n', stdout); |
157 | fputc('\n', stdout); | ||
158 | } | ||
159 | grecs_tree_free(tree); | 157 | grecs_tree_free(tree); |
160 | exit(0); | 158 | exit(0); |
161 | } | 159 | } |
diff --git a/src/.gitignore b/src/.gitignore index 9ef1b57..feb5040 100644 --- a/src/.gitignore +++ b/src/.gitignore | |||
@@ -2,6 +2,10 @@ grecs-gram.c | |||
2 | grecs-gram.h | 2 | grecs-gram.h |
3 | grecs-gram.output | 3 | grecs-gram.output |
4 | grecs-lex.c | 4 | grecs-lex.c |
5 | meta1-gram.c | ||
6 | meta1-gram.h | ||
7 | meta1-gram.output | ||
8 | meta1-lex.c | ||