Commits

joseanpg  committed 53252cc

Update src/lexer.js

String Token RegExp added

  • Participants
  • Parent commits a5f0272

Comments (0)

Files changed (1)

File src/lexer.js

 );
 
 var NUMBER = /^-?[0-9]+(\.[0-9]+)?/;
+var STRING = /^("|')(?:[^"\\]|\\.)*\1/;
 var COMMENT = /^\/\/.*/;
 var WHITESPACE = /^[^\n\S]+/;
 var INDENT = /^(?:\n[^\n\S]*)+/;
 };
 
 var stringToken = function() {
-    var firstChar = chunk.charAt(0),
-        quoted = false,
-        nextChar;
-    if(firstChar == '"' || firstChar == "'") {
-        for(var i = 1; i < chunk.length; i++) {
-            if(!quoted) {
-                nextChar = chunk.charAt(i);
-                if(nextChar == "\\") {
-                    quoted = true;
-                } else if(nextChar == firstChar) {
-                    tokens.push(['STRING', chunk.substring(0, i + 1), lineno]);
-                    return i + 1;
-                }
-            } else {
-                quoted = false;
-            }
-        }
-    }
-    return 0;
-};
+  var token = STRING.exec(chunk);
+  if (token) {
+    tokens.push(['STRING', token[0], lineno]);
+    return token[0].length;
+    
+  }
+  return 0;
+};    
 
 var genericToken = function() {
     var token = GENERIC.exec(chunk);