[antlr-interest] Ignoring special comment lines

Matthew Ford Matthew.Ford at forward.com.au
Tue Feb 5 13:09:23 PST 2002


here is a version that starts with //

// Single-line comments
SL_COMMENT
 : "//"
  (~('\n'|'\r'))* NEWLINE
  {$setType(Token.SKIP);}
 ;


NEWLINE
  : ( /* '\r' '\n' can be matched in one alternative or by matching
    '\r' in one iteration and '\n' in another.  I am trying to
    handle any flavor of newline that comes in, but the language
    that allows both "\r\n" and "\r" and "\n" to all be valid
    newline is ambiguous.  Consequently, the resulting grammar
    must be ambiguous.  I'm shutting this warning off.
    */
    options {
    generateAmbigWarnings=false;
   }
   : '\r' '\n'   // DOS
   | '\r'  // Macintosh
   | '\n' // Unix
   )  {newline();}
;

matthew
----- Original Message -----
From: "miguelpinheiro2000" <miguelpinheiro2000 at yahoo.com>
To: <antlr-interest at yahoogroups.com>
Sent: Tuesday, February 05, 2002 9:25 PM
Subject: [antlr-interest] Ignoring special comment lines


> Hi!
> I would like to define a Lexer rule to match everything between ';'
> and the end of line and ignore it (except de ';'). I have allready
> defined a SEMI rule as
>
> SEMI : ';';
>
> because I'm interested to pass it to the Parser.
>
> The typical text file I would like to parse is in this format:
>
> <comand 1>;
> <comand 2>; ignored comment
> <comand 3>; ignored comment 2
> <comand 4>;
>
> Any help would be appreciated.
> Thank you,
>
> Miguel
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list