[pypy-svn] r40558 - pypy/dist/pypy/lang/js

santagada at codespeak.net santagada at codespeak.net
Thu Mar 15 22:01:30 CET 2007


Author: santagada
Date: Thu Mar 15 22:01:28 2007
New Revision: 40558

Added:
   pypy/dist/pypy/lang/js/constants.py
Modified:
   pypy/dist/pypy/lang/js/jsparser.py
   pypy/dist/pypy/lang/js/operations.py
Log:
finishing touches on the quoting stuff


Added: pypy/dist/pypy/lang/js/constants.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/constants.py	Thu Mar 15 22:01:28 2007
@@ -0,0 +1,28 @@
+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))
+unescapedict = dict(zip(escapes, codes))
+
+SLASH = "\\"
\ No newline at end of file

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 22:01:28 2007
@@ -10,44 +10,19 @@
 from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
 from pypy.rlib.parsing.ebnfparse import Symbol
 from pypy.rlib.streamio import open_file_as_stream, fdopen_as_stream
+from constants import escapedict
 
-DEBUG = True
+DEBUG = False
 
 class JsSyntaxError(Exception):
     pass
 
-SLASH = "\\"
 jsdir = path.join(path.dirname(__file__),"js")
 jsdefspath = path.join(jsdir, "jsdefs.js")
 jsparsepath = path.join(jsdir, "jsparse.js")
 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 = []

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 22:01:28 2007
@@ -7,8 +7,7 @@
 from pypy.lang.js.jsobj import *
 from pypy.rlib.parsing.ebnfparse import Symbol, Nonterminal
 from pypy.rlib.rarithmetic import r_uint, intmask
-
-SLASH = "\\"
+from constants import unescapedict, SLASH
 
 class Node(object):
     """
@@ -765,8 +764,6 @@
     def eval(self, ctx):
         return W_Number(self.num)
 
-
-
 class String(Expression):
     opcode = 'STRING'
     
@@ -779,18 +776,6 @@
     def get_literal(self):
         return W_String(self.strval).ToString()
 
-    escapedict = { 
-        r'\n' : '\n',
-        r'\r' : '\r',
-        r'\f' : '\f',
-        r'\v' : '\v',
-        r'\ ' : '\ ',
-        r'\t' : '\t',
-	    r"\'" : "'",
-	    r"\b" : "\b",
-        r'\"' : '"',
-        r'\\' : '\\'
-    }
     def string_unquote(self, string):
         temp = []
         stop = len(string)-1
@@ -813,9 +798,9 @@
     
         for c in internalstring:
             if last == SLASH:
-                escapeseq = self.escapedict[last+c]
-                temp.append(escapeseq)
-                last = escapeseq
+                unescapeseq = unescapedict[last+c]
+                temp.append(unescapeseq)
+                last = unescapeseq
                 continue
             if c != SLASH:        
                 temp.append(c)



More information about the Pypy-commit mailing list