Revision: 4137
          http://vexi.svn.sourceforge.net/vexi/?rev=4137&view=rev
Author:   mkpg2
Date:     2011-05-13 02:57:51 +0000 (Fri, 13 May 2011)

Log Message:
-----------
Feature. Multiline strings.

Modified Paths:
--------------
    trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/parse/Lexer.jpp
    
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/TestGeneral.java

Added Paths:
-----------
    
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/multiline_string.js

Modified: trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/parse/Lexer.jpp
===================================================================
--- trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/parse/Lexer.jpp  
2011-05-13 00:54:34 UTC (rev 4136)
+++ trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/parse/Lexer.jpp  
2011-05-13 02:57:51 UTC (rev 4137)
@@ -207,18 +207,53 @@
     }
     
     private int getString(int c) throws IOException {
-        StringBuffer stringBuf = null;
-        int quoteChar = c;
-        c = in.read();
-        in.startString(); // start after the first "
-        while(c != quoteChar) {
-            if (c == '\n' || c == -1) throw new LexerException("unterminated 
string literal");
+        boolean multiline = false;
+        int quoteChar = c;     //1
+        c = in.read();         //2
+        if(c==quoteChar){
+            c = in.read();     //3
+            if(c!=quoteChar){
+                in.unread();
+                this.string = "";
+                return STRING;
+            }else{
+                multiline = true;
+                c = in.read();
+            }
+        }
+        
+        // REMARK: avoid StringBuffer in SmartReader since we need to micro 
manage which chars are added due to the escaping.
+        StringBuffer stringBuf = new StringBuffer(); 
+        while(true) {
+            if(c==quoteChar){
+                if(multiline){
+                    c = in.read();        //2
+                    if(c==quoteChar){
+                        c = in.read();    //3
+                        if(c==quoteChar){
+                            break;
+                        }else{
+                            // double
+                            stringBuf.append((char)quoteChar);
+                            stringBuf.append((char)quoteChar);
+                        }
+                    }else{
+                        // single
+                        stringBuf.append((char)quoteChar);
+                    }
+                    
+                }else{
+                    break;
+                }
+            }
+            
+            
+            if (c == '\n' || c == -1) {
+                if(c!='\n' || !multiline){
+                    throw new LexerException("unterminated string literal");
+                }
+            }
             if (c == '\\') {
-                if (stringBuf == null) {
-                    in.unread();   // Don't include the backslash
-                    stringBuf = new StringBuffer(in.getString());
-                    in.read();
-                }
                 switch (c = in.read()) {
                 case 'b': c = '\b'; break;
                 case 'f': c = '\f'; break;
@@ -243,18 +278,13 @@
                     break;
                 }
             }
-            if (stringBuf != null) stringBuf.append((char) c);
-            c = in.read();
+            stringBuf.append((char) c);
+            c = in.read();                //1
         }
-        if (stringBuf != null) this.string = stringBuf.toString().intern();
-        else {
-            in.unread(); // miss the trailing "
-            this.string = in.getString().intern();
-            in.read();
-        }
+        this.string = stringBuf.toString().intern();
         return STRING;
     }
-
+                    
     private int _getToken() throws IOException {
         int c;
         do { c = in.read(); } while (c == '\u0020' || c == '\u0009' || c == 
'\u000C' || c == '\u000B' || c == '\n' || c == '\r');

Modified: 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/TestGeneral.java
===================================================================
--- 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/TestGeneral.java   
    2011-05-13 00:54:34 UTC (rev 4136)
+++ 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/TestGeneral.java   
    2011-05-13 02:57:51 UTC (rev 4137)
@@ -16,7 +16,7 @@
     public static void main(String[] args) throws Throwable {
        try{
                JSTestSuite jts = new JSTestSuite(TestGeneral.class);
-               JSTestCase t = jts.createTestCase(jts.getResourceDirs(), 
"varargs.js");
+               JSTestCase t = jts.createTestCase(jts.getResourceDirs(), 
"multiline_string.js");
                //t.printByteCode();
                t.runBare();
        }catch(Throwable t){

Added: 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/multiline_string.js
===================================================================
--- 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/multiline_string.js
                            (rev 0)
+++ 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/multiline_string.js
    2011-05-13 02:57:51 UTC (rev 4137)
@@ -0,0 +1,18 @@
+assert("""""".length==0);
+assert(""""""=="");
+assert("this\n    is a multiline string\n"=="""this
+    is a multiline string
+""");
+
+assert("".length==0);
+assert(" ".length==1);
+
+
+assert("".length==0);
+
+
+assert(' " '== """ " """);
+assert(' "" '== """ "" """);
+
+
+


Property changes on: 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/multiline_string.js
___________________________________________________________________
Added: svn:mime-type
   + text/plain


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to