Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / flex / dist / scan.l
blob5f1d70b5297efb37780df1780ba894862ce941b2
1 /*      $NetBSD: scan.l,v 1.1.1.1 2009/10/26 00:26:55 christos Exp $    */
3 /* scan.l - scanner for flex input -*-C-*- */
5 %{
6 /*  Copyright (c) 1990 The Regents of the University of California. */
7 /*  All rights reserved. */
9 /*  This code is derived from software contributed to Berkeley by */
10 /*  Vern Paxson. */
12 /*  The United States Government has rights in this work pursuant */
13 /*  to contract no. DE-AC03-76SF00098 between the United States */
14 /*  Department of Energy and the University of California. */
16 /*  This file is part of flex. */
18 /*  Redistribution and use in source and binary forms, with or without */
19 /*  modification, are permitted provided that the following conditions */
20 /*  are met: */
22 /*  1. Redistributions of source code must retain the above copyright */
23 /*     notice, this list of conditions and the following disclaimer. */
24 /*  2. Redistributions in binary form must reproduce the above copyright */
25 /*     notice, this list of conditions and the following disclaimer in the */
26 /*     documentation and/or other materials provided with the distribution. */
28 /*  Neither the name of the University nor the names of its contributors */
29 /*  may be used to endorse or promote products derived from this software */
30 /*  without specific prior written permission. */
32 /*  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
33 /*  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
34 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
35 /*  PURPOSE. */
37 #include "flexdef.h"
38 #include "parse.h"
39 extern bool tablesverify, tablesext;
40 extern int trlcontxt; /* Set in  parse.y for each rule. */
41 extern const char *escaped_qstart, *escaped_qend;
43 #define ACTION_ECHO add_action( yytext )
44 #define ACTION_IFDEF(def, should_define) \
45         { \
46         if ( should_define ) \
47                 action_define( def, 1 ); \
48         }
50 #define ACTION_ECHO_QSTART add_action (escaped_qstart)
51 #define ACTION_ECHO_QEND   add_action (escaped_qend)
53 #define ACTION_M4_IFDEF(def, should_define) \
54     do{ \
55         if ( should_define ) \
56             buf_m4_define( &m4defs_buf, def, NULL);\
57         else \
58             buf_m4_undefine( &m4defs_buf, def);\
59     } while(0)
61 #define MARK_END_OF_PROLOG mark_prolog();
63 #define YY_DECL \
64         int flexscan()
66 #define RETURNCHAR \
67         yylval = (unsigned char) yytext[0]; \
68         return CHAR;
70 #define RETURNNAME \
71         if(yyleng < MAXLINE) \
72          { \
73         strlcpy( nmstr, yytext, sizeof(nmstr) ); \
74          } \
75         else \
76          { \
77            synerr(_("Input line too long\n")); \
78            FLEX_EXIT(EXIT_FAILURE);  \
79          }  \
80         return NAME;
82 #define PUT_BACK_STRING(str, start) \
83         for ( i = strlen( str ) - 1; i >= start; --i ) \
84                 unput((str)[i])
86 #define CHECK_REJECT(str) \
87         if ( all_upper( str ) ) \
88                 reject = true;
90 #define CHECK_YYMORE(str) \
91         if ( all_lower( str ) ) \
92                 yymore_used = true;
94 #define YY_USER_INIT \
95         if ( getenv("POSIXLY_CORRECT") ) \
96                 posix_compat = true;
100 %option caseless nodefault stack noyy_top_state
101 %option nostdinit
103 %x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE
104 %x FIRSTCCL CCL ACTION RECOVER COMMENT ACTION_STRING PERCENT_BRACE_ACTION
105 %x OPTION LINEDIR CODEBLOCK_MATCH_BRACE
106 %x GROUP_WITH_PARAMS
107 %x GROUP_MINUS_PARAMS
108 %x EXTENDED_COMMENT
109 %x COMMENT_DISCARD
111 WS              [[:blank:]]+
112 OPTWS           [[:blank:]]*
113 NOT_WS          [^[:blank:]\r\n]
115 NL              \r?\n
117 NAME            ([[:alpha:]_][[:alnum:]_-]*)
118 NOT_NAME        [^[:alpha:]_*\n]+
120 SCNAME          {NAME}
122 ESCSEQ          (\\([^\n]|[0-7]{1,3}|x[[:xdigit:]]{1,2}))
124 FIRST_CCL_CHAR  ([^\\\n]|{ESCSEQ})
125 CCL_CHAR        ([^\\\n\]]|{ESCSEQ})
126 CCL_EXPR        ("[:"^?[[:alpha:]]+":]")
128 LEXOPT          [aceknopr]
130 M4QSTART    "[["
131 M4QEND      "]]"
134         static int bracelevel, didadef, indented_code;
135         static int doing_rule_action = false;
136         static int option_sense;
138         int doing_codeblock = false;
139         int i, brace_depth=0, brace_start_line=0;
140         Char nmdef[MAXLINE];
143 <INITIAL>{
144         ^{WS}           indented_code = true; BEGIN(CODEBLOCK);
145         ^"/*"           ACTION_ECHO; yy_push_state( COMMENT );
146         ^#{OPTWS}line{WS}       yy_push_state( LINEDIR );
147         ^"%s"{NAME}?    return SCDECL;
148         ^"%x"{NAME}?    return XSCDECL;
149         ^"%{".*{NL}     {
150                         ++linenum;
151                         line_directive_out( (FILE *) 0, 1 );
152                         indented_code = false;
153                         BEGIN(CODEBLOCK);
154                         }
155     ^"%top"[[:blank:]]*"{"[[:blank:]]*{NL}    {
156                 brace_start_line = linenum;
157                 ++linenum;
158                 buf_linedir( &top_buf, infilename?infilename:"<stdin>", linenum);
159                 brace_depth = 1;
160                 yy_push_state(CODEBLOCK_MATCH_BRACE);
161             }
163     ^"%top".*   synerr( _("malformed '%top' directive") );
165         {WS}            /* discard */
167         ^"%%".*         {
168                         sectnum = 2;
169                         bracelevel = 0;
170                         mark_defs1();
171                         line_directive_out( (FILE *) 0, 1 );
172                         BEGIN(SECT2PROLOG);
173                         return SECTEND;
174                         }
176         ^"%pointer".*{NL}       yytext_is_array = false; ++linenum;
177         ^"%array".*{NL}         yytext_is_array = true; ++linenum;
179         ^"%option"      BEGIN(OPTION); return OPTION_OP;
181         ^"%"{LEXOPT}{OPTWS}[[:digit:]]*{OPTWS}{NL}      ++linenum; /* ignore */
182         ^"%"{LEXOPT}{WS}.*{NL}  ++linenum;      /* ignore */
184         /* xgettext: no-c-format */
185         ^"%"[^sxaceknopr{}].*   synerr( _( "unrecognized '%' directive" ) );
187         ^{NAME}         {
188                         if(yyleng < MAXLINE)
189                          {
190                         strlcpy( nmstr, yytext, sizeof(nmstr) );
191                          }
192                         else
193                          {
194                            synerr( _("Input line too long\n"));
195                            FLEX_EXIT(EXIT_FAILURE);
196                          }
198                         didadef = false;
199                         BEGIN(PICKUPDEF);
200                         }
202         {SCNAME}        RETURNNAME;
203         ^{OPTWS}{NL}    ++linenum; /* allows blank lines in section 1 */
204         {OPTWS}{NL}     ACTION_ECHO; ++linenum; /* maybe end of comment line */
208 <COMMENT>{
209         "*/"            ACTION_ECHO; yy_pop_state();
210         "*"             ACTION_ECHO;
211     {M4QSTART}  ACTION_ECHO_QSTART;
212     {M4QEND}    ACTION_ECHO_QEND;
213         [^*\n]      ACTION_ECHO;
214         {NL}        ++linenum; ACTION_ECHO;
217 <COMMENT_DISCARD>{
218         /* This is the same as COMMENT, but is discarded rather than output. */
219         "*/"            yy_pop_state();
220     "*"         ;
221         [^*\n]      ;
222         {NL}        ++linenum;
225 <EXTENDED_COMMENT>{
226     ")"         yy_pop_state();
227     [^\n\)]+      ;
228     {NL}        ++linenum;        
231 <LINEDIR>{
232         \n              yy_pop_state();
233         [[:digit:]]+    linenum = myctoi( yytext );
235         \"[^"\n]*\"     {
236                         flex_free( (void *) infilename );
237                         infilename = copy_string( yytext + 1 );
238                         infilename[strlen( infilename ) - 1] = '\0';
239                         }
240         .               /* ignore spurious characters */
243 <CODEBLOCK>{
244         ^"%}".*{NL}     ++linenum; BEGIN(INITIAL);
246     {M4QSTART}  ACTION_ECHO_QSTART;
247     {M4QEND}    ACTION_ECHO_QEND;
248         .               ACTION_ECHO;
250         {NL}            {
251                         ++linenum;
252                         ACTION_ECHO;
253                         if ( indented_code )
254                                 BEGIN(INITIAL);
255                         }
258 <CODEBLOCK_MATCH_BRACE>{
259     "}"     {
260                 if( --brace_depth == 0){
261                     /* TODO: Matched. */
262                     yy_pop_state();
263                 }else
264                     buf_strnappend(&top_buf, yytext, yyleng);
265             }
267     "{"     {
268                 brace_depth++;
269                 buf_strnappend(&top_buf, yytext, yyleng);
270             }
272     {NL}    {
273                 ++linenum;
274                 buf_strnappend(&top_buf, yytext, yyleng);
275             }
277     {M4QSTART}  buf_strnappend(&top_buf, escaped_qstart, strlen(escaped_qstart));
278     {M4QEND}    buf_strnappend(&top_buf, escaped_qend, strlen(escaped_qend));
280     [^{}\r\n]  {
281                 buf_strnappend(&top_buf, yytext, yyleng);
282                }
284     <<EOF>>     {
285                 linenum = brace_start_line;
286                 synerr(_("Unmatched '{'"));
287                 yyterminate();
288                 }
292 <PICKUPDEF>{
293         {WS}            /* separates name and definition */
295         {NOT_WS}[^\r\n]*        {
296                         if(yyleng < MAXLINE)
297                          {
298                         strlcpy( (char *) nmdef, yytext, sizeof(nmdef) );
299                          }
300                         else
301                          {
302                            synerr( _("Input line too long\n"));
303                            FLEX_EXIT(EXIT_FAILURE);
304                          }
305                         /* Skip trailing whitespace. */
306                         for ( i = strlen( (char *) nmdef ) - 1;
307                               i >= 0 && (nmdef[i] == ' ' || nmdef[i] == '\t');
308                               --i )
309                                 ;
311                         nmdef[i + 1] = '\0';
313                         ndinstal( nmstr, nmdef );
314                         didadef = true;
315                         }
317         {NL}            {
318                         if ( ! didadef )
319                                 synerr( _( "incomplete name definition" ) );
320                         BEGIN(INITIAL);
321                         ++linenum;
322                         }
326 <OPTION>{
327         {NL}            ++linenum; BEGIN(INITIAL);
328         {WS}            option_sense = true;
330         "="             return '=';
332         no              option_sense = ! option_sense;
334         7bit            csize = option_sense ? 128 : 256;
335         8bit            csize = option_sense ? 256 : 128;
337         align           long_align = option_sense;
338         always-interactive      {
339                         ACTION_M4_IFDEF( "M4""_YY_ALWAYS_INTERACTIVE", option_sense );
340             interactive = option_sense;
341                         }
342         array           yytext_is_array = option_sense;
343     ansi-definitions ansi_func_defs = option_sense;
344     ansi-prototypes  ansi_func_protos = option_sense;
345         backup          backing_up_report = option_sense;
346         batch           interactive = ! option_sense;
347     bison-bridge     bison_bridge_lval = option_sense;
348     bison-locations  { if((bison_bridge_lloc = option_sense))
349                             bison_bridge_lval = true;
350                      }
351         "c++"           C_plus_plus = option_sense;
352         caseful|case-sensitive          sf_set_case_ins(!option_sense);
353         caseless|case-insensitive       sf_set_case_ins(option_sense);
354         debug           ddebug = option_sense;
355         default         spprdflt = ! option_sense;
356         ecs             useecs = option_sense;
357         fast            {
358                         useecs = usemecs = false;
359                         use_read = fullspd = true;
360                         }
361         full            {
362                         useecs = usemecs = false;
363                         use_read = fulltbl = true;
364                         }
365         input           ACTION_IFDEF("YY_NO_INPUT", ! option_sense);
366         interactive     interactive = option_sense;
367         lex-compat      lex_compat = option_sense;
368         posix-compat    posix_compat = option_sense;
369         main            {
370                         ACTION_M4_IFDEF( "M4""_YY_MAIN", option_sense);
371             /* Override yywrap */
372             if( option_sense == true )
373                 do_yywrap = false;
374                         }
375         meta-ecs        usemecs = option_sense;
376         never-interactive       {
377                         ACTION_M4_IFDEF( "M4""_YY_NEVER_INTERACTIVE", option_sense );
378             interactive = !option_sense;
379                         }
380         perf-report     performance_report += option_sense ? 1 : -1;
381         pointer         yytext_is_array = ! option_sense;
382         read            use_read = option_sense;
383     reentrant   reentrant = option_sense;
384         reject          reject_really_used = option_sense;
385         stack           ACTION_M4_IFDEF( "M4""_YY_STACK_USED", option_sense );
386         stdinit         do_stdinit = option_sense;
387         stdout          use_stdout = option_sense;
388     unistd      ACTION_IFDEF("YY_NO_UNISTD_H", ! option_sense);
389         unput           ACTION_M4_IFDEF("M4""_YY_NO_UNPUT", ! option_sense);
390         verbose         printstats = option_sense;
391         warn            nowarn = ! option_sense;
392         yylineno        do_yylineno = option_sense; ACTION_M4_IFDEF("M4""_YY_USE_LINENO", option_sense);
393         yymore          yymore_really_used = option_sense;
394         yywrap      do_yywrap = option_sense;
396         yy_push_state   ACTION_M4_IFDEF("M4""_YY_NO_PUSH_STATE", ! option_sense);
397         yy_pop_state    ACTION_M4_IFDEF("M4""_YY_NO_POP_STATE", ! option_sense);
398         yy_top_state    ACTION_M4_IFDEF("M4""_YY_NO_TOP_STATE", ! option_sense);
400         yy_scan_buffer  ACTION_M4_IFDEF("M4""_YY_NO_SCAN_BUFFER", ! option_sense);
401         yy_scan_bytes   ACTION_M4_IFDEF("M4""_YY_NO_SCAN_BYTES", ! option_sense);
402         yy_scan_string  ACTION_M4_IFDEF("M4""_YY_NO_SCAN_STRING", ! option_sense);
404     yyalloc         ACTION_M4_IFDEF("M4""_YY_NO_FLEX_ALLOC", ! option_sense);
405     yyrealloc       ACTION_M4_IFDEF("M4""_YY_NO_FLEX_REALLOC", ! option_sense);
406     yyfree          ACTION_M4_IFDEF("M4""_YY_NO_FLEX_FREE", ! option_sense);
408     yyget_debug     ACTION_M4_IFDEF("M4""_YY_NO_GET_DEBUG", ! option_sense);
409     yyset_debug     ACTION_M4_IFDEF("M4""_YY_NO_SET_DEBUG", ! option_sense);
410     yyget_extra     ACTION_M4_IFDEF("M4""_YY_NO_GET_EXTRA", ! option_sense);
411     yyset_extra     ACTION_M4_IFDEF("M4""_YY_NO_SET_EXTRA", ! option_sense);
412     yyget_leng      ACTION_M4_IFDEF("M4""_YY_NO_GET_LENG", ! option_sense);
413     yyget_text      ACTION_M4_IFDEF("M4""_YY_NO_GET_TEXT", ! option_sense);
414     yyget_lineno    ACTION_M4_IFDEF("M4""_YY_NO_GET_LINENO", ! option_sense);
415     yyset_lineno    ACTION_M4_IFDEF("M4""_YY_NO_SET_LINENO", ! option_sense);
416     yyget_in        ACTION_M4_IFDEF("M4""_YY_NO_GET_IN", ! option_sense);
417     yyset_in        ACTION_M4_IFDEF("M4""_YY_NO_SET_IN", ! option_sense);
418     yyget_out       ACTION_M4_IFDEF("M4""_YY_NO_GET_OUT", ! option_sense);
419     yyset_out       ACTION_M4_IFDEF("M4""_YY_NO_SET_OUT", ! option_sense);
420     yyget_lval      ACTION_M4_IFDEF("M4""_YY_NO_GET_LVAL", ! option_sense);
421     yyset_lval      ACTION_M4_IFDEF("M4""_YY_NO_SET_LVAL", ! option_sense);
422     yyget_lloc      ACTION_M4_IFDEF("M4""_YY_NO_GET_LLOC", ! option_sense);
423     yyset_lloc      ACTION_M4_IFDEF("M4""_YY_NO_SET_LLOC", ! option_sense);
425         extra-type      return OPT_EXTRA_TYPE;
426         outfile         return OPT_OUTFILE;
427         prefix          return OPT_PREFIX;
428         yyclass         return OPT_YYCLASS;
429         header(-file)?      return OPT_HEADER;
430         tables-file         return OPT_TABLES;
431         tables-verify   {
432                     tablesverify = option_sense;
433                     if(!tablesext && option_sense)
434                         tablesext = true;
435                     }
438         \"[^"\n]*\"     {
439                         if(yyleng-1 < MAXLINE)
440                          {
441                         strlcpy( nmstr, yytext + 1, sizeof(nmstr) );
442                          }
443                         else
444                          {
445                            synerr( _("Input line too long\n"));
446                            FLEX_EXIT(EXIT_FAILURE);
447                          }
448                         nmstr[strlen( nmstr ) - 1] = '\0';
449                         return NAME;
450                         }
452         (([a-mo-z]|n[a-np-z])[[:alpha:]\-+]*)|. {
453                         format_synerr( _( "unrecognized %%option: %s" ),
454                                 yytext );
455                         BEGIN(RECOVER);
456                         }
459 <RECOVER>.*{NL}         ++linenum; BEGIN(INITIAL);
462 <SECT2PROLOG>{
463         ^"%{".* ++bracelevel; yyless( 2 );      /* eat only %{ */
464         ^"%}".* --bracelevel; yyless( 2 );      /* eat only %} */
466         ^{WS}.* ACTION_ECHO;    /* indented code in prolog */
468         ^{NOT_WS}.*     {       /* non-indented code */
469                         if ( bracelevel <= 0 )
470                                 { /* not in %{ ... %} */
471                                 yyless( 0 );    /* put it all back */
472                                 yy_set_bol( 1 );
473                                 mark_prolog();
474                                 BEGIN(SECT2);
475                                 }
476                         else
477                                 ACTION_ECHO;
478                         }
480         .               ACTION_ECHO;
481         {NL}    ++linenum; ACTION_ECHO;
483         <<EOF>>         {
484                         mark_prolog();
485                         sectnum = 0;
486                         yyterminate(); /* to stop the parser */
487                         }
490 <SECT2>{
491         ^{OPTWS}{NL}    ++linenum; /* allow blank lines in section 2 */
493         ^{OPTWS}"%{"    {
494                         indented_code = false;
495                         doing_codeblock = true;
496                         bracelevel = 1;
497                         BEGIN(PERCENT_BRACE_ACTION);
498                         }
500         ^{OPTWS}"<"         {
501                         /* Allow "<" to appear in (?x) patterns. */
502                         if (!sf_skip_ws())
503                             BEGIN(SC);
504                         return '<';
505                     }
506         ^{OPTWS}"^"     return '^';
507         \"              BEGIN(QUOTE); return '"';
508         "{"/[[:digit:]] {
509                         BEGIN(NUM);
510                         if ( lex_compat || posix_compat )
511                                 return BEGIN_REPEAT_POSIX;
512                         else
513                                 return BEGIN_REPEAT_FLEX;
514                         }
515         "$"/([[:blank:]]|{NL})  return '$';
517         {WS}"%{"                {
518                         bracelevel = 1;
519                         BEGIN(PERCENT_BRACE_ACTION);
521                         if ( in_rule )
522                                 {
523                                 doing_rule_action = true;
524                                 in_rule = false;
525                                 return '\n';
526                                 }
527                         }
528         {WS}"|".*{NL}   {
529                         if (sf_skip_ws()){
530                             /* We're in the middle of a (?x: ) pattern. */
531                             /* Push back everything starting at the "|" */
532                             size_t amt;
533                             amt = strchr (yytext, '|') - yytext;
534                             yyless(amt);
535                         }
536                         else {
537                             continued_action = true;
538                             ++linenum;
539                             return '\n';
540                         }
541                     }
543         ^{WS}"/*"       {
545                 if (sf_skip_ws()){
546                     /* We're in the middle of a (?x: ) pattern. */
547                     yy_push_state(COMMENT_DISCARD);
548                 }
549                 else{
550                     yyless( yyleng - 2 );       /* put back '/', '*' */
551                     bracelevel = 0;
552                     continued_action = false;
553                     BEGIN(ACTION);
554                 }
555                         }
557         ^{WS}           /* allow indented rules */ ;
559         {WS}            {
560             if (sf_skip_ws()){
561                 /* We're in the middle of a (?x: ) pattern. */
562             }
563             else{
564                 /* This rule is separate from the one below because
565                  * otherwise we get variable trailing context, so
566                  * we can't build the scanner using -{f,F}.
567                  */
568                 bracelevel = 0;
569                 continued_action = false;
570                 BEGIN(ACTION);
572                 if ( in_rule )
573                     {
574                     doing_rule_action = true;
575                     in_rule = false;
576                     return '\n';
577                     }
578             }
579                         }
581         {OPTWS}{NL}     {
582             if (sf_skip_ws()){
583                 /* We're in the middle of a (?x: ) pattern. */
584                 ++linenum;
585             }
586             else{
587                 bracelevel = 0;
588                 continued_action = false;
589                 BEGIN(ACTION);
590                 unput( '\n' );  /* so <ACTION> sees it */
592                 if ( in_rule )
593                     {
594                     doing_rule_action = true;
595                     in_rule = false;
596                     return '\n';
597                     }
598             }
599                         }
601         ^{OPTWS}"<<EOF>>"       |
602         "<<EOF>>"       return EOF_OP;
604         ^"%%".*         {
605                         sectnum = 3;
606                         BEGIN(SECT3);
607                         outn("/* Begin user sect3 */");
608                         yyterminate(); /* to stop the parser */
609                         }
611         "["({FIRST_CCL_CHAR}|{CCL_EXPR})({CCL_CHAR}|{CCL_EXPR})*        {
612                         int cclval;
614                         if(yyleng < MAXLINE)
615                          {
616                         strlcpy( nmstr, yytext, sizeof(nmstr) );
617                          }
618                         else
619                          {
620                            synerr( _("Input line too long\n"));
621                            FLEX_EXIT(EXIT_FAILURE);
622                          }
624                         /* Check to see if we've already encountered this
625                          * ccl.
626                          */
627                         if (0 /* <--- This "0" effectively disables the reuse of a
628                    * character class (purely based on its source text).
629                    * The reason it was disabled is so yacc/bison can parse
630                    * ccl operations, such as ccl difference and union.
631                    */
632                 &&  (cclval = ccllookup( (Char *) nmstr )) != 0 )
633                                 {
634                                 if ( input() != ']' )
635                                         synerr( _( "bad character class" ) );
637                                 yylval = cclval;
638                                 ++cclreuse;
639                                 return PREVCCL;
640                                 }
641                         else
642                                 {
643                                 /* We fudge a bit.  We know that this ccl will
644                                  * soon be numbered as lastccl + 1 by cclinit.
645                                  */
646                                 cclinstal( (Char *) nmstr, lastccl + 1 );
648                                 /* Push back everything but the leading bracket
649                                  * so the ccl can be rescanned.
650                                  */
651                                 yyless( 1 );
653                                 BEGIN(FIRSTCCL);
654                                 return '[';
655                                 }
656                         }
657     "{-}"       return CCL_OP_DIFF;
658     "{+}"       return CCL_OP_UNION;
661     /* Check for :space: at the end of the rule so we don't
662      * wrap the expanded regex in '(' ')' -- breaking trailing
663      * context.
664      */
665         "{"{NAME}"}"[[:space:]]?         {
666                         register Char *nmdefptr;
667             int end_is_ws, end_ch;
669             end_ch = yytext[yyleng-1];
670             end_is_ws = end_ch != '}' ? 1 : 0;
672                         if(yyleng-1 < MAXLINE)
673                          {
674                         strlcpy( nmstr, yytext + 1, sizeof(nmstr) );
675                          }
676                         else
677                          {
678                            synerr( _("Input line too long\n"));
679                            FLEX_EXIT(EXIT_FAILURE);
680                          }
681 nmstr[yyleng - 2 - end_is_ws] = '\0';  /* chop trailing brace */
683                         if ( (nmdefptr = ndlookup( nmstr )) == 0 )
684                                 format_synerr(
685                                         _( "undefined definition {%s}" ),
686                                                 nmstr );
688                         else
689                                 { /* push back name surrounded by ()'s */
690                                 int len = strlen( (char *) nmdefptr );
691                 if (end_is_ws)
692                     unput(end_ch);
694                                 if ( lex_compat || nmdefptr[0] == '^' ||
695                                      (len > 0 && nmdefptr[len - 1] == '$')
696                      || (end_is_ws && trlcontxt && !sf_skip_ws()))
697                                         { /* don't use ()'s after all */
698                                         PUT_BACK_STRING((char *) nmdefptr, 0);
700                                         if ( nmdefptr[0] == '^' )
701                                                 BEGIN(CARETISBOL);
702                                         }
704                                 else
705                                         {
706                                         unput(')');
707                                         PUT_BACK_STRING((char *) nmdefptr, 0);
708                                         unput('(');
709                                         }
710                                 }
711                         }
713     "/*"        {
714                     if (sf_skip_ws())
715                         yy_push_state(COMMENT_DISCARD);
716                     else{
717                         /* Push back the "*" and return "/" as usual. */
718                         yyless(1);
719                         return '/';
720                     }
721                 }
723     "(?#"       {
724                     if (lex_compat || posix_compat){
725                         /* Push back the "?#" and treat it like a normal parens. */
726                         yyless(1);
727                         sf_push(); 
728                         return '(';
729                     }
730                     else
731                         yy_push_state(EXTENDED_COMMENT);
732                 }
733     "(?"        {
734                     sf_push();
735                     if (lex_compat || posix_compat)
736                         /* Push back the "?" and treat it like a normal parens. */
737                         yyless(1);
738                     else
739                         BEGIN(GROUP_WITH_PARAMS);
740                     return '(';
741                 }
742     "("         sf_push(); return '(';
743     ")"         sf_pop(); return ')';
745         [/|*+?.(){}]    return (unsigned char) yytext[0];
746         .               RETURNCHAR;
750 <SC>{
751         {OPTWS}{NL}{OPTWS}      ++linenum;      /* Allow blank lines & continuations */
752         [,*]            return (unsigned char) yytext[0];
753         ">"             BEGIN(SECT2); return '>';
754         ">"/^           BEGIN(CARETISBOL); return '>';
755         {SCNAME}        RETURNNAME;
756         .               {
757                         format_synerr( _( "bad <start condition>: %s" ),
758                                 yytext );
759                         }
762 <CARETISBOL>"^"         BEGIN(SECT2); return '^';
765 <QUOTE>{
766         [^"\n]          RETURNCHAR;
767         \"              BEGIN(SECT2); return '"';
769         {NL}            {
770                         synerr( _( "missing quote" ) );
771                         BEGIN(SECT2);
772                         ++linenum;
773                         return '"';
774                         }
777 <GROUP_WITH_PARAMS>{
778     ":"     BEGIN(SECT2);
779     "-"     BEGIN(GROUP_MINUS_PARAMS);
780     i       sf_set_case_ins(1);
781     s       sf_set_dot_all(1);
782     x       sf_set_skip_ws(1);
784 <GROUP_MINUS_PARAMS>{
785     ":"     BEGIN(SECT2);
786     i       sf_set_case_ins(0);
787     s       sf_set_dot_all(0);
788     x       sf_set_skip_ws(0);
791 <FIRSTCCL>{
792         "^"/[^-\]\n]    BEGIN(CCL); return '^';
793         "^"/("-"|"]")   return '^';
794         .               BEGIN(CCL); RETURNCHAR;
797 <CCL>{
798         -/[^\]\n]       return '-';
799         [^\]\n]         RETURNCHAR;
800         "]"             BEGIN(SECT2); return ']';
801         .|{NL}          {
802                         synerr( _( "bad character class" ) );
803                         BEGIN(SECT2);
804                         return ']';
805                         }
808 <FIRSTCCL,CCL>{
809         "[:alnum:]"     BEGIN(CCL); return CCE_ALNUM;
810         "[:alpha:]"     BEGIN(CCL); return CCE_ALPHA;
811         "[:blank:]"     BEGIN(CCL); return CCE_BLANK;
812         "[:cntrl:]"     BEGIN(CCL); return CCE_CNTRL;
813         "[:digit:]"     BEGIN(CCL); return CCE_DIGIT;
814         "[:graph:]"     BEGIN(CCL); return CCE_GRAPH;
815         "[:lower:]"     BEGIN(CCL); return CCE_LOWER;
816         "[:print:]"     BEGIN(CCL); return CCE_PRINT;
817         "[:punct:]"     BEGIN(CCL); return CCE_PUNCT;
818         "[:space:]"     BEGIN(CCL); return CCE_SPACE;
819         "[:upper:]"     BEGIN(CCL); return CCE_UPPER;
820         "[:xdigit:]"    BEGIN(CCL); return CCE_XDIGIT;
822         "[:^alnum:]"    BEGIN(CCL); return CCE_NEG_ALNUM;
823         "[:^alpha:]"    BEGIN(CCL); return CCE_NEG_ALPHA;
824         "[:^blank:]"    BEGIN(CCL); return CCE_NEG_BLANK;
825         "[:^cntrl:]"    BEGIN(CCL); return CCE_NEG_CNTRL;
826         "[:^digit:]"    BEGIN(CCL); return CCE_NEG_DIGIT;
827         "[:^graph:]"    BEGIN(CCL); return CCE_NEG_GRAPH;
828         "[:^lower:]"    BEGIN(CCL); return CCE_NEG_LOWER;
829         "[:^print:]"    BEGIN(CCL); return CCE_NEG_PRINT;
830         "[:^punct:]"    BEGIN(CCL); return CCE_NEG_PUNCT;
831         "[:^space:]"    BEGIN(CCL); return CCE_NEG_SPACE;
832         "[:^upper:]"    BEGIN(CCL); return CCE_NEG_UPPER;
833         "[:^xdigit:]"   BEGIN(CCL); return CCE_NEG_XDIGIT;
834         {CCL_EXPR}      {
835                         format_synerr(
836                                 _( "bad character class expression: %s" ),
837                                         yytext );
838                         BEGIN(CCL); return CCE_ALNUM;
839                         }
842 <NUM>{
843         [[:digit:]]+    {
844                         yylval = myctoi( yytext );
845                         return NUMBER;
846                         }
848         ","             return ',';
849         "}"             {
850                         BEGIN(SECT2);
851                         if ( lex_compat || posix_compat )
852                                 return END_REPEAT_POSIX;
853                         else
854                                 return END_REPEAT_FLEX;
855                         }
857         .               {
858                         synerr( _( "bad character inside {}'s" ) );
859                         BEGIN(SECT2);
860                         return '}';
861                         }
863         {NL}            {
864                         synerr( _( "missing }" ) );
865                         BEGIN(SECT2);
866                         ++linenum;
867                         return '}';
868                         }
872 <PERCENT_BRACE_ACTION>{
873         {OPTWS}"%}".*           bracelevel = 0;
875         <ACTION>"/*"            ACTION_ECHO; yy_push_state( COMMENT );
877         <CODEBLOCK,ACTION>{
878                 "reject"        {
879                         ACTION_ECHO;
880                         CHECK_REJECT(yytext);
881                         }
882                 "yymore"        {
883                         ACTION_ECHO;
884                         CHECK_YYMORE(yytext);
885                         }
886         }
888     {M4QSTART}  ACTION_ECHO_QEND;
889     {M4QEND}    ACTION_ECHO_QEND;
890     .           ACTION_ECHO;
891         {NL}            {
892                         ++linenum;
893                         ACTION_ECHO;
894                         if ( bracelevel == 0 ||
895                              (doing_codeblock && indented_code) )
896                                 {
897                                 if ( doing_rule_action )
898                                         add_action( "\tYY_BREAK\n" );
900                                 doing_rule_action = doing_codeblock = false;
901                                 BEGIN(SECT2);
902                                 }
903                         }
907         /* Reject and YYmore() are checked for above, in PERCENT_BRACE_ACTION */
908 <ACTION>{
909         "{"             ACTION_ECHO; ++bracelevel;
910         "}"             ACTION_ECHO; --bracelevel;
911     {M4QSTART}  ACTION_ECHO_QEND;
912     {M4QEND}    ACTION_ECHO_QEND;
913         [^[:alpha:]_{}"'/\n\[\]]+       ACTION_ECHO;
914     [\[\]]      ACTION_ECHO;
915         {NAME}          ACTION_ECHO;
916         "'"([^'\\\n]|\\.)*"'"   ACTION_ECHO; /* character constant */
917         \"              ACTION_ECHO; BEGIN(ACTION_STRING);
918         {NL}            {
919                         ++linenum;
920                         ACTION_ECHO;
921                         if ( bracelevel == 0 )
922                                 {
923                                 if ( doing_rule_action )
924                                         add_action( "\tYY_BREAK\n" );
926                                 doing_rule_action = false;
927                                 BEGIN(SECT2);
928                                 }
929                         }
930         .               ACTION_ECHO;
933 <ACTION_STRING>{
934         [^"\\\n]+       ACTION_ECHO;
935         \\.             ACTION_ECHO;
936         {NL}            ++linenum; ACTION_ECHO; BEGIN(ACTION);
937         \"              ACTION_ECHO; BEGIN(ACTION);
938         .               ACTION_ECHO;
941 <COMMENT,COMMENT_DISCARD,ACTION,ACTION_STRING><<EOF>>   {
942                         synerr( _( "EOF encountered inside an action" ) );
943                         yyterminate();
944                         }
946 <EXTENDED_COMMENT,GROUP_WITH_PARAMS,GROUP_MINUS_PARAMS><<EOF>>  {
947                         synerr( _( "EOF encountered inside pattern" ) );
948                         yyterminate();
949                         }
951 <SECT2,QUOTE,FIRSTCCL,CCL>{ESCSEQ}      {
952                         yylval = myesc( (Char *) yytext );
954                         if ( YY_START == FIRSTCCL )
955                                 BEGIN(CCL);
957                         return CHAR;
958                         }
961 <SECT3>{
962     {M4QSTART}  fwrite (escaped_qstart, 1, strlen(escaped_qstart), yyout);
963     {M4QEND}    fwrite (escaped_qend, 1, strlen(escaped_qend), yyout);
964         [^\[\]\n]*(\n?) ECHO;
965         (.|\n)      ECHO;
966         <<EOF>>         sectnum = 0; yyterminate();
969 <*>.|\n                 format_synerr( _( "bad character: %s" ), yytext );
974 int yywrap()
975         {
976         if ( --num_input_files > 0 )
977                 {
978                 set_input_file( *++input_files );
979                 return 0;
980                 }
982         else
983                 return 1;
984         }
987 /* set_input_file - open the given file (if NULL, stdin) for scanning */
989 void set_input_file( file )
990 char *file;
991         {
992         if ( file && strcmp( file, "-" ) )
993                 {
994                 infilename = copy_string( file );
995                 yyin = fopen( infilename, "r" );
997                 if ( yyin == NULL )
998                         lerrsf( _( "can't open %s" ), file );
999                 }
1001         else
1002                 {
1003                 yyin = stdin;
1004                 infilename = copy_string( "<stdin>" );
1005                 }
1007         linenum = 1;
1008         }
1011 /* Wrapper routines for accessing the scanner's malloc routines. */
1013 void *flex_alloc( size )
1014 size_t size;
1015         {
1016         return (void *) malloc( size );
1017         }
1019 void *flex_realloc( ptr, size )
1020 void *ptr;
1021 size_t size;
1022         {
1023         return (void *) realloc( ptr, size );
1024         }
1026 void flex_free( ptr )
1027 void *ptr;
1028         {
1029         if ( ptr )
1030                 free( ptr );
1031         }