[antlr-interest] Antlr grammar for xml like grammar

Ymo ymo.mail at gmail.com
Tue Aug 26 09:40:11 PDT 2008


Hi matt i apreciate you taking a look at this.

I pasted the reduced input & grammar:

The first line is never recognized as TOK_PI. It is always seen as TOK_CODE.

Input is :
«@»
«fgdsfgs»
«%-- comment --%»

then i reduced the grammar to this

tokens {
    LG='\u00ab';
    RG='\u00bb';
}


//LEXER
TOK_PI : LG '@';
TOK_LCOMMENT : '%-';
TOK_RCOMMENT : '-%';

TOK_BLOCK : { tagMode==false }? =>
   (LG TOK_LCOMMENT) => TOK_COMMENT { $type=TOK_COMMENT; } |
   (TOK_PI) => TOK_PI { $type=TOK_PI; } |
   (LG ) => TOK_CODE { $type=TOK_CODE; } |
   TOK_TEXT { $type=TOK_TEXT; }  {
   };

fragment
TOK_TEXT :
   ( ~(LG|RG) )+ {
    };

fragment
TOK_CODE :
   LG  ( options {k=2;greedy=false;} : . )*  RG {
    };

fragment
TOK_COMMENT :
   LG TOK_LCOMMENT ( options {k=3;greedy=false;} : . )* TOK_RCOMMENT RG {
      $channel=HIDDEN;
    };
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080826/dcef8f6e/attachment.html 


More information about the antlr-interest mailing list