(flex.info)How do I skip as many chars as possible?


Next: deleteme00 Prev: How do I use my own I/O classes in a C++ scanner? Up: FAQ
Enter node , (file) or (file)node

How do I skip as many chars as possible?
========================================

How do I skip as many chars as possible - without interfering with the
other patterns?

   In the example below, we want to skip over characters until we see
the phrase "endskip".  The following will _NOT_ work correctly (do you
see why not?)

     /* INCORRECT SCANNER */
     %x SKIP
     %%
     <INITIAL>startskip   BEGIN(SKIP);
     ...
     <SKIP>"endskip"       BEGIN(INITIAL);
     <SKIP>.*             ;

   The problem is that the pattern .* will eat up the word "endskip."
The simplest (but slow) fix is:

     <SKIP>"endskip"      BEGIN(INITIAL);
     <SKIP>.              ;

   The fix involves making the second rule match more, without making it
match "endskip" plus something else.  So for example:

     <SKIP>"endskip"     BEGIN(INITIAL);
     <SKIP>[^e]+         ;
     <SKIP>.		        ;/* so you eat up e's, too */


automatically generated by info2www version 1.2.2.9