[antlr-interest] How to discard comment text when catching source code part?
Auber Lin
auberlin at hotmail.com
Sun Mar 23 23:42:31 PDT 2008
hi ANTLR users,
i tried to get some part of c source code like the following syntax expression:
function_definitionscope { ModifierText; DeclText; LBLine; LBOffset; DeclLine; DeclOffset;}@init { $function_definition::ModifierText = ''; $function_definition::DeclText = ''; $function_definition::LBLine = 0; $function_definition::LBOffset = 0; $function_definition::DeclLine = 0; $function_definition::DeclOffset = 0;}@after{ self.StoreFunctionDefinition($function_definition.start.line, $function_definition.start.charPositionInLine, $function_definition.stop.line, $function_definition.stop.charPositionInLine, $function_definition::ModifierText, $function_definition::DeclText, $function_definition::LBLine, $function_definition::LBOffset, $function_definition::DeclLine, $function_definition::DeclOffset)} : d=declaration_specifiers? declarator ( declaration+ a=compound_statement // K&R style | b=compound_statement // ANSI style ) { if d != None: $function_definition::ModifierText = $declaration_specifiers.text else: $function_definition::ModifierText = '' $function_definition::DeclText = $declarator.text $function_definition::DeclLine = $declarator.start.line $function_definition::DeclOffset = $declarator.start.charPositionInLine if a != None: $function_definition::LBLine = $a.start.line $function_definition::LBOffset = $a.start.charPositionInLine else: $function_definition::LBLine = $b.start.line $function_definition::LBOffset = $b.start.charPositionInLine } ;
it works fine for most cases except for the comments exists in the function parameter list part, like this:
STATUS
SetParameters ( IN BASE_CODE_PROTOCOL *This, IN BOOLEAN *NewAutoArp, OPTIONAL IN BOOLEAN *NewSendGUID, OPTIONAL IN UINT8 *NewTTL, OPTIONAL IN UINT8 *NewToS, OPTIONAL IN BOOLEAN *NewMakeCallback // Make callback indicator
)
the comment part after '//' is also picked out as a part of function.
i already have set hidden channel for comments, i don't know why they still appear in the text i picked out.
LINE_COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} ;
is there any option of ANTLR that could make me get the no-comment code context?
Cheers!
Auber
_________________________________________________________________
Test your Star IQ
http://club.live.com/red_carpet_reveal.aspx?icid=redcarpet_HMTAGMAR
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080324/7ad7b295/attachment.html
More information about the antlr-interest
mailing list