Provide handler to support non-returning states
The fast lexer generator for Java
Brought to you by:
lsf37,
steve_rowe
In the lexer you often return the new state, but that's not required. I'd like to be able to catch all cases. Those who return a state are easy to catch, the others not.
If would be nice to add something like
%defaultreturn {
%defaultreturn }
where you can add some lines of code if it's not returned during the switch
it should be placed right after the switch, so
switch (zzBufferL[zzCurrentPosL]) {
//a lot of cases and a default
}
/* include lines of defaultreturn here */
And/or a try/finally statement around the switch to catch them all, no matter what.
Only with one of these solutions I will be able to catch them all.
To give an idea why we need such solution: we're working on a streaming parser, which means we'll write while reading to keep the output as much as the same as the input. While writing we want to use eventhandlers to select certain states to slightly modify them. Untill now we parsed the input to a model and wrote that to a file, but this way some data might get lost (comments, indents, etc.). That's why we need to catch every loop.
example :
try {
switch (zzBufferL[zzCurrentPosL]) {
//a lot of cases and a default
}
finally {
%statehandler%
}
}