
|
If you were logged in you would be able to see more operations.
|
|
|
ANTLR v3
Created: 13/Mar/08 11:23 AM
Updated: 02/May/08 04:51 PM
|
|
| Component/s: |
All targets
|
| Affects Version/s: |
3.0.1
|
| Fix Version/s: |
3.1
|
|
|
Jim Idle wrote:
I was dreaming about this last night - I know, it's sad - but when I woke up I thought of something that shuodl be easy:
1. Add integer ruleDepth; to the state
2. Reset it to zero in nextToken
3. Each lexer rule increments and decrements it
Then, depending on how much you want people to have to change grammar for 3.1, either:
Just add $ruledepth and a template state.ruleDepth and tell people to use:
$ruledepth == 1 $type = TTTT : null;
boy this sure sounds familiar! i thought i did a ruleLevel thing once to set token type...let's keep this on radar to fix.
Or, add dummy locals (or dummy int and String in state) so that the template for say $type is:
(state.ruledepth == 1 state.type ? _type)
And then have:
$super::type
$super::channel
And so on, which don't check the state.ruleDepth as they just set it and the next thing that does emit() or returns to nextToken picks it up correctly.
Trivial change for uses either way around. I kind of like super:: as it might be useful for other things later, but your call of course.
|
|
Description
|
Jim Idle wrote:
I was dreaming about this last night - I know, it's sad - but when I woke up I thought of something that shuodl be easy:
1. Add integer ruleDepth; to the state
2. Reset it to zero in nextToken
3. Each lexer rule increments and decrements it
Then, depending on how much you want people to have to change grammar for 3.1, either:
Just add $ruledepth and a template state.ruleDepth and tell people to use:
$ruledepth == 1 $type = TTTT : null;
boy this sure sounds familiar! i thought i did a ruleLevel thing once to set token type...let's keep this on radar to fix.
Or, add dummy locals (or dummy int and String in state) so that the template for say $type is:
(state.ruledepth == 1 state.type ? _type)
And then have:
$super::type
$super::channel
And so on, which don't check the state.ruleDepth as they just set it and the next thing that does emit() or returns to nextToken picks it up correctly.
Trivial change for uses either way around. I kind of like super:: as it might be useful for other things later, but your call of course.
|
Show » |
|
X : ID WS? '=' ID ; // result is X on normal channel
WS : ' '+ {$channel = HIDDEN; } ;
STRING : '"' (ESC|.)* '"' ; // result is STRING not ESC
FLOAT : INT '.' INT? ; // should be FLOAT
INT : Digit+ ;
fragment
Digit : '0'..'9' ;
So i made $channel also a local. At end of each nonfragment lexer rule, i copy locals to state object. You might set line or char position etc... but those are likely global attributes. This is an inconsistent impl perhaps but a *minimal* runtime template change at this late stage.
Jim, it still won't work for
X : ... {$type=Y; emit();} ;
but, shouldn't you really do:
X : ... {$type=Y; emit(A_TOKEN);} ;
as emit() is default at end of X?
I only changed two lines to make this work "better" now. Later we can optimize out local alloc/copy.