[antlr-interest] RE : Problem with new lines

Anthony Brenelière abreneliere at telys.com
Wed Feb 5 15:14:23 PST 2003


Try by adding a ‘+’ behind :

NEWLINE
	: ("\r\n" | '\r' | '\n')+
	{ newline(); $setType(Token.SKIP); }
;

WS
	: (' '|'\t')+
	{ $setType(Token.SKIP); }
;


-----Message d'origine-----
De : Sharon Li [mailto:hushlee83 at yahoo.com.sg] 
Envoyé : jeudi 6 février 2003 00:01
À : Antlr Interest Group
Objet : [antlr-interest] Problem with new lines

Hello,
can anyone help me with this? 
1) My lexer can't seem to recognize newlines. Thanks.
/**************************** Lexer class
***************************************/
class ViewLexer extends Lexer;
options { 
    charVocabulary='\3'..'\377'; 
    filter=true;
    k = 4;
    defaultErrorHandler=false;
}
//protected SYMBOL : (SIGN|'%'|'/'|'.'|','|'*');
protected LETTER : ( 'a'..'z' | 'A'..'Z' ) ; 
protected DIGIT  : ( '0'..'9' ) ; 
protected SIGN   : ('-'|'+');
COLON : ':';
DOT     : '.';
COMMA : ',';
NUMERIC : (SIGN)? (DIGIT)+ ((DOT) (d:DIGIT)*)*
                ;
WORD : (LETTER) (LETTER|DIGIT)*
         ;
            
SL_COMMENT
        :       "//"
                (~('\n'|'\r'))* ('\n'|'\r'('\n')?)?
                {$setType(Token.SKIP); newline();}
        ;
//COMMENT : "/*" (options {greedy=false;} :.)* "*/" ;
NEWLINE : ('\r''\n')=> '\r''\n' 
        | '\r'{newline();}
        | '\n'{newline();}                  
        {
     newline(); 
     $setType(Token.SKIP);
    } 
        ;
WS      : (' '|'\t') { $setType(Token.SKIP); } ;
/**************************************** End of lexer
*************************************/
2)  How can I check for comments. How do I write a parser rule that
allows comments ?
Thanks a lot!!
Yahoo! Travel
- Valentine surprise deals. Book now! 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


 

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



More information about the antlr-interest mailing list