1 /* Scan Bison Skeletons. -*- C -*-
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
6 This file is part of Bison, the GNU Compiler Compiler.
8 Bison is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 Bison is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bison; see the file COPYING. If not, write to the Free
20 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 %option nodefault noyywrap nounput never-interactive debug
24 %option prefix="skel_" outfile="lex.yy.c"
27 /* Work around a bug in flex 2.5.31. See Debian bug 333231
28 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
32 #define FLEX_PREFIX(Id) skel_ ## Id
33 #include "flex-scanner.h"
42 #include "scan-skel.h"
44 #define YY_DECL static int skel_lex (void)
47 #define QPUTS(String) \
48 fputs (quotearg_style (c_quoting_style, String), yyout)
50 static void fail_for_at_directive_too_many_args (void);
51 static void fail_for_invalid_at (char const *at);
53 /* In SC_AT_DIRECTIVE_ARG context, the name of the directive. */
54 static char *at_directive_name;
56 /* Currently, only the @warn, @complain, and @fatal directives take multiple
57 arguments, and they already can't take more than 5. */
58 #define AT_DIRECTIVE_ARGC_MAX 5
59 static int at_directive_argc = 0;
60 static char *at_directive_argv[AT_DIRECTIVE_ARGC_MAX];
63 %x SC_AT_DIRECTIVE_ARG
64 %x SC_AT_DIRECTIVE_SKIP_WS
69 int lineno IF_LINT (= 0);
73 "@@" fputc ('@', yyout);
74 "@{" fputc ('[', yyout);
75 "@}" fputc (']', yyout);
77 "@oline@" fprintf (yyout, "%d", lineno + 1);
78 "@ofile@" QPUTS (outname);
79 "@dir_prefix@" QPUTS (dir_prefix);
82 yytext[yyleng-1] = '\0';
83 at_directive_name = xstrdup (yytext);
84 BEGIN SC_AT_DIRECTIVE_ARG;
87 /* This pattern must not match more than the previous @ patterns. */
88 @[^@{}(\n]* fail_for_invalid_at (yytext);
101 <SC_AT_DIRECTIVE_ARG>{
102 [^@\n]+ { STRING_GROW; }
103 \n { ++lineno; STRING_GROW; }
105 "@@" { obstack_1grow (&obstack_for_string, '@'); }
106 "@{" { obstack_1grow (&obstack_for_string, '['); }
107 "@}" { obstack_1grow (&obstack_for_string, ']'); }
108 "@`" /* Emtpy. Useful for starting an argument
109 that begins with whitespace. */
112 if (at_directive_argc >= AT_DIRECTIVE_ARGC_MAX)
113 fail_for_at_directive_too_many_args ();
115 obstack_1grow (&obstack_for_string, '\0');
116 at_directive_argv[at_directive_argc++] =
117 obstack_finish (&obstack_for_string);
119 /* Like M4, skip whitespace after a comma. */
120 if (yytext[1] == ',')
121 BEGIN SC_AT_DIRECTIVE_SKIP_WS;
124 if (0 == strcmp (at_directive_name, "@basename"))
126 if (at_directive_argc > 1)
127 fail_for_at_directive_too_many_args ();
128 fputs (last_component (at_directive_argv[0]), yyout);
130 else if (0 == strcmp (at_directive_name, "@warn")
131 || 0 == strcmp (at_directive_name, "@complain")
132 || 0 == strcmp (at_directive_name, "@fatal"))
134 void (*func)(char const *, ...);
135 switch (at_directive_name[1])
137 case 'w': func = warn; break;
138 case 'c': func = complain; break;
139 case 'f': func = fatal; break;
140 default: aver (false); func = NULL; break;
142 switch (at_directive_argc)
145 func (_(at_directive_argv[0]));
148 func (_(at_directive_argv[0]), at_directive_argv[1]);
151 func (_(at_directive_argv[0]), at_directive_argv[1],
152 at_directive_argv[2]);
155 func (_(at_directive_argv[0]), at_directive_argv[1],
156 at_directive_argv[2], at_directive_argv[3]);
159 func (_(at_directive_argv[0]), at_directive_argv[1],
160 at_directive_argv[2], at_directive_argv[3],
161 at_directive_argv[4]);
164 fail_for_at_directive_too_many_args ();
168 else if (0 == strcmp (at_directive_name, "@output"))
170 if (at_directive_argc > 1)
171 fail_for_at_directive_too_many_args ();
177 outname = xstrdup (at_directive_argv[0]);
178 output_file_name_check (outname);
179 yyout = xfopen (outname, "w");
183 fail_for_invalid_at (at_directive_name);
185 obstack_free (&obstack_for_string, at_directive_argv[0]);
186 at_directive_argc = 0;
187 free (at_directive_name);
192 @.? { fail_for_invalid_at (yytext); }
195 <SC_AT_DIRECTIVE_SKIP_WS>{
198 . { yyless (0); BEGIN SC_AT_DIRECTIVE_ARG; }
201 <SC_AT_DIRECTIVE_ARG,SC_AT_DIRECTIVE_SKIP_WS>{
203 fatal (_("unclosed %s directive in skeleton"), at_directive_name);
209 /*------------------------.
210 | Scan a Bison skeleton. |
211 `------------------------*/
216 static bool initialized = false;
220 obstack_init (&obstack_for_string);
223 skel__flex_debug = trace_flag & trace_skeleton;
225 /* Reclaim Flex's buffers. */
230 fail_for_at_directive_too_many_args (void)
232 fatal (_("too many arguments for %s directive in skeleton"),
237 fail_for_invalid_at (char const *at)
239 fatal ("invalid @ in skeleton: %s", at);
243 skel_scanner_free (void)
245 obstack_free (&obstack_for_string, 0);