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

James Robson james.robson at ymail.com
Sun Jul 26 21:52:23 PDT 2009


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: http://au.mobile.yahoo.com/mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090726/b3b491b2/attachment.html 


More information about the antlr-interest mailing list