Hi Bart, Thanks! Adding a WS* solved the problem. I use the ELSE because it's kind of reverse filter, I specify what to exclude from input to output.
Regards, Balazs On Mon, Oct 17, 2011 at 11:20 AM, Bart Kiers <[email protected]> wrote: > Hi Balazs, > > Since PC is not a parser rule, you need to account for the space(s) between > 'PC_HASH_VALUE' and DIGIT. > And since you've set `filter=true`, you don't need a fall-through rule > ELSE, AFAIK. > > Regards, > > Bart. > > > On Mon, Oct 17, 2011 at 11:15 AM, Balazs Varnai <[email protected]> wrote: > >> Hi All, >> >> I have a simple grammar to collapse white-spaces and comment from a c >> source >> code input. Also I would like to filter out some variables with a specific >> name. These have a strict format, so no "real" C parsing needed. >> Works fine but for example a line "#define PC_HASH_VALUE 1" is not >> recognized. As far I remember from previous ANTLR usage, this was working >> straight away. Any suggestions? Thanks! >> >> /* **** [ CODE ] **** */ >> lexer grammar Collapse; >> >> options { >> language = Java; >> filter = true; >> } >> @header { >> package rewriter; >> import java.util.*; >> import java.io.*; >> >> } >> >> @members { >> PrintStream out; >> >> public Collapse(CharStream input, PrintStream out) { >> this(input); >> this.out = out; >> } >> } >> >> PC: 'PC_HASH_VALUE' text=DIGIT {$channel=HIDDEN;}; >> >> fragment >> DIGIT: '0'..'9'; >> >> COMMENT >> : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} >> | '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;} >> ; >> >> WS : ( ' ' >> | '\t' >> | '\r' >> | '\n' >> ) {$channel=HIDDEN;} >> ; >> >> ELSE : c=. {out.print((char)$c);} ; // match any char and emit >> /* **** [ END ] **** */ >> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest >> Unsubscribe: >> http://www.antlr.org/mailman/options/antlr-interest/your-email-address >> > > List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
