1 | /* scan.l - scanner for flex input -*-C-*- */
|
---|
2 |
|
---|
3 | %{
|
---|
4 | /* Copyright (c) 1990 The Regents of the University of California. */
|
---|
5 | /* All rights reserved. */
|
---|
6 |
|
---|
7 | /* This code is derived from software contributed to Berkeley by */
|
---|
8 | /* Vern Paxson. */
|
---|
9 |
|
---|
10 | /* The United States Government has rights in this work pursuant */
|
---|
11 | /* to contract no. DE-AC03-76SF00098 between the United States */
|
---|
12 | /* Department of Energy and the University of California. */
|
---|
13 |
|
---|
14 | /* This file is part of flex. */
|
---|
15 |
|
---|
16 | /* Redistribution and use in source and binary forms, with or without */
|
---|
17 | /* modification, are permitted provided that the following conditions */
|
---|
18 | /* are met: */
|
---|
19 |
|
---|
20 | /* 1. Redistributions of source code must retain the above copyright */
|
---|
21 | /* notice, this list of conditions and the following disclaimer. */
|
---|
22 | /* 2. Redistributions in binary form must reproduce the above copyright */
|
---|
23 | /* notice, this list of conditions and the following disclaimer in the */
|
---|
24 | /* documentation and/or other materials provided with the distribution. */
|
---|
25 |
|
---|
26 | /* Neither the name of the University nor the names of its contributors */
|
---|
27 | /* may be used to endorse or promote products derived from this software */
|
---|
28 | /* without specific prior written permission. */
|
---|
29 |
|
---|
30 | /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
|
---|
31 | /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
|
---|
32 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
|
---|
33 | /* PURPOSE. */
|
---|
34 |
|
---|
35 | #include "flexdef.h"
|
---|
36 | #include "parse.h"
|
---|
37 | extern bool tablesverify, tablesext;
|
---|
38 | extern int trlcontxt; /* Set in parse.y for each rule. */
|
---|
39 |
|
---|
40 | #define ACTION_ECHO add_action( yytext )
|
---|
41 | #define ACTION_IFDEF(def, should_define) \
|
---|
42 | { \
|
---|
43 | if ( should_define ) \
|
---|
44 | action_define( def, 1 ); \
|
---|
45 | }
|
---|
46 |
|
---|
47 | #define ACTION_M4_IFDEF(def, should_define) \
|
---|
48 | do{ \
|
---|
49 | if ( should_define ) \
|
---|
50 | buf_m4_define( &m4defs_buf, def, NULL);\
|
---|
51 | else \
|
---|
52 | buf_m4_undefine( &m4defs_buf, def);\
|
---|
53 | } while(0)
|
---|
54 |
|
---|
55 | #define MARK_END_OF_PROLOG mark_prolog();
|
---|
56 |
|
---|
57 | #define YY_DECL \
|
---|
58 | int flexscan()
|
---|
59 |
|
---|
60 | #define RETURNCHAR \
|
---|
61 | yylval = (unsigned char) yytext[0]; \
|
---|
62 | return CHAR;
|
---|
63 |
|
---|
64 | #define RETURNNAME \
|
---|
65 | if(yyleng < MAXLINE) \
|
---|
66 | { \
|
---|
67 | strcpy( nmstr, yytext ); \
|
---|
68 | } \
|
---|
69 | else \
|
---|
70 | { \
|
---|
71 | synerr(_("Input line too long\n")); \
|
---|
72 | FLEX_EXIT(EXIT_FAILURE); \
|
---|
73 | } \
|
---|
74 | return NAME;
|
---|
75 |
|
---|
76 | #define PUT_BACK_STRING(str, start) \
|
---|
77 | for ( i = strlen( str ) - 1; i >= start; --i ) \
|
---|
78 | unput((str)[i])
|
---|
79 |
|
---|
80 | #define CHECK_REJECT(str) \
|
---|
81 | if ( all_upper( str ) ) \
|
---|
82 | reject = true;
|
---|
83 |
|
---|
84 | #define CHECK_YYMORE(str) \
|
---|
85 | if ( all_lower( str ) ) \
|
---|
86 | yymore_used = true;
|
---|
87 |
|
---|
88 | #define YY_USER_INIT \
|
---|
89 | if ( getenv("POSIXLY_CORRECT") ) \
|
---|
90 | posix_compat = true;
|
---|
91 |
|
---|
92 | %}
|
---|
93 |
|
---|
94 | %option caseless nodefault stack noyy_top_state
|
---|
95 | %option nostdinit
|
---|
96 |
|
---|
97 | %x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE
|
---|
98 | %x FIRSTCCL CCL ACTION RECOVER COMMENT ACTION_STRING PERCENT_BRACE_ACTION
|
---|
99 | %x OPTION LINEDIR CODEBLOCK_MATCH_BRACE
|
---|
100 |
|
---|
101 | WS [[:blank:]]+
|
---|
102 | OPTWS [[:blank:]]*
|
---|
103 | NOT_WS [^[:blank:]\r\n]
|
---|
104 |
|
---|
105 | NL \r?\n
|
---|
106 |
|
---|
107 | NAME ([[:alpha:]_][[:alnum:]_-]*)
|
---|
108 | NOT_NAME [^[:alpha:]_*\n]+
|
---|
109 |
|
---|
110 | SCNAME {NAME}
|
---|
111 |
|
---|
112 | ESCSEQ (\\([^\n]|[0-7]{1,3}|x[[:xdigit:]]{1,2}))
|
---|
113 |
|
---|
114 | FIRST_CCL_CHAR ([^\\\n]|{ESCSEQ})
|
---|
115 | CCL_CHAR ([^\\\n\]]|{ESCSEQ})
|
---|
116 | CCL_EXPR ("[:"[[:alpha:]]+":]")
|
---|
117 |
|
---|
118 | LEXOPT [aceknopr]
|
---|
119 |
|
---|
120 | %%
|
---|
121 | static int bracelevel, didadef, indented_code;
|
---|
122 | static int doing_rule_action = false;
|
---|
123 | static int option_sense;
|
---|
124 |
|
---|
125 | int doing_codeblock = false;
|
---|
126 | int i, brace_depth=0, brace_start_line=0;
|
---|
127 | Char nmdef[MAXLINE];
|
---|
128 |
|
---|
129 |
|
---|
130 | <INITIAL>{
|
---|
131 | ^{WS} indented_code = true; BEGIN(CODEBLOCK);
|
---|
132 | ^"/*" ACTION_ECHO; yy_push_state( COMMENT );
|
---|
133 | ^#{OPTWS}line{WS} yy_push_state( LINEDIR );
|
---|
134 | ^"%s"{NAME}? return SCDECL;
|
---|
135 | ^"%x"{NAME}? return XSCDECL;
|
---|
136 | ^"%{".*{NL} {
|
---|
137 | ++linenum;
|
---|
138 | line_directive_out( (FILE *) 0, 1 );
|
---|
139 | indented_code = false;
|
---|
140 | BEGIN(CODEBLOCK);
|
---|
141 | }
|
---|
142 | ^"%top"[[:blank:]]*"{"[[:blank:]]*{NL} {
|
---|
143 | brace_start_line = linenum;
|
---|
144 | ++linenum;
|
---|
145 | buf_linedir( &top_buf, infilename?infilename:"<stdin>", linenum);
|
---|
146 | brace_depth = 1;
|
---|
147 | yy_push_state(CODEBLOCK_MATCH_BRACE);
|
---|
148 | }
|
---|
149 |
|
---|
150 | ^"%top".* synerr( _("malformed '%top' directive") );
|
---|
151 |
|
---|
152 | {WS} /* discard */
|
---|
153 |
|
---|
154 | ^"%%".* {
|
---|
155 | sectnum = 2;
|
---|
156 | bracelevel = 0;
|
---|
157 | mark_defs1();
|
---|
158 | line_directive_out( (FILE *) 0, 1 );
|
---|
159 | BEGIN(SECT2PROLOG);
|
---|
160 | return SECTEND;
|
---|
161 | }
|
---|
162 |
|
---|
163 | ^"%pointer".*{NL} yytext_is_array = false; ++linenum;
|
---|
164 | ^"%array".*{NL} yytext_is_array = true; ++linenum;
|
---|
165 |
|
---|
166 | ^"%option" BEGIN(OPTION); return OPTION_OP;
|
---|
167 |
|
---|
168 | ^"%"{LEXOPT}{OPTWS}[[:digit:]]*{OPTWS}{NL} ++linenum; /* ignore */
|
---|
169 | ^"%"{LEXOPT}{WS}.*{NL} ++linenum; /* ignore */
|
---|
170 |
|
---|
171 | /* xgettext: no-c-format */
|
---|
172 | ^"%"[^sxaceknopr{}].* synerr( _( "unrecognized '%' directive" ) );
|
---|
173 |
|
---|
174 | ^{NAME} {
|
---|
175 | if(yyleng < MAXLINE)
|
---|
176 | {
|
---|
177 | strcpy( nmstr, yytext );
|
---|
178 | }
|
---|
179 | else
|
---|
180 | {
|
---|
181 | synerr( _("Input line too long\n"));
|
---|
182 | FLEX_EXIT(EXIT_FAILURE);
|
---|
183 | }
|
---|
184 |
|
---|
185 | didadef = false;
|
---|
186 | BEGIN(PICKUPDEF);
|
---|
187 | }
|
---|
188 |
|
---|
189 | {SCNAME} RETURNNAME;
|
---|
190 | ^{OPTWS}{NL} ++linenum; /* allows blank lines in section 1 */
|
---|
191 | {OPTWS}{NL} ACTION_ECHO; ++linenum; /* maybe end of comment line */
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | <COMMENT>{
|
---|
196 | "*/" ACTION_ECHO; yy_pop_state();
|
---|
197 | "*" ACTION_ECHO;
|
---|
198 | [^*\n]+ ACTION_ECHO;
|
---|
199 | [^*\n]*{NL} ++linenum; ACTION_ECHO;
|
---|
200 | }
|
---|
201 |
|
---|
202 | <LINEDIR>{
|
---|
203 | \n yy_pop_state();
|
---|
204 | [[:digit:]]+ linenum = myctoi( yytext );
|
---|
205 |
|
---|
206 | \"[^"\n]*\" {
|
---|
207 | flex_free( (void *) infilename );
|
---|
208 | infilename = copy_string( yytext + 1 );
|
---|
209 | infilename[strlen( infilename ) - 1] = '\0';
|
---|
210 | }
|
---|
211 | . /* ignore spurious characters */
|
---|
212 | }
|
---|
213 |
|
---|
214 | <CODEBLOCK>{
|
---|
215 | ^"%}".*{NL} ++linenum; BEGIN(INITIAL);
|
---|
216 |
|
---|
217 | {NAME}|{NOT_NAME}|. ACTION_ECHO;
|
---|
218 |
|
---|
219 | {NL} {
|
---|
220 | ++linenum;
|
---|
221 | ACTION_ECHO;
|
---|
222 | if ( indented_code )
|
---|
223 | BEGIN(INITIAL);
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | <CODEBLOCK_MATCH_BRACE>{
|
---|
228 | "}" {
|
---|
229 | if( --brace_depth == 0){
|
---|
230 | /* TODO: Matched. */
|
---|
231 | yy_pop_state();
|
---|
232 | }else
|
---|
233 | buf_strnappend(&top_buf, yytext, yyleng);
|
---|
234 | }
|
---|
235 |
|
---|
236 | "{" {
|
---|
237 | brace_depth++;
|
---|
238 | buf_strnappend(&top_buf, yytext, yyleng);
|
---|
239 | }
|
---|
240 |
|
---|
241 | {NL} {
|
---|
242 | ++linenum;
|
---|
243 | buf_strnappend(&top_buf, yytext, yyleng);
|
---|
244 | }
|
---|
245 |
|
---|
246 | [^{}\r\n]+ {
|
---|
247 | buf_strnappend(&top_buf, yytext, yyleng);
|
---|
248 | }
|
---|
249 |
|
---|
250 | <<EOF>> {
|
---|
251 | linenum = brace_start_line;
|
---|
252 | synerr(_("Unmatched '{'"));
|
---|
253 | yyterminate();
|
---|
254 | }
|
---|
255 | }
|
---|
256 |
|
---|
257 |
|
---|
258 | <PICKUPDEF>{
|
---|
259 | {WS} /* separates name and definition */
|
---|
260 |
|
---|
261 | {NOT_WS}[^\r\n]* {
|
---|
262 | if(yyleng < MAXLINE)
|
---|
263 | {
|
---|
264 | strcpy( (char *) nmdef, yytext );
|
---|
265 | }
|
---|
266 | else
|
---|
267 | {
|
---|
268 | synerr( _("Input line too long\n"));
|
---|
269 | FLEX_EXIT(EXIT_FAILURE);
|
---|
270 | }
|
---|
271 | /* Skip trailing whitespace. */
|
---|
272 | for ( i = strlen( (char *) nmdef ) - 1;
|
---|
273 | i >= 0 && (nmdef[i] == ' ' || nmdef[i] == '\t');
|
---|
274 | --i )
|
---|
275 | ;
|
---|
276 |
|
---|
277 | nmdef[i + 1] = '\0';
|
---|
278 |
|
---|
279 | ndinstal( nmstr, nmdef );
|
---|
280 | didadef = true;
|
---|
281 | }
|
---|
282 |
|
---|
283 | {NL} {
|
---|
284 | if ( ! didadef )
|
---|
285 | synerr( _( "incomplete name definition" ) );
|
---|
286 | BEGIN(INITIAL);
|
---|
287 | ++linenum;
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 |
|
---|
292 | <OPTION>{
|
---|
293 | {NL} ++linenum; BEGIN(INITIAL);
|
---|
294 | {WS} option_sense = true;
|
---|
295 |
|
---|
296 | "=" return '=';
|
---|
297 |
|
---|
298 | no option_sense = ! option_sense;
|
---|
299 |
|
---|
300 | 7bit csize = option_sense ? 128 : 256;
|
---|
301 | 8bit csize = option_sense ? 256 : 128;
|
---|
302 |
|
---|
303 | align long_align = option_sense;
|
---|
304 | always-interactive {
|
---|
305 | ACTION_M4_IFDEF( "M4""_YY_ALWAYS_INTERACTIVE", option_sense );
|
---|
306 | interactive = option_sense;
|
---|
307 | }
|
---|
308 | array yytext_is_array = option_sense;
|
---|
309 | ansi-definitions ansi_func_defs = option_sense;
|
---|
310 | ansi-prototypes ansi_func_protos = option_sense;
|
---|
311 | backup backing_up_report = option_sense;
|
---|
312 | batch interactive = ! option_sense;
|
---|
313 | bison-bridge bison_bridge_lval = option_sense;
|
---|
314 | bison-locations { if((bison_bridge_lloc = option_sense))
|
---|
315 | bison_bridge_lval = true;
|
---|
316 | }
|
---|
317 | "c++" C_plus_plus = option_sense;
|
---|
318 | caseful|case-sensitive caseins = ! option_sense;
|
---|
319 | caseless|case-insensitive caseins = option_sense;
|
---|
320 | debug ddebug = option_sense;
|
---|
321 | default spprdflt = ! option_sense;
|
---|
322 | ecs useecs = option_sense;
|
---|
323 | fast {
|
---|
324 | useecs = usemecs = false;
|
---|
325 | use_read = fullspd = true;
|
---|
326 | }
|
---|
327 | full {
|
---|
328 | useecs = usemecs = false;
|
---|
329 | use_read = fulltbl = true;
|
---|
330 | }
|
---|
331 | input ACTION_IFDEF("YY_NO_INPUT", ! option_sense);
|
---|
332 | interactive interactive = option_sense;
|
---|
333 | lex-compat lex_compat = option_sense;
|
---|
334 | posix-compat posix_compat = option_sense;
|
---|
335 | main {
|
---|
336 | ACTION_M4_IFDEF( "M4""_YY_MAIN", option_sense);
|
---|
337 | /* Override yywrap */
|
---|
338 | if( option_sense == true )
|
---|
339 | do_yywrap = false;
|
---|
340 | }
|
---|
341 | meta-ecs usemecs = option_sense;
|
---|
342 | never-interactive {
|
---|
343 | ACTION_M4_IFDEF( "M4""_YY_NEVER_INTERACTIVE", option_sense );
|
---|
344 | interactive = !option_sense;
|
---|
345 | }
|
---|
346 | perf-report performance_report += option_sense ? 1 : -1;
|
---|
347 | pointer yytext_is_array = ! option_sense;
|
---|
348 | read use_read = option_sense;
|
---|
349 | reentrant reentrant = option_sense;
|
---|
350 | reject reject_really_used = option_sense;
|
---|
351 | stack ACTION_M4_IFDEF( "M4""_YY_STACK_USED", option_sense );
|
---|
352 | stdinit do_stdinit = option_sense;
|
---|
353 | stdout use_stdout = option_sense;
|
---|
354 | unistd ACTION_IFDEF("YY_NO_UNISTD_H", ! option_sense);
|
---|
355 | unput ACTION_M4_IFDEF("M4""_YY_NO_UNPUT", ! option_sense);
|
---|
356 | verbose printstats = option_sense;
|
---|
357 | warn nowarn = ! option_sense;
|
---|
358 | yylineno do_yylineno = option_sense; ACTION_M4_IFDEF("M4""_YY_USE_LINENO", option_sense);
|
---|
359 | yymore yymore_really_used = option_sense;
|
---|
360 | yywrap do_yywrap = option_sense;
|
---|
361 |
|
---|
362 | yy_push_state ACTION_M4_IFDEF("M4""_YY_NO_PUSH_STATE", ! option_sense);
|
---|
363 | yy_pop_state ACTION_M4_IFDEF("M4""_YY_NO_POP_STATE", ! option_sense);
|
---|
364 | yy_top_state ACTION_M4_IFDEF("M4""_YY_NO_TOP_STATE", ! option_sense);
|
---|
365 |
|
---|
366 | yy_scan_buffer ACTION_M4_IFDEF("M4""_YY_NO_SCAN_BUFFER", ! option_sense);
|
---|
367 | yy_scan_bytes ACTION_M4_IFDEF("M4""_YY_NO_SCAN_BYTES", ! option_sense);
|
---|
368 | yy_scan_string ACTION_M4_IFDEF("M4""_YY_NO_SCAN_STRING", ! option_sense);
|
---|
369 |
|
---|
370 | yyalloc ACTION_M4_IFDEF("M4""_YY_NO_FLEX_ALLOC", ! option_sense);
|
---|
371 | yyrealloc ACTION_M4_IFDEF("M4""_YY_NO_FLEX_REALLOC", ! option_sense);
|
---|
372 | yyfree ACTION_M4_IFDEF("M4""_YY_NO_FLEX_FREE", ! option_sense);
|
---|
373 |
|
---|
374 | yyget_debug ACTION_M4_IFDEF("M4""_YY_NO_GET_DEBUG", ! option_sense);
|
---|
375 | yyset_debug ACTION_M4_IFDEF("M4""_YY_NO_SET_DEBUG", ! option_sense);
|
---|
376 | yyget_extra ACTION_M4_IFDEF("M4""_YY_NO_GET_EXTRA", ! option_sense);
|
---|
377 | yyset_extra ACTION_M4_IFDEF("M4""_YY_NO_SET_EXTRA", ! option_sense);
|
---|
378 | yyget_leng ACTION_M4_IFDEF("M4""_YY_NO_GET_LENG", ! option_sense);
|
---|
379 | yyget_text ACTION_M4_IFDEF("M4""_YY_NO_GET_TEXT", ! option_sense);
|
---|
380 | yyget_lineno ACTION_M4_IFDEF("M4""_YY_NO_GET_LINENO", ! option_sense);
|
---|
381 | yyset_lineno ACTION_M4_IFDEF("M4""_YY_NO_SET_LINENO", ! option_sense);
|
---|
382 | yyget_in ACTION_M4_IFDEF("M4""_YY_NO_GET_IN", ! option_sense);
|
---|
383 | yyset_in ACTION_M4_IFDEF("M4""_YY_NO_SET_IN", ! option_sense);
|
---|
384 | yyget_out ACTION_M4_IFDEF("M4""_YY_NO_GET_OUT", ! option_sense);
|
---|
385 | yyset_out ACTION_M4_IFDEF("M4""_YY_NO_SET_OUT", ! option_sense);
|
---|
386 | yyget_lval ACTION_M4_IFDEF("M4""_YY_NO_GET_LVAL", ! option_sense);
|
---|
387 | yyset_lval ACTION_M4_IFDEF("M4""_YY_NO_SET_LVAL", ! option_sense);
|
---|
388 | yyget_lloc ACTION_M4_IFDEF("M4""_YY_NO_GET_LLOC", ! option_sense);
|
---|
389 | yyset_lloc ACTION_M4_IFDEF("M4""_YY_NO_SET_LLOC", ! option_sense);
|
---|
390 |
|
---|
391 | outfile return OPT_OUTFILE;
|
---|
392 | prefix return OPT_PREFIX;
|
---|
393 | yyclass return OPT_YYCLASS;
|
---|
394 | header(-file)? return OPT_HEADER;
|
---|
395 | tables-file return OPT_TABLES;
|
---|
396 | tables-verify {
|
---|
397 | tablesverify = option_sense;
|
---|
398 | if(!tablesext && option_sense)
|
---|
399 | tablesext = true;
|
---|
400 | }
|
---|
401 |
|
---|
402 |
|
---|
403 | \"[^"\n]*\" {
|
---|
404 | if(yyleng-1 < MAXLINE)
|
---|
405 | {
|
---|
406 | strcpy( nmstr, yytext + 1 );
|
---|
407 | }
|
---|
408 | else
|
---|
409 | {
|
---|
410 | synerr( _("Input line too long\n"));
|
---|
411 | FLEX_EXIT(EXIT_FAILURE);
|
---|
412 | }
|
---|
413 | nmstr[strlen( nmstr ) - 1] = '\0';
|
---|
414 | return NAME;
|
---|
415 | }
|
---|
416 |
|
---|
417 | (([a-mo-z]|n[a-np-z])[[:alpha:]\-+]*)|. {
|
---|
418 | format_synerr( _( "unrecognized %%option: %s" ),
|
---|
419 | yytext );
|
---|
420 | BEGIN(RECOVER);
|
---|
421 | }
|
---|
422 | }
|
---|
423 |
|
---|
424 | <RECOVER>.*{NL} ++linenum; BEGIN(INITIAL);
|
---|
425 |
|
---|
426 |
|
---|
427 | <SECT2PROLOG>{
|
---|
428 | ^"%{".* ++bracelevel; yyless( 2 ); /* eat only %{ */
|
---|
429 | ^"%}".* --bracelevel; yyless( 2 ); /* eat only %} */
|
---|
430 |
|
---|
431 | ^{WS}.* ACTION_ECHO; /* indented code in prolog */
|
---|
432 |
|
---|
433 | ^{NOT_WS}.* { /* non-indented code */
|
---|
434 | if ( bracelevel <= 0 )
|
---|
435 | { /* not in %{ ... %} */
|
---|
436 | yyless( 0 ); /* put it all back */
|
---|
437 | yy_set_bol( 1 );
|
---|
438 | mark_prolog();
|
---|
439 | BEGIN(SECT2);
|
---|
440 | }
|
---|
441 | else
|
---|
442 | ACTION_ECHO;
|
---|
443 | }
|
---|
444 |
|
---|
445 | .* ACTION_ECHO;
|
---|
446 | {NL} ++linenum; ACTION_ECHO;
|
---|
447 |
|
---|
448 | <<EOF>> {
|
---|
449 | mark_prolog();
|
---|
450 | sectnum = 0;
|
---|
451 | yyterminate(); /* to stop the parser */
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | <SECT2>{
|
---|
456 | ^{OPTWS}{NL} ++linenum; /* allow blank lines in section 2 */
|
---|
457 |
|
---|
458 | ^{OPTWS}"%{" {
|
---|
459 | indented_code = false;
|
---|
460 | doing_codeblock = true;
|
---|
461 | bracelevel = 1;
|
---|
462 | BEGIN(PERCENT_BRACE_ACTION);
|
---|
463 | }
|
---|
464 |
|
---|
465 | ^{OPTWS}"<" BEGIN(SC); return '<';
|
---|
466 | ^{OPTWS}"^" return '^';
|
---|
467 | \" BEGIN(QUOTE); return '"';
|
---|
468 | "{"/[[:digit:]] {
|
---|
469 | BEGIN(NUM);
|
---|
470 | if ( lex_compat || posix_compat )
|
---|
471 | return BEGIN_REPEAT_POSIX;
|
---|
472 | else
|
---|
473 | return BEGIN_REPEAT_FLEX;
|
---|
474 | }
|
---|
475 | "$"/([[:blank:]]|{NL}) return '$';
|
---|
476 |
|
---|
477 | {WS}"%{" {
|
---|
478 | bracelevel = 1;
|
---|
479 | BEGIN(PERCENT_BRACE_ACTION);
|
---|
480 |
|
---|
481 | if ( in_rule )
|
---|
482 | {
|
---|
483 | doing_rule_action = true;
|
---|
484 | in_rule = false;
|
---|
485 | return '\n';
|
---|
486 | }
|
---|
487 | }
|
---|
488 | {WS}"|".*{NL} continued_action = true; ++linenum; return '\n';
|
---|
489 |
|
---|
490 | ^{WS}"/*" {
|
---|
491 | yyless( yyleng - 2 ); /* put back '/', '*' */
|
---|
492 | bracelevel = 0;
|
---|
493 | continued_action = false;
|
---|
494 | BEGIN(ACTION);
|
---|
495 | }
|
---|
496 |
|
---|
497 | ^{WS} /* allow indented rules */
|
---|
498 |
|
---|
499 | {WS} {
|
---|
500 | /* This rule is separate from the one below because
|
---|
501 | * otherwise we get variable trailing context, so
|
---|
502 | * we can't build the scanner using -{f,F}.
|
---|
503 | */
|
---|
504 | bracelevel = 0;
|
---|
505 | continued_action = false;
|
---|
506 | BEGIN(ACTION);
|
---|
507 |
|
---|
508 | if ( in_rule )
|
---|
509 | {
|
---|
510 | doing_rule_action = true;
|
---|
511 | in_rule = false;
|
---|
512 | return '\n';
|
---|
513 | }
|
---|
514 | }
|
---|
515 |
|
---|
516 | {OPTWS}{NL} {
|
---|
517 | bracelevel = 0;
|
---|
518 | continued_action = false;
|
---|
519 | BEGIN(ACTION);
|
---|
520 | unput( '\n' ); /* so <ACTION> sees it */
|
---|
521 |
|
---|
522 | if ( in_rule )
|
---|
523 | {
|
---|
524 | doing_rule_action = true;
|
---|
525 | in_rule = false;
|
---|
526 | return '\n';
|
---|
527 | }
|
---|
528 | }
|
---|
529 |
|
---|
530 | ^{OPTWS}"<<EOF>>" |
|
---|
531 | "<<EOF>>" return EOF_OP;
|
---|
532 |
|
---|
533 | ^"%%".* {
|
---|
534 | sectnum = 3;
|
---|
535 | BEGIN(SECT3);
|
---|
536 | outn("/* Begin user sect3 */");
|
---|
537 | yyterminate(); /* to stop the parser */
|
---|
538 | }
|
---|
539 |
|
---|
540 | "["({FIRST_CCL_CHAR}|{CCL_EXPR})({CCL_CHAR}|{CCL_EXPR})* {
|
---|
541 | int cclval;
|
---|
542 |
|
---|
543 | if(yyleng < MAXLINE)
|
---|
544 | {
|
---|
545 | strcpy( nmstr, yytext );
|
---|
546 | }
|
---|
547 | else
|
---|
548 | {
|
---|
549 | synerr( _("Input line too long\n"));
|
---|
550 | FLEX_EXIT(EXIT_FAILURE);
|
---|
551 | }
|
---|
552 |
|
---|
553 | /* Check to see if we've already encountered this
|
---|
554 | * ccl.
|
---|
555 | */
|
---|
556 | if ( (cclval = ccllookup( (Char *) nmstr )) != 0 )
|
---|
557 | {
|
---|
558 | if ( input() != ']' )
|
---|
559 | synerr( _( "bad character class" ) );
|
---|
560 |
|
---|
561 | yylval = cclval;
|
---|
562 | ++cclreuse;
|
---|
563 | return PREVCCL;
|
---|
564 | }
|
---|
565 | else
|
---|
566 | {
|
---|
567 | /* We fudge a bit. We know that this ccl will
|
---|
568 | * soon be numbered as lastccl + 1 by cclinit.
|
---|
569 | */
|
---|
570 | cclinstal( (Char *) nmstr, lastccl + 1 );
|
---|
571 |
|
---|
572 | /* Push back everything but the leading bracket
|
---|
573 | * so the ccl can be rescanned.
|
---|
574 | */
|
---|
575 | yyless( 1 );
|
---|
576 |
|
---|
577 | BEGIN(FIRSTCCL);
|
---|
578 | return '[';
|
---|
579 | }
|
---|
580 | }
|
---|
581 |
|
---|
582 | /* Check for :space: at the end of the rule so we don't
|
---|
583 | * wrap the expanded regex in '(' ')' -- breaking trailing
|
---|
584 | * context.
|
---|
585 | */
|
---|
586 | "{"{NAME}"}"[[:space:]]? {
|
---|
587 | register Char *nmdefptr;
|
---|
588 | int end_is_ws, end_ch;
|
---|
589 |
|
---|
590 | end_ch = yytext[yyleng-1];
|
---|
591 | end_is_ws = end_ch != '}' ? 1 : 0;
|
---|
592 |
|
---|
593 | if(yyleng-1 < MAXLINE)
|
---|
594 | {
|
---|
595 | strcpy( nmstr, yytext + 1 );
|
---|
596 | }
|
---|
597 | else
|
---|
598 | {
|
---|
599 | synerr( _("Input line too long\n"));
|
---|
600 | FLEX_EXIT(EXIT_FAILURE);
|
---|
601 | }
|
---|
602 | nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */
|
---|
603 |
|
---|
604 | if ( (nmdefptr = ndlookup( nmstr )) == 0 )
|
---|
605 | format_synerr(
|
---|
606 | _( "undefined definition {%s}" ),
|
---|
607 | nmstr );
|
---|
608 |
|
---|
609 | else
|
---|
610 | { /* push back name surrounded by ()'s */
|
---|
611 | int len = strlen( (char *) nmdefptr );
|
---|
612 | if (end_is_ws)
|
---|
613 | unput(end_ch);
|
---|
614 |
|
---|
615 | if ( lex_compat || nmdefptr[0] == '^' ||
|
---|
616 | (len > 0 && nmdefptr[len - 1] == '$')
|
---|
617 | || (end_is_ws && trlcontxt))
|
---|
618 | { /* don't use ()'s after all */
|
---|
619 | PUT_BACK_STRING((char *) nmdefptr, 0);
|
---|
620 |
|
---|
621 | if ( nmdefptr[0] == '^' )
|
---|
622 | BEGIN(CARETISBOL);
|
---|
623 | }
|
---|
624 |
|
---|
625 | else
|
---|
626 | {
|
---|
627 | unput(')');
|
---|
628 | PUT_BACK_STRING((char *) nmdefptr, 0);
|
---|
629 | unput('(');
|
---|
630 | }
|
---|
631 | }
|
---|
632 | }
|
---|
633 |
|
---|
634 | [/|*+?.(){}] return (unsigned char) yytext[0];
|
---|
635 | . RETURNCHAR;
|
---|
636 | }
|
---|
637 |
|
---|
638 |
|
---|
639 | <SC>{
|
---|
640 | {OPTWS}{NL}{OPTWS} ++linenum; /* Allow blank lines & continuations */
|
---|
641 | [,*] return (unsigned char) yytext[0];
|
---|
642 | ">" BEGIN(SECT2); return '>';
|
---|
643 | ">"/^ BEGIN(CARETISBOL); return '>';
|
---|
644 | {SCNAME} RETURNNAME;
|
---|
645 | . {
|
---|
646 | format_synerr( _( "bad <start condition>: %s" ),
|
---|
647 | yytext );
|
---|
648 | }
|
---|
649 | }
|
---|
650 |
|
---|
651 | <CARETISBOL>"^" BEGIN(SECT2); return '^';
|
---|
652 |
|
---|
653 |
|
---|
654 | <QUOTE>{
|
---|
655 | [^"\n] RETURNCHAR;
|
---|
656 | \" BEGIN(SECT2); return '"';
|
---|
657 |
|
---|
658 | {NL} {
|
---|
659 | synerr( _( "missing quote" ) );
|
---|
660 | BEGIN(SECT2);
|
---|
661 | ++linenum;
|
---|
662 | return '"';
|
---|
663 | }
|
---|
664 | }
|
---|
665 |
|
---|
666 |
|
---|
667 | <FIRSTCCL>{
|
---|
668 | "^"/[^-\]\n] BEGIN(CCL); return '^';
|
---|
669 | "^"/("-"|"]") return '^';
|
---|
670 | . BEGIN(CCL); RETURNCHAR;
|
---|
671 | }
|
---|
672 |
|
---|
673 | <CCL>{
|
---|
674 | -/[^\]\n] return '-';
|
---|
675 | [^\]\n] RETURNCHAR;
|
---|
676 | "]" BEGIN(SECT2); return ']';
|
---|
677 | .|{NL} {
|
---|
678 | synerr( _( "bad character class" ) );
|
---|
679 | BEGIN(SECT2);
|
---|
680 | return ']';
|
---|
681 | }
|
---|
682 | }
|
---|
683 |
|
---|
684 | <FIRSTCCL,CCL>{
|
---|
685 | "[:alnum:]" BEGIN(CCL); return CCE_ALNUM;
|
---|
686 | "[:alpha:]" BEGIN(CCL); return CCE_ALPHA;
|
---|
687 | "[:blank:]" BEGIN(CCL); return CCE_BLANK;
|
---|
688 | "[:cntrl:]" BEGIN(CCL); return CCE_CNTRL;
|
---|
689 | "[:digit:]" BEGIN(CCL); return CCE_DIGIT;
|
---|
690 | "[:graph:]" BEGIN(CCL); return CCE_GRAPH;
|
---|
691 | "[:lower:]" BEGIN(CCL); return CCE_LOWER;
|
---|
692 | "[:print:]" BEGIN(CCL); return CCE_PRINT;
|
---|
693 | "[:punct:]" BEGIN(CCL); return CCE_PUNCT;
|
---|
694 | "[:space:]" BEGIN(CCL); return CCE_SPACE;
|
---|
695 | "[:upper:]" BEGIN(CCL); return CCE_UPPER;
|
---|
696 | "[:xdigit:]" BEGIN(CCL); return CCE_XDIGIT;
|
---|
697 | {CCL_EXPR} {
|
---|
698 | format_synerr(
|
---|
699 | _( "bad character class expression: %s" ),
|
---|
700 | yytext );
|
---|
701 | BEGIN(CCL); return CCE_ALNUM;
|
---|
702 | }
|
---|
703 | }
|
---|
704 |
|
---|
705 | <NUM>{
|
---|
706 | [[:digit:]]+ {
|
---|
707 | yylval = myctoi( yytext );
|
---|
708 | return NUMBER;
|
---|
709 | }
|
---|
710 |
|
---|
711 | "," return ',';
|
---|
712 | "}" {
|
---|
713 | BEGIN(SECT2);
|
---|
714 | if ( lex_compat || posix_compat )
|
---|
715 | return END_REPEAT_POSIX;
|
---|
716 | else
|
---|
717 | return END_REPEAT_FLEX;
|
---|
718 | }
|
---|
719 |
|
---|
720 | . {
|
---|
721 | synerr( _( "bad character inside {}'s" ) );
|
---|
722 | BEGIN(SECT2);
|
---|
723 | return '}';
|
---|
724 | }
|
---|
725 |
|
---|
726 | {NL} {
|
---|
727 | synerr( _( "missing }" ) );
|
---|
728 | BEGIN(SECT2);
|
---|
729 | ++linenum;
|
---|
730 | return '}';
|
---|
731 | }
|
---|
732 | }
|
---|
733 |
|
---|
734 |
|
---|
735 | <PERCENT_BRACE_ACTION>{
|
---|
736 | {OPTWS}"%}".* bracelevel = 0;
|
---|
737 |
|
---|
738 | <ACTION>"/*" ACTION_ECHO; yy_push_state( COMMENT );
|
---|
739 |
|
---|
740 | <CODEBLOCK,ACTION>{
|
---|
741 | "reject" {
|
---|
742 | ACTION_ECHO;
|
---|
743 | CHECK_REJECT(yytext);
|
---|
744 | }
|
---|
745 | "yymore" {
|
---|
746 | ACTION_ECHO;
|
---|
747 | CHECK_YYMORE(yytext);
|
---|
748 | }
|
---|
749 | }
|
---|
750 |
|
---|
751 | {NAME}|{NOT_NAME}|. ACTION_ECHO;
|
---|
752 | {NL} {
|
---|
753 | ++linenum;
|
---|
754 | ACTION_ECHO;
|
---|
755 | if ( bracelevel == 0 ||
|
---|
756 | (doing_codeblock && indented_code) )
|
---|
757 | {
|
---|
758 | if ( doing_rule_action )
|
---|
759 | add_action( "\tYY_BREAK\n" );
|
---|
760 |
|
---|
761 | doing_rule_action = doing_codeblock = false;
|
---|
762 | BEGIN(SECT2);
|
---|
763 | }
|
---|
764 | }
|
---|
765 | }
|
---|
766 |
|
---|
767 |
|
---|
768 | /* Reject and YYmore() are checked for above, in PERCENT_BRACE_ACTION */
|
---|
769 | <ACTION>{
|
---|
770 | "{" ACTION_ECHO; ++bracelevel;
|
---|
771 | "}" ACTION_ECHO; --bracelevel;
|
---|
772 | [^[:alpha:]_{}"'/\n]+ ACTION_ECHO;
|
---|
773 | {NAME} ACTION_ECHO;
|
---|
774 | "'"([^'\\\n]|\\.)*"'" ACTION_ECHO; /* character constant */
|
---|
775 | \" ACTION_ECHO; BEGIN(ACTION_STRING);
|
---|
776 | {NL} {
|
---|
777 | ++linenum;
|
---|
778 | ACTION_ECHO;
|
---|
779 | if ( bracelevel == 0 )
|
---|
780 | {
|
---|
781 | if ( doing_rule_action )
|
---|
782 | add_action( "\tYY_BREAK\n" );
|
---|
783 |
|
---|
784 | doing_rule_action = false;
|
---|
785 | BEGIN(SECT2);
|
---|
786 | }
|
---|
787 | }
|
---|
788 | . ACTION_ECHO;
|
---|
789 | }
|
---|
790 |
|
---|
791 | <ACTION_STRING>{
|
---|
792 | [^"\\\n]+ ACTION_ECHO;
|
---|
793 | \\. ACTION_ECHO;
|
---|
794 | {NL} ++linenum; ACTION_ECHO; BEGIN(ACTION);
|
---|
795 | \" ACTION_ECHO; BEGIN(ACTION);
|
---|
796 | . ACTION_ECHO;
|
---|
797 | }
|
---|
798 |
|
---|
799 | <COMMENT,ACTION,ACTION_STRING><<EOF>> {
|
---|
800 | synerr( _( "EOF encountered inside an action" ) );
|
---|
801 | yyterminate();
|
---|
802 | }
|
---|
803 |
|
---|
804 |
|
---|
805 | <SECT2,QUOTE,FIRSTCCL,CCL>{ESCSEQ} {
|
---|
806 | yylval = myesc( (Char *) yytext );
|
---|
807 |
|
---|
808 | if ( YY_START == FIRSTCCL )
|
---|
809 | BEGIN(CCL);
|
---|
810 |
|
---|
811 | return CHAR;
|
---|
812 | }
|
---|
813 |
|
---|
814 |
|
---|
815 | <SECT3>{
|
---|
816 | .*(\n?) ECHO;
|
---|
817 | <<EOF>> sectnum = 0; yyterminate();
|
---|
818 | }
|
---|
819 |
|
---|
820 | <*>.|\n format_synerr( _( "bad character: %s" ), yytext );
|
---|
821 |
|
---|
822 | %%
|
---|
823 |
|
---|
824 |
|
---|
825 | int yywrap()
|
---|
826 | {
|
---|
827 | if ( --num_input_files > 0 )
|
---|
828 | {
|
---|
829 | set_input_file( *++input_files );
|
---|
830 | return 0;
|
---|
831 | }
|
---|
832 |
|
---|
833 | else
|
---|
834 | return 1;
|
---|
835 | }
|
---|
836 |
|
---|
837 |
|
---|
838 | /* set_input_file - open the given file (if NULL, stdin) for scanning */
|
---|
839 |
|
---|
840 | void set_input_file( file )
|
---|
841 | char *file;
|
---|
842 | {
|
---|
843 | if ( file && strcmp( file, "-" ) )
|
---|
844 | {
|
---|
845 | infilename = copy_string( file );
|
---|
846 | yyin = fopen( infilename, "r" );
|
---|
847 |
|
---|
848 | if ( yyin == NULL )
|
---|
849 | lerrsf( _( "can't open %s" ), file );
|
---|
850 | }
|
---|
851 |
|
---|
852 | else
|
---|
853 | {
|
---|
854 | yyin = stdin;
|
---|
855 | infilename = copy_string( "<stdin>" );
|
---|
856 | }
|
---|
857 |
|
---|
858 | linenum = 1;
|
---|
859 | }
|
---|
860 |
|
---|
861 |
|
---|
862 | /* Wrapper routines for accessing the scanner's malloc routines. */
|
---|
863 |
|
---|
864 | void *flex_alloc( size )
|
---|
865 | size_t size;
|
---|
866 | {
|
---|
867 | return (void *) malloc( size );
|
---|
868 | }
|
---|
869 |
|
---|
870 | void *flex_realloc( ptr, size )
|
---|
871 | void *ptr;
|
---|
872 | size_t size;
|
---|
873 | {
|
---|
874 | return (void *) realloc( ptr, size );
|
---|
875 | }
|
---|
876 |
|
---|
877 | void flex_free( ptr )
|
---|
878 | void *ptr;
|
---|
879 | {
|
---|
880 | if ( ptr )
|
---|
881 | free( ptr );
|
---|
882 | }
|
---|