[antlr-interest] Excaping quotation characters in quoted strings - javascript target

James Robson james.robson at ymail.com
Sun Jul 26 22:05:11 PDT 2009


Don't worry I've solved the problem. It was my lack of JavaScript knowledge..



________________________________
From: James Robson <james.robson at ymail.com>
To: antlr-interest at antlr.org
Sent: Monday, 27 July, 2009 2:52:23 PM
Subject: [antlr-interest] Excaping quotation characters in quoted strings - javascript target


HI, I'm trying to allow escape sequencs in quoted strings  using the java script target.

I've a similar implementation using the Java Target which works without any problems. It seems that the ext is not available when using the javascirpt target.

Does anyone know how this could be solved for the javascript target?

Below are the lexer rules:


TEXT        
@init{var lBuf = "";}
    :   
           QUOTATION_MARK
           ( escaped=ESC {lBuf = lBuf.concat(this.getText());} | 
             normal=~(QUOTATION_MARK|'\\'|'\n'|'\r')     {lBuf = lBuf.concat(String.fromCharCode(normal));} )* 
           QUOTATION_MARK    
           {this.setText("\"".concat(lBuf, "\""));}
    ;

fragment
ESC
    :   '\\'
        (       'n'    {this.setText("\n");}
        |       'r'    {this.setText("\r");}
        |       't'    {this.setText("\t");}
        |       'b'    {this.setText("\b");}
        |       'f'    {this.setText("\f");}
        |       '"'    {this.setText("\\\"");}
        |       '\''   {this.setText("\'");}
        |       '\\'   {this.setText("\\");}
        )
    ;

QUOTATION_MARK
  : '"'
  ;

________________________________
 Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how.


      ____________________________________________________________________________________
Access Yahoo!7 Mail on your mobile. Anytime. Anywhere.
Show me how: http://au.mobile.yahoo.com/mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090726/71bb8505/attachment.html 


More information about the antlr-interest mailing list