1 /* Scan Bison Skeletons. -*- C -*-
3 Copyright (C) 2001-2012 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 %option nodefault noyywrap noinput nounput never-interactive debug
21 %option prefix="skel_" outfile="lex.yy.c"
24 /* Work around a bug in flex 2.5.31. See Debian bug 333231
25 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
29 #define FLEX_PREFIX(Id) skel_ ## Id
30 #include <src/flex-scanner.h>
36 #include <src/complain.h>
37 #include <src/getargs.h>
38 #include <src/files.h>
39 #include <src/scan-skel.h>
41 #define YY_DECL static int skel_lex (void)
44 static void at_directive_perform (int argc, char *argv[],
45 char **outnamep, int *out_linenop);
46 static void fail_for_at_directive_too_many_args (char const *at_directive_name);
47 static void fail_for_at_directive_too_few_args (char const *at_directive_name);
48 static void fail_for_invalid_at (char const *at);
51 %x SC_AT_DIRECTIVE_ARGS
52 %x SC_AT_DIRECTIVE_SKIP_WS
57 int out_lineno PACIFY_CC (= 0);
60 /* Currently, only the @warn, @complain, @fatal, @warn_at, @complain_at, and
61 @fatal_at directives take multiple arguments, and the last three already
62 can't take more than 7. argv[0] is the directive name. */
68 "@@" fputc ('@', yyout);
69 "@{" fputc ('[', yyout);
70 "@}" fputc (']', yyout);
71 "@`" continue; /* Used by b4_cat in ../data/bison.m4. */
74 "@oline@" fprintf (yyout, "%d", out_lineno + 1);
75 "@ofile@" fputs (quotearg_style (c_quoting_style, outname), yyout);
78 yytext[yyleng-1] = '\0';
79 obstack_grow (&obstack_for_string, yytext, yyleng);
80 argv[argc++] = obstack_finish (&obstack_for_string);
81 BEGIN SC_AT_DIRECTIVE_ARGS;
84 /* This pattern must not match more than the previous @ patterns. */
85 @[^@{}`(\n]* fail_for_invalid_at (yytext);
86 \n out_lineno++; ECHO;
98 <SC_AT_DIRECTIVE_ARGS>
102 "@@" obstack_1grow (&obstack_for_string, '@');
103 "@{" obstack_1grow (&obstack_for_string, '[');
104 "@}" obstack_1grow (&obstack_for_string, ']');
105 "@`" continue; /* For starting an argument that begins with whitespace. */
109 if (argc >= ARGC_MAX)
110 fail_for_at_directive_too_many_args (argv[0]);
112 argv[argc++] = obstack_finish0 (&obstack_for_string);
114 /* Like M4, skip whitespace after a comma. */
115 if (yytext[1] == ',')
116 BEGIN SC_AT_DIRECTIVE_SKIP_WS;
119 at_directive_perform (argc, argv, &outname, &out_lineno);
120 obstack_free (&obstack_for_string, argv[0]);
126 @.? fail_for_invalid_at (yytext);
129 <SC_AT_DIRECTIVE_SKIP_WS>
132 . yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS;
135 <SC_AT_DIRECTIVE_ARGS,SC_AT_DIRECTIVE_SKIP_WS>
137 <<EOF>> complain (NULL, fatal, _("unclosed %s directive in skeleton"), argv[0]);
142 /*------------------------.
143 | Scan a Bison skeleton. |
144 `------------------------*/
149 static bool initialized = false;
153 obstack_init (&obstack_for_string);
156 skel__flex_debug = trace_flag & trace_skeleton;
161 skel_scanner_free (void)
163 obstack_free (&obstack_for_string, 0);
164 /* Reclaim Flex's buffers. */
168 static inline warnings
169 flag (const char *arg)
173 case 'w': return Wother;
174 case 'c': return complaint;
175 case 'f': return fatal;
176 default: aver (false); break;
181 at_directive_perform (int argc, char *argv[], char **outnamep, int *out_linenop)
183 if (STREQ (argv[0], "@basename"))
186 fail_for_at_directive_too_many_args (argv[0]);
187 fputs (last_component (argv[1]), yyout);
189 else if (STREQ (argv[0], "@warn") || STREQ (argv[0], "@warn_at")
190 || STREQ (argv[0], "@complain") || STREQ (argv[0], "@complain_at")
191 || STREQ (argv[0], "@fatal") || STREQ (argv[0], "@fatal_at"))
193 warnings w = flag (*argv);
195 location *locp = NULL;
196 if (STREQ (*argv + strlen (*argv) - 3, "_at"))
199 fail_for_at_directive_too_few_args (argv[0]);
200 boundary_set_from_string (&loc.start, argv[1]);
201 boundary_set_from_string (&loc.end, argv[2]);
207 fail_for_at_directive_too_few_args (argv[0]);
208 complain_args (locp, w, argc, argv);
210 else if (STREQ (argv[0], "@output"))
213 fail_for_at_directive_too_many_args (argv[0]);
219 *outnamep = xstrdup (argv[1]);
220 output_file_name_check (outnamep);
221 yyout = xfopen (*outnamep, "w");
225 fail_for_invalid_at (argv[0]);
229 fail_for_at_directive_too_few_args (char const *at_directive_name)
231 complain (NULL, fatal, _("too few arguments for %s directive in skeleton"),
236 fail_for_at_directive_too_many_args (char const *at_directive_name)
238 complain (NULL, fatal, _("too many arguments for %s directive in skeleton"),
243 fail_for_invalid_at (char const *at)
245 complain (NULL, fatal, "invalid @ in skeleton: %s", at);