[antlr-interest] C and #define

Paul Keir paul at paulkeir.com
Mon May 21 02:08:24 PDT 2007


Hi,

I'm building on the C grammar from the examples, and would like to 
modify the lexer rule which ignores lines starting with #; I'd like not 
to ignore #define, but ignore the rest. Currently the rule is:

// ignore #line info for now
LINE_COMMAND
    : '#' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
    ;

Remembering that the # can be separated from the define, I've tried a 
few things like this:

// ignore #line info for now
LINE_COMMAND
    :  ~( '#' 'define' | '#define' ) ~('\n'|'\r')* '\r'? '\n' 
{$channel=HIDDEN;}
    ;

but I can't get it to work as intended. Can anyone offer a suggestion?

Best regards,
Paul


-- 
512k Broadband £14.99 per month
Unlimited Downloads - No extra Costs
£14.99 per month (inc. VAT)
Order Now www.adsl4less.com


More information about the antlr-interest mailing list