Fix unescaping in matlab, miniMAL and rpython.
authorJoel Martin <github@martintribe.org>
Tue, 26 Sep 2017 15:34:49 +0000 (10:34 -0500)
committerJoel Martin <github@martintribe.org>
Thu, 28 Sep 2017 12:40:47 +0000 (07:40 -0500)
matlab/reader.m
miniMAL/reader.json
rpython/reader.py

index ada1af6..8cea773 100644 (file)
@@ -16,9 +16,10 @@ classdef reader
                 atm = str2double(token);
             elseif strcmp(token(1), '"')
                 atm = token(2:length(token)-1);
+                atm = strrep(atm, '\\', char(255));
                 atm = strrep(atm, '\"', '"');
                 atm = strrep(atm, '\n', char(10));
-                atm = strrep(atm, '\\', '\');
+                atm = strrep(atm, char(255), '\');
             elseif strcmp(token(1), ':')
                 s = token(2:end);
                 atm = type_utils.keyword(s);
index d9ceedd..830158e 100644 (file)
       ["parseInt", "token", 10],
     ["if", ["=", ["`", "\""], ["get", "token", 0]],
       [".",
-        [".",
-          [".",
-            ["slice", "token", 1, ["-", ["count", "token"], 1]],
-            ["`", "replace"], ["RegExp", ["`", "\\\\\""], ["`", "g"]], ["`", "\""]],
-          ["`", "replace"], ["RegExp", ["`", "\\\\n"], ["`", "g"]], ["`", "\n"]],
-        ["`", "replace"], ["RegExp", ["`", "\\\\\\\\"], ["`", "g"]], ["`", "\\"]],
+        ["slice", "token", 1, ["-", ["count", "token"], 1]],
+        ["`", "replace"], ["RegExp", ["`", "\\\\(.)"], ["`", "g"]],
+                          ["fn", ["_", "c"],
+                            ["if", ["=", "c", ["`", "n"]],
+                              ["`", "\n"],
+                              "c"]]],
     ["if", ["=", ["`", ":"], ["get", "token", 0]],
       ["keyword", ["slice", "token", 1]],
     ["if", ["=", ["`", "nil"], "token"],
index 1e5acf6..5f8af46 100644 (file)
@@ -51,9 +51,10 @@ def read_atom(reader):
             return MalStr(u"")
         else:
             s = unicode(token[1:end])
+            s = types._replace(u'\\\\', u"\u029e", s)
             s = types._replace(u'\\"', u'"', s)
             s = types._replace(u'\\n', u"\n", s)
-            s = types._replace(u'\\\\', u"\\", s)
+            s = types._replace(u"\u029e", u"\\", s)
             return MalStr(s)
     elif token[0] == ':':           return _keywordu(unicode(token[1:]))
     elif token == "nil":            return types.nil