[antlr-interest] Parsing documentation comments (with nesting!) (v3)

Rick Mann rmann at latencyzero.com
Wed Feb 21 19:49:07 PST 2007


On Feb 21, 2007, at 19:36 , Rick Mann wrote:

> COMMENT
>     :    '/*' ( options {greedy=false;} : . )* '*/'
>     ;
>
> I've tried this, and it works fine, but I can't get at the text of  
> the comment. I tried labeling the subrule, but it didn't like that.  
> So I tried this:
>
> COMMENT
>     :    '/*'! COMMENTTEXT '*/'! { System.out.println("Found a  
> comment [" + $COMMENTTEXT.text + "]"); }
>     ;
>
> fragment
> COMMENTTEXT
> options
> {
>     greedy = false;
> }
>     :    .*
>     ;
>
> But I get "The following alternatives are unreachable: 1".


I noticed one error in the above: the '*" should go after  
"COMMENTTEXT" in the COMMENT rule, but then I can't reference  
$COMMENTTEXT (I get other errors).



More information about the antlr-interest mailing list