[pypy-svn] r40521 - in pypy/dist/pypy/lang/js: . js

santagada at codespeak.net santagada at codespeak.net
Thu Mar 15 06:18:28 CET 2007


Author: santagada
Date: Thu Mar 15 06:18:26 2007
New Revision: 40521

Modified:
   pypy/dist/pypy/lang/js/js/jsparse.js
   pypy/dist/pypy/lang/js/jsparser.py
   pypy/dist/pypy/lang/js/operations.py
Log:
improving the escaping, one bit at a time


Modified: pypy/dist/pypy/lang/js/js/jsparse.js
==============================================================================
--- pypy/dist/pypy/lang/js/js/jsparse.js	(original)
+++ pypy/dist/pypy/lang/js/js/jsparse.js	Thu Mar 15 06:18:26 2007
@@ -157,7 +157,7 @@
             var id = match[0];
             token.type = keywords[id] || IDENTIFIER;
             token.value = id;
-        } else if ((match = /^"(?:\\.|[^"])*"|^'(?:[^']|\\.)*'/(input))) { //"){
+        } else if ((match = /^"(?:\\.|[^"])*"|^'(?:\\.|[^'])*'/(input))) { //"){
             token.type = STRING;
             token.value = match[0];
         } else if (this.scanOperand &&

Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py	(original)
+++ pypy/dist/pypy/lang/js/jsparser.py	Thu Mar 15 06:18:26 2007
@@ -11,7 +11,7 @@
 from pypy.rlib.parsing.ebnfparse import Symbol
 from pypy.rlib.streamio import open_file_as_stream, fdopen_as_stream
 
-DEBUG = False
+DEBUG = True
 
 class JsSyntaxError(Exception):
     pass
@@ -23,16 +23,38 @@
 fname = path.join(path.dirname(__file__) ,"tobeparsed.js")
 command = 'js -f %s -f %s -f %s'%(jsdefspath, jsparsepath, fname)
 
+escapes = [
+    r'\n',
+    r'\r',
+    r'\f',
+    r'\v',
+    r'\ ',
+    r'\t',
+    r"\'",
+    r'\b',
+    r'\"',
+    r'\\']
+
+codes = [
+    '\n',
+    '\r',
+    '\f',
+    '\v',
+    '\ ',
+    '\t',
+    "'",
+    "\b",
+    '"',
+    '\\']
+
+escapedict = dict(zip(codes,escapes))
+
 def read_js_output(code_string):
     tmp = []
     last = ""
     for c in code_string:
-        if c == "'":
-            tmp.append("\\'")
-        elif c == SLASH:
-            tmp.append(SLASH*2)
-        elif c == "\n":
-            tmp.append("\\n")
+        if c in escapedict:
+            tmp.append(escapedict[c])
         else:
             tmp.append(c)
         last = c

Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py	(original)
+++ pypy/dist/pypy/lang/js/operations.py	Thu Mar 15 06:18:26 2007
@@ -781,8 +781,13 @@
 
     escapedict = { 
         r'\n' : '\n',
+        r'\r' : '\r',
+        r'\f' : '\f',
+        r'\v' : '\v',
+        r'\ ' : '\ ',
         r'\t' : '\t',
-        r"\'" : "'",
+	    r"\'" : "'",
+	    r"\b" : "\b",
         r'\"' : '"',
         r'\\' : '\\'
     }



More information about the Pypy-commit mailing list