[antlr-interest] RE : Problem with new lines

Sharon Li hushlee83 at yahoo.com.sg
Wed Feb 5 15:31:15 PST 2003


hmm..seems like it still doesn't work, but thanks anyway.
angle factor: 10   //--> exception after first line
initial color: 1 5
color increment: 1 10
initial line width: 5 pixels
// another comment
line width increment: 0
..............
An exception occurs straight after the first line. I can't figure where the problem lies. The previous codes works well with this but it doesn't work once I insert a newline after "angle factor:10":

/************ input file with new line inserted *******************/

angle factor: 10


initial color: 1 5
color increment: 1 10
initial line width: 5 pixels
// another comment
line width increment: 0
...............

 Anthony_Brenelière <abreneliere at telys.com> wrote:
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/ 


 Yahoo! Travel
- Valentine surprise deals. Book now!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030206/9b4cde8a/attachment.html


More information about the antlr-interest mailing list