Commits

Waldemar Kornewald committed fe17b0a

fixed unicode strings

Comments (0)

Files changed (3)

pyvascript/grammar.py

 from pymeta.grammar import OMeta
+import json
 import os
 
 def compile(source):
 
 translator_path = os.path.join(os.path.dirname(__file__), 'translator.ometa')
 pyva_translator = open(translator_path, 'r').read()
-class Translator(OMeta.makeGrammar(pyva_translator, {'p': p})):
+class Translator(OMeta.makeGrammar(pyva_translator, {'p': p, 'json': json})):
     op_map = {
         'not': '!',
     }

pyvascript/stdlib.pyva

                                  self.append(item)
 Array.prototype.index = Array.prototype.indexOf
 
+String.prototype.index = String.prototype.indexOf
 String.prototype.join = def(self, iterable):
                             return iterable.join(self)
+String.prototype.lower = String.prototype.toLowerCase
+String.prototype.upper = String.prototype.toUpperCase
+
 
 def isinstance(item, cls):
     if JS('cls instanceof Array'):

pyvascript/translator.ometa

 name      :n       -> self.get_name(n)
 number    :n       -> str(n)
 hexnumber :n       -> hex(n)
-string    :s       -> "'%s'" % s.encode('utf8').encode('string_escape').decode('utf8')
+string    :s       -> json.dumps(s)
 
 new  expr:c                  -> 'new %s' % c