[antlr-interest] Match a repetition of characters

Douglas Godfrey douglasgodfrey at gmail.com
Fri Jun 24 08:39:10 PDT 2011


underline returns [char symbol]
 : underlineAtom {$symbol=$underlineAtom.text} {$symbol}+ LINE_BREAK
 ;

underlineAtom
 : ( UNDERSCORE UNDERSCORE UNDERSCORE UNDERSCORE+ )
 | ( STAR STAR STAR STAR+ )
 | ( PIPE PIPE PIPE PIPE+ )
 | ( BACKTICK BACKTICK BACKTICK BACKTICK+ )
 | ( COLUMN COLUMN COLUMN COLUMN+ )
 | ( SPECIAL_CHAR SPECIAL_CHAR SPECIAL_CHAR SPECIAL_CHAR+ )
 ;



On Fri, Jun 24, 2011 at 6:02 AM, Robin <diabeteman at gmail.com> wrote:

> Hello everyone,
>
> I'm trying to write a rule that matches the repetition (4 or more) of the
> same special character
>
> For example:
>
> "^^^^^^^^^^^^^^^^^^^^"
>
> or
>
> "________________"
>
> I have these lexer rules :
>
> UNDERSCORE : '_';
> BACKTICK : '`';
> STAR : '*';
> PIPE : '|';
> COLUMN : ':';
> SPECIAL_CHAR :
>
> ('!'|'"'|'#'|'$'|'%'|'&'|'\''|'('|')'|'+'|','|'.'|'/'|';'|'<'|'='|'>'|'?'|'@'|'['|'\\'|']'|'^'|'{'|'}'|'~');
> LINE_BREAK : '\u000C'?'\r'?'\n';
>
> And I'd like to write a parser rule named "underline" that only matches if
> this is a repetition of *the same character* and that returns this
> character. So that enclosing rules can use it.
>
> For now I wrote this:
>
> underline returns [char symbol]
>  : underlineAtom {$symbol=$underlineAtom.text} {$symbol}+ LINE_BREAK
>  ;
>
> underlineAtom
>  : UNDERSCORE
>  | STAR
>  | PIPE
>  | BACKTICK
>  | COLUMN
>  | SPECIAL_CHAR
>  ;
>
> But my grammar does not compile...
>
> Can someone help me on this ? :)
>
> Thanks
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list