[antlr-interest] Comments / White-Space and All The Rest

Terence Parr parrt at cs.usfca.edu
Fri Nov 24 12:07:41 PST 2006


forAnnotated
	:	f='fof' ...
		{if ( input.get($f.index-1).getType()==DOC_COMMENT ) {...} }
		...
	;

  In reality you would need a for loop to look backwards so that it  
avoided whitespace, unless of course you use skip on those tokens in  
the lexer.

Ter

On Nov 24, 2006, at 11:57 AM, Randall R Schulz wrote:

> Hi,
>
> Here are the top-level rules for which I'd like to record  
> intervening comments:
>
> fofAnnotated
>     :   'fof'
>         '('
>                 name
>             ',' formulaRole
>             ',' firstOrderFormula
>           ( ',' annotations ) ?
>         ')'
>         Period
>         {
>             acceptFOF($firstOrderFormula.fof, $name.n,  
> $formulaRole.role);
>         }
>     ;
>
>
> cnfAnnotated
>     :   'cnf'
>         '('
>                 name
>             ',' formulaRole
>             ',' clausalFormula
>           ( ',' annotations ) ?
>         ')'
>         Period
>         {
>             acceptCNF($clausalFormula.cf, $name.n, $formulaRole.role);
>         }
>     ;
>
>
> How would I modify them to get at the 'fof' or 'cnf' keyword token  
> so I
> can work backward and find any interstitial comments?
>
>
> Thanks.
>
> Randall Schulz



More information about the antlr-interest mailing list