diff src/jscomp.sml @ 646:fb2a0e76dcef

ListEdit demo, minus prose
author Adam Chlipala <adamc@hcoop.net>
date Tue, 10 Mar 2009 12:44:40 -0400
parents b98f547a6a45
children 96ebc6bdb5a0
line wrap: on
line diff
--- a/src/jscomp.sml	Tue Mar 10 11:18:01 2009 -0400
+++ b/src/jscomp.sml	Tue Mar 10 12:44:40 2009 -0400
@@ -409,6 +409,12 @@
                       Print.prefaces "Can't unurlify" [("t", MonoPrint.p_typ MonoEnv.empty t)];
                       ("ERROR", st))
 
+        fun padWith (ch, s, len) =
+            if size s < len then
+                padWith (ch, String.str ch ^ s, len - 1)
+            else
+                s
+
         fun jsExp mode skip outer =
             let
                 val len = length outer
@@ -448,7 +454,16 @@
                                                             else
                                                                 "\\074"
                                                           | #"\\" => "\\\\"
-                                                          | ch => String.str ch) s
+                                                          | #"\n" => "\\n"
+                                                          | #"\r" => "\\r"
+                                                          | #"\t" => "\\t"
+                                                          | ch =>
+                                                            if Char.isPrint ch then
+                                                                String.str ch
+                                                            else
+                                                                "\\" ^ padWith (#"0",
+                                                                                Int.fmt StringCvt.OCT (ord ch),
+                                                                                3)) s
                                      ^ "\"")
                               | _ => str (Prim.toString p)
 
@@ -878,6 +893,15 @@
                           | EDml _ => unsupported "DML"
                           | ENextval _ => unsupported "Nextval"
                           | EUnurlify _ => unsupported "EUnurlify"
+                          | EJavaScript (_, e as (EAbs _, _), _) =>
+                            let
+                                val (e, st) = jsE inner (e, st)
+                            in
+                                (strcat [str "\"cr(\"+ca(",
+                                         e,
+                                         str ")+\")\""],
+                                 st)
+                            end
                           | EJavaScript (_, e, _) =>
                             let
                                 val (e, st) = jsE inner (e, st)