[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 */
This document was generated on November 4, 2011 using texi2html 5.0.