comparison src/mono_opt.sml @ 2048:4d64af730e35

Differentiate between HTML and normal string literals
author Adam Chlipala <adam@chlipala.net>
date Fri, 01 Aug 2014 15:44:17 -0400
parents 93ff76058825
children 1b76ae703cbb 278e10629ba1
comparison
equal deleted inserted replaced
2047:6be31671911b 2048:4d64af730e35
143 andalso (Char.isLower (String.sub (s, 0)) orelse String.sub (s, 0) = #"_") 143 andalso (Char.isLower (String.sub (s, 0)) orelse String.sub (s, 0) = #"_")
144 andalso CharVector.all (fn ch => Char.isLower ch orelse Char.isDigit ch orelse ch = #"_" orelse ch = #"-") s 144 andalso CharVector.all (fn ch => Char.isLower ch orelse Char.isDigit ch orelse ch = #"_" orelse ch = #"-") s
145 145
146 fun exp e = 146 fun exp e =
147 case e of 147 case e of
148 EPrim (Prim.String s) => 148 EPrim (Prim.String (Prim.Html, s)) =>
149 if CharVector.exists Char.isSpace s then 149 if CharVector.exists Char.isSpace s then
150 let 150 let
151 val (_, chs) = 151 val (_, chs) =
152 CharVector.foldl (fn (ch, (lastSpace, chs)) => 152 CharVector.foldl (fn (ch, (lastSpace, chs)) =>
153 let 153 let
158 else 158 else
159 (isSpace, ch :: chs) 159 (isSpace, ch :: chs)
160 end) 160 end)
161 (false, []) s 161 (false, []) s
162 in 162 in
163 EPrim (Prim.String (String.implode (rev chs))) 163 EPrim (Prim.String (Prim.Html, String.implode (rev chs)))
164 end 164 end
165 else 165 else
166 e 166 e
167 167
168 | EFfiApp ("Basis", "strcat", [(e1, _), (e2, _)]) => exp (EStrcat (e1, e2)) 168 | EFfiApp ("Basis", "strcat", [(e1, _), (e2, _)]) => exp (EStrcat (e1, e2))
169 169
170 | EStrcat ((EPrim (Prim.String s1), loc), (EPrim (Prim.String s2), _)) => 170 | EStrcat ((EPrim (Prim.String (Prim.Html, s1)), loc), (EPrim (Prim.String (Prim.Html, s2)), _)) =>
171 let 171 let
172 val s = 172 val s =
173 if size s1 > 0 andalso size s2 > 0 173 if size s1 > 0 andalso size s2 > 0
174 andalso Char.isSpace (String.sub (s1, size s1 - 1)) 174 andalso Char.isSpace (String.sub (s1, size s1 - 1))
175 andalso Char.isSpace (String.sub (s2, 0)) then 175 andalso Char.isSpace (String.sub (s2, 0)) then
176 s1 ^ String.extract (s2, 1, NONE) 176 s1 ^ String.extract (s2, 1, NONE)
177 else 177 else
178 s1 ^ s2 178 s1 ^ s2
179 in 179 in
180 EPrim (Prim.String s) 180 EPrim (Prim.String (Prim.Html, s))
181 end 181 end
182 182
183 | EStrcat ((EPrim (Prim.String s1), loc), (EStrcat ((EPrim (Prim.String s2), _), rest), _)) => 183 | EStrcat ((EPrim (Prim.String (_, s1)), loc), (EPrim (Prim.String (_, s2)), _)) =>
184 EPrim (Prim.String (Prim.Normal, s1 ^ s2))
185
186 | EStrcat ((EPrim (Prim.String (Prim.Html, s1)), loc), (EStrcat ((EPrim (Prim.String (Prim.Html, s2)), _), rest), _)) =>
184 let 187 let
185 val s = 188 val s =
186 if size s1 > 0 andalso size s2 > 0 189 if size s1 > 0 andalso size s2 > 0
187 andalso Char.isSpace (String.sub (s1, size s1 - 1)) 190 andalso Char.isSpace (String.sub (s1, size s1 - 1))
188 andalso Char.isSpace (String.sub (s2, 0)) then 191 andalso Char.isSpace (String.sub (s2, 0)) then
189 s1 ^ String.extract (s2, 1, NONE) 192 s1 ^ String.extract (s2, 1, NONE)
190 else 193 else
191 s1 ^ s2 194 s1 ^ s2
192 in 195 in
193 EStrcat ((EPrim (Prim.String s), loc), rest) 196 EStrcat ((EPrim (Prim.String (Prim.Html, s)), loc), rest)
194 end 197 end
198
199 | EStrcat ((EPrim (Prim.String (_, s1)), loc), (EStrcat ((EPrim (Prim.String (_, s2)), _), rest), _)) =>
200 EStrcat ((EPrim (Prim.String (Prim.Normal, s1 ^ s2)), loc), rest)
195 201
196 | EStrcat ((EStrcat (e1, e2), loc), e3) => 202 | EStrcat ((EStrcat (e1, e2), loc), e3) =>
197 optExp (EStrcat (e1, (EStrcat (e2, e3), loc)), loc) 203 optExp (EStrcat (e1, (EStrcat (e2, e3), loc)), loc)
198 204
199 | EWrite (EStrcat (e1, e2), loc) => 205 | EWrite (EStrcat (e1, e2), loc) =>
200 ESeq ((optExp (EWrite e1, loc), loc), 206 ESeq ((optExp (EWrite e1, loc), loc),
201 (optExp (EWrite e2, loc), loc)) 207 (optExp (EWrite e2, loc), loc))
202 208
203 | ESeq ((EWrite (EPrim (Prim.String s1), _), loc), 209 | ESeq ((EWrite (EPrim (Prim.String (_, s1)), _), loc),
204 (EWrite (EPrim (Prim.String s2), _), _)) => 210 (EWrite (EPrim (Prim.String (_, s2)), _), _)) =>
205 EWrite (EPrim (Prim.String (s1 ^ s2)), loc) 211 EWrite (EPrim (Prim.String (Prim.Normal, s1 ^ s2)), loc)
206 | ESeq ((EWrite (EPrim (Prim.String s1), _), loc), 212 | ESeq ((EWrite (EPrim (Prim.String (_, s1)), _), loc),
207 (ESeq ((EWrite (EPrim (Prim.String s2), _), _), 213 (ESeq ((EWrite (EPrim (Prim.String (_, s2)), _), _),
208 e), _)) => 214 e), _)) =>
209 ESeq ((EWrite (EPrim (Prim.String (s1 ^ s2)), loc), loc), 215 ESeq ((EWrite (EPrim (Prim.String (Prim.Normal, s1 ^ s2)), loc), loc),
210 e) 216 e)
211 217
212 | EFfiApp ("Basis", "htmlifySpecialChar", [((EPrim (Prim.Char ch), _), _)]) => 218 | EFfiApp ("Basis", "htmlifySpecialChar", [((EPrim (Prim.Char ch), _), _)]) =>
213 EPrim (Prim.String (htmlifySpecialChar ch)) 219 EPrim (Prim.String (Prim.Html, htmlifySpecialChar ch))
214 | EWrite (EFfiApp ("Basis", "htmlifySpecialChar", [e]), _) => 220 | EWrite (EFfiApp ("Basis", "htmlifySpecialChar", [e]), _) =>
215 EFfiApp ("Basis", "htmlifySpecialChar_w", [e]) 221 EFfiApp ("Basis", "htmlifySpecialChar_w", [e])
216 222
217 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "intToString", [((EPrim (Prim.Int n), _), _)]), _), _)]) => 223 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "intToString", [((EPrim (Prim.Int n), _), _)]), _), _)]) =>
218 EPrim (Prim.String (htmlifyInt n)) 224 EPrim (Prim.String (Prim.Html, htmlifyInt n))
219 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "intToString", es), _), _)]) => 225 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "intToString", es), _), _)]) =>
220 EFfiApp ("Basis", "htmlifyInt", es) 226 EFfiApp ("Basis", "htmlifyInt", es)
221 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "intToString"), _), 227 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "intToString"), _),
222 (EPrim (Prim.Int n), _)), _), _)]) => 228 (EPrim (Prim.Int n), _)), _), _)]) =>
223 EPrim (Prim.String (htmlifyInt n)) 229 EPrim (Prim.String (Prim.Html, htmlifyInt n))
224 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "intToString"), _), 230 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "intToString"), _),
225 e), loc), _)]) => 231 e), loc), _)]) =>
226 EFfiApp ("Basis", "htmlifyInt", [(e, (TFfi ("Basis", "int"), loc))]) 232 EFfiApp ("Basis", "htmlifyInt", [(e, (TFfi ("Basis", "int"), loc))])
227 | EWrite (EFfiApp ("Basis", "htmlifyInt", [e]), _) => 233 | EWrite (EFfiApp ("Basis", "htmlifyInt", [e]), _) =>
228 EFfiApp ("Basis", "htmlifyInt_w", [e]) 234 EFfiApp ("Basis", "htmlifyInt_w", [e])
229 235
230 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "floatToString", [((EPrim (Prim.Float n), _), _)]), _), _)]) => 236 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "floatToString", [((EPrim (Prim.Float n), _), _)]), _), _)]) =>
231 EPrim (Prim.String (htmlifyFloat n)) 237 EPrim (Prim.String (Prim.Html, htmlifyFloat n))
232 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "floatToString", es), _), _)]) => 238 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "floatToString", es), _), _)]) =>
233 EFfiApp ("Basis", "htmlifyFloat", es) 239 EFfiApp ("Basis", "htmlifyFloat", es)
234 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "floatToString"), _), 240 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "floatToString"), _),
235 (EPrim (Prim.Float n), _)), _), _)]) => 241 (EPrim (Prim.Float n), _)), _), _)]) =>
236 EPrim (Prim.String (htmlifyFloat n)) 242 EPrim (Prim.String (Prim.Html, htmlifyFloat n))
237 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "floatToString"), _), 243 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "floatToString"), _),
238 e), loc), _)]) => 244 e), loc), _)]) =>
239 EFfiApp ("Basis", "htmlifyFloat", [(e, (TFfi ("Basis", "float"), loc))]) 245 EFfiApp ("Basis", "htmlifyFloat", [(e, (TFfi ("Basis", "float"), loc))])
240 | EWrite (EFfiApp ("Basis", "htmlifyFloat", [e]), _) => 246 | EWrite (EFfiApp ("Basis", "htmlifyFloat", [e]), _) =>
241 EFfiApp ("Basis", "htmlifyFloat_w", [e]) 247 EFfiApp ("Basis", "htmlifyFloat_w", [e])
242 248
243 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "boolToString", 249 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "boolToString",
244 [((ECon (Enum, PConFfi {con = "True", ...}, NONE), _), _)]), _), _)]) => 250 [((ECon (Enum, PConFfi {con = "True", ...}, NONE), _), _)]), _), _)]) =>
245 EPrim (Prim.String "True") 251 EPrim (Prim.String (Prim.Html, "True"))
246 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "boolToString", 252 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "boolToString",
247 [((ECon (Enum, PConFfi {con = "False", ...}, NONE), _), _)]), _), _)]) => 253 [((ECon (Enum, PConFfi {con = "False", ...}, NONE), _), _)]), _), _)]) =>
248 EPrim (Prim.String "False") 254 EPrim (Prim.String (Prim.Html, "False"))
249 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "boolToString", es), _), _)]) => 255 | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "boolToString", es), _), _)]) =>
250 EFfiApp ("Basis", "htmlifyBool", es) 256 EFfiApp ("Basis", "htmlifyBool", es)
251 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "boolToString"), _), 257 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "boolToString"), _),
252 (ECon (Enum, PConFfi {con = "True", ...}, NONE), _)), _), _)]) => 258 (ECon (Enum, PConFfi {con = "True", ...}, NONE), _)), _), _)]) =>
253 EPrim (Prim.String "True") 259 EPrim (Prim.String (Prim.Html, "True"))
254 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "boolToString"), _), 260 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "boolToString"), _),
255 (ECon (Enum, PConFfi {con = "False", ...}, NONE), _)), _), _)]) => 261 (ECon (Enum, PConFfi {con = "False", ...}, NONE), _)), _), _)]) =>
256 EPrim (Prim.String "False") 262 EPrim (Prim.String (Prim.Html, "False"))
257 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "boolToString"), _), 263 | EFfiApp ("Basis", "htmlifyString", [((EApp ((EFfi ("Basis", "boolToString"), _),
258 e), loc), _)]) => 264 e), loc), _)]) =>
259 EFfiApp ("Basis", "htmlifyBool", [(e, (TFfi ("Basis", "bool"), loc))]) 265 EFfiApp ("Basis", "htmlifyBool", [(e, (TFfi ("Basis", "bool"), loc))])
260 | EWrite (EFfiApp ("Basis", "htmlifyBool", [e]), _) => 266 | EWrite (EFfiApp ("Basis", "htmlifyBool", [e]), _) =>
261 EFfiApp ("Basis", "htmlifyBool_w", [e]) 267 EFfiApp ("Basis", "htmlifyBool_w", [e])
265 | EFfiApp ("Basis", "htmlifyString_w", [((EApp ((EFfi ("Basis", "timeToString"), loc), e), _), _)]) => 271 | EFfiApp ("Basis", "htmlifyString_w", [((EApp ((EFfi ("Basis", "timeToString"), loc), e), _), _)]) =>
266 EFfiApp ("Basis", "htmlifyTime_w", [(e, (TFfi ("Basis", "time"), loc))]) 272 EFfiApp ("Basis", "htmlifyTime_w", [(e, (TFfi ("Basis", "time"), loc))])
267 | EWrite (EFfiApp ("Basis", "htmlifyTime", [e]), _) => 273 | EWrite (EFfiApp ("Basis", "htmlifyTime", [e]), _) =>
268 EFfiApp ("Basis", "htmlifyTime_w", [e]) 274 EFfiApp ("Basis", "htmlifyTime_w", [e])
269 275
270 | EFfiApp ("Basis", "htmlifyString", [((EPrim (Prim.String s), _), _)]) => 276 | EFfiApp ("Basis", "htmlifyString", [((EPrim (Prim.String (_, s)), _), _)]) =>
271 EPrim (Prim.String (htmlifyString s)) 277 EPrim (Prim.String (Prim.Html, htmlifyString s))
272 | EWrite (EFfiApp ("Basis", "htmlifyString", [((EPrim (Prim.String s), _), _)]), loc) => 278 | EWrite (EFfiApp ("Basis", "htmlifyString", [((EPrim (Prim.String (_, s)), _), _)]), loc) =>
273 EWrite (EPrim (Prim.String (htmlifyString s)), loc) 279 EWrite (EPrim (Prim.String (Prim.Html, htmlifyString s)), loc)
274 | EWrite (EFfiApp ("Basis", "htmlifyString", [e]), _) => 280 | EWrite (EFfiApp ("Basis", "htmlifyString", [e]), _) =>
275 EFfiApp ("Basis", "htmlifyString_w", [e]) 281 EFfiApp ("Basis", "htmlifyString_w", [e])
276 | EFfiApp ("Basis", "htmlifyString_w", [((EPrim (Prim.String s), loc), _)]) => 282 | EFfiApp ("Basis", "htmlifyString_w", [((EPrim (Prim.String (_, s)), loc), _)]) =>
277 EWrite (EPrim (Prim.String (htmlifyString s)), loc) 283 EWrite (EPrim (Prim.String (Prim.Html, htmlifyString s)), loc)
278 284
279 | EWrite (EFfiApp ("Basis", "htmlifySource", [e]), _) => 285 | EWrite (EFfiApp ("Basis", "htmlifySource", [e]), _) =>
280 EFfiApp ("Basis", "htmlifySource_w", [e]) 286 EFfiApp ("Basis", "htmlifySource_w", [e])
281 287
282 | EFfiApp ("Basis", "attrifyInt", [((EPrim (Prim.Int n), _), _)]) => 288 | EFfiApp ("Basis", "attrifyInt", [((EPrim (Prim.Int n), _), _)]) =>
283 EPrim (Prim.String (attrifyInt n)) 289 EPrim (Prim.String (Prim.Html, attrifyInt n))
284 | EWrite (EFfiApp ("Basis", "attrifyInt", [((EPrim (Prim.Int n), _), _)]), loc) => 290 | EWrite (EFfiApp ("Basis", "attrifyInt", [((EPrim (Prim.Int n), _), _)]), loc) =>
285 EWrite (EPrim (Prim.String (attrifyInt n)), loc) 291 EWrite (EPrim (Prim.String (Prim.Html, attrifyInt n)), loc)
286 | EWrite (EFfiApp ("Basis", "attrifyInt", [e]), _) => 292 | EWrite (EFfiApp ("Basis", "attrifyInt", [e]), _) =>
287 EFfiApp ("Basis", "attrifyInt_w", [e]) 293 EFfiApp ("Basis", "attrifyInt_w", [e])
288 294
289 | EFfiApp ("Basis", "attrifyFloat", [((EPrim (Prim.Float n), _), _)]) => 295 | EFfiApp ("Basis", "attrifyFloat", [((EPrim (Prim.Float n), _), _)]) =>
290 EPrim (Prim.String (attrifyFloat n)) 296 EPrim (Prim.String (Prim.Html, attrifyFloat n))
291 | EWrite (EFfiApp ("Basis", "attrifyFloat", [((EPrim (Prim.Float n), _), _)]), loc) => 297 | EWrite (EFfiApp ("Basis", "attrifyFloat", [((EPrim (Prim.Float n), _), _)]), loc) =>
292 EWrite (EPrim (Prim.String (attrifyFloat n)), loc) 298 EWrite (EPrim (Prim.String (Prim.Html, attrifyFloat n)), loc)
293 | EWrite (EFfiApp ("Basis", "attrifyFloat", [e]), _) => 299 | EWrite (EFfiApp ("Basis", "attrifyFloat", [e]), _) =>
294 EFfiApp ("Basis", "attrifyFloat_w", [e]) 300 EFfiApp ("Basis", "attrifyFloat_w", [e])
295 301
296 | EFfiApp ("Basis", "attrifyString", [((EPrim (Prim.String s), _), _)]) => 302 | EFfiApp ("Basis", "attrifyString", [((EPrim (Prim.String (_, s)), _), _)]) =>
297 EPrim (Prim.String (attrifyString s)) 303 EPrim (Prim.String (Prim.Html, attrifyString s))
298 | EWrite (EFfiApp ("Basis", "attrifyString", [((EPrim (Prim.String s), _), _)]), loc) => 304 | EWrite (EFfiApp ("Basis", "attrifyString", [((EPrim (Prim.String (_, s)), _), _)]), loc) =>
299 EWrite (EPrim (Prim.String (attrifyString s)), loc) 305 EWrite (EPrim (Prim.String (Prim.Html, attrifyString s)), loc)
300 | EWrite (EFfiApp ("Basis", "attrifyString", [e]), _) => 306 | EWrite (EFfiApp ("Basis", "attrifyString", [e]), _) =>
301 EFfiApp ("Basis", "attrifyString_w", [e]) 307 EFfiApp ("Basis", "attrifyString_w", [e])
302 308
303 | EFfiApp ("Basis", "attrifyChar", [((EPrim (Prim.Char s), _), _)]) => 309 | EFfiApp ("Basis", "attrifyChar", [((EPrim (Prim.Char s), _), _)]) =>
304 EPrim (Prim.String (attrifyChar s)) 310 EPrim (Prim.String (Prim.Html, attrifyChar s))
305 | EWrite (EFfiApp ("Basis", "attrifyChar", [((EPrim (Prim.Char s), _), _)]), loc) => 311 | EWrite (EFfiApp ("Basis", "attrifyChar", [((EPrim (Prim.Char s), _), _)]), loc) =>
306 EWrite (EPrim (Prim.String (attrifyChar s)), loc) 312 EWrite (EPrim (Prim.String (Prim.Html, attrifyChar s)), loc)
307 | EWrite (EFfiApp ("Basis", "attrifyChar", [e]), _) => 313 | EWrite (EFfiApp ("Basis", "attrifyChar", [e]), _) =>
308 EFfiApp ("Basis", "attrifyChar_w", [e]) 314 EFfiApp ("Basis", "attrifyChar_w", [e])
309 315
310 | EFfiApp ("Basis", "attrifyCss_class", [((EPrim (Prim.String s), _), _)]) => 316 | EFfiApp ("Basis", "attrifyCss_class", [((EPrim (Prim.String (_, s)), _), _)]) =>
311 EPrim (Prim.String s) 317 EPrim (Prim.String (Prim.Html, s))
312 | EWrite (EFfiApp ("Basis", "attrifyCss_class", [((EPrim (Prim.String s), _), _)]), loc) => 318 | EWrite (EFfiApp ("Basis", "attrifyCss_class", [((EPrim (Prim.String (_, s)), _), _)]), loc) =>
313 EWrite (EPrim (Prim.String s), loc) 319 EWrite (EPrim (Prim.String (Prim.Html, s)), loc)
314 | EWrite (EFfiApp ("Basis", "attrifyCss_class", [e]), _) => 320 | EWrite (EFfiApp ("Basis", "attrifyCss_class", [e]), _) =>
315 EFfiApp ("Basis", "attrifyString_w", [e]) 321 EFfiApp ("Basis", "attrifyString_w", [e])
316 322
317 | EFfiApp ("Basis", "urlifyInt", [((EPrim (Prim.Int n), _), _)]) => 323 | EFfiApp ("Basis", "urlifyInt", [((EPrim (Prim.Int n), _), _)]) =>
318 EPrim (Prim.String (urlifyInt n)) 324 EPrim (Prim.String (Prim.Normal, urlifyInt n))
319 | EWrite (EFfiApp ("Basis", "urlifyInt", [((EPrim (Prim.Int n), _), _)]), loc) => 325 | EWrite (EFfiApp ("Basis", "urlifyInt", [((EPrim (Prim.Int n), _), _)]), loc) =>
320 EWrite (EPrim (Prim.String (urlifyInt n)), loc) 326 EWrite (EPrim (Prim.String (Prim.Normal, urlifyInt n)), loc)
321 | EWrite (EFfiApp ("Basis", "urlifyInt", [e]), _) => 327 | EWrite (EFfiApp ("Basis", "urlifyInt", [e]), _) =>
322 EFfiApp ("Basis", "urlifyInt_w", [e]) 328 EFfiApp ("Basis", "urlifyInt_w", [e])
323 329
324 | EFfiApp ("Basis", "urlifyFloat", [((EPrim (Prim.Float n), _), _)]) => 330 | EFfiApp ("Basis", "urlifyFloat", [((EPrim (Prim.Float n), _), _)]) =>
325 EPrim (Prim.String (urlifyFloat n)) 331 EPrim (Prim.String (Prim.Normal, urlifyFloat n))
326 | EWrite (EFfiApp ("Basis", "urlifyFloat", [((EPrim (Prim.Float n), _), _)]), loc) => 332 | EWrite (EFfiApp ("Basis", "urlifyFloat", [((EPrim (Prim.Float n), _), _)]), loc) =>
327 EWrite (EPrim (Prim.String (urlifyFloat n)), loc) 333 EWrite (EPrim (Prim.String (Prim.Normal, urlifyFloat n)), loc)
328 | EWrite (EFfiApp ("Basis", "urlifyFloat", [e]), _) => 334 | EWrite (EFfiApp ("Basis", "urlifyFloat", [e]), _) =>
329 EFfiApp ("Basis", "urlifyFloat_w", [e]) 335 EFfiApp ("Basis", "urlifyFloat_w", [e])
330 336
331 | EFfiApp ("Basis", "urlifyString", [((EPrim (Prim.String s), _), _)]) => 337 | EFfiApp ("Basis", "urlifyString", [((EPrim (Prim.String (_, s)), _), _)]) =>
332 EPrim (Prim.String (urlifyString s)) 338 EPrim (Prim.String (Prim.Normal, urlifyString s))
333 | EWrite (EFfiApp ("Basis", "urlifyString", [((EPrim (Prim.String s), _), _)]), loc) => 339 | EWrite (EFfiApp ("Basis", "urlifyString", [((EPrim (Prim.String (Prim.Normal, s)), _), _)]), loc) =>
334 EWrite (EPrim (Prim.String (urlifyString s)), loc) 340 EWrite (EPrim (Prim.String (Prim.Normal, urlifyString s)), loc)
335 | EWrite (EFfiApp ("Basis", "urlifyString", [e]), _) => 341 | EWrite (EFfiApp ("Basis", "urlifyString", [e]), _) =>
336 EFfiApp ("Basis", "urlifyString_w", [e]) 342 EFfiApp ("Basis", "urlifyString_w", [e])
337 343
338 | EFfiApp ("Basis", "urlifyBool", [((ECon (Enum, PConFfi {con = "True", ...}, NONE), _), _)]) => 344 | EFfiApp ("Basis", "urlifyBool", [((ECon (Enum, PConFfi {con = "True", ...}, NONE), _), _)]) =>
339 EPrim (Prim.String "1") 345 EPrim (Prim.String (Prim.Normal, "1"))
340 | EFfiApp ("Basis", "urlifyBool", [((ECon (Enum, PConFfi {con = "False", ...}, NONE), _), _)]) => 346 | EFfiApp ("Basis", "urlifyBool", [((ECon (Enum, PConFfi {con = "False", ...}, NONE), _), _)]) =>
341 EPrim (Prim.String "0") 347 EPrim (Prim.String (Prim.Normal, "0"))
342 | EWrite (EFfiApp ("Basis", "urlifyBool", [((ECon (Enum, PConFfi {con = "True", ...}, NONE), _), _)]), loc) => 348 | EWrite (EFfiApp ("Basis", "urlifyBool", [((ECon (Enum, PConFfi {con = "True", ...}, NONE), _), _)]), loc) =>
343 EWrite (EPrim (Prim.String "1"), loc) 349 EWrite (EPrim (Prim.String (Prim.Normal, "1")), loc)
344 | EWrite (EFfiApp ("Basis", "urlifyBool", [((ECon (Enum, PConFfi {con = "False", ...}, NONE), _), _)]), loc) => 350 | EWrite (EFfiApp ("Basis", "urlifyBool", [((ECon (Enum, PConFfi {con = "False", ...}, NONE), _), _)]), loc) =>
345 EWrite (EPrim (Prim.String "0"), loc) 351 EWrite (EPrim (Prim.String (Prim.Normal, "0")), loc)
346 | EWrite (EFfiApp ("Basis", "urlifyBool", [e]), _) => 352 | EWrite (EFfiApp ("Basis", "urlifyBool", [e]), _) =>
347 EFfiApp ("Basis", "urlifyBool_w", [e]) 353 EFfiApp ("Basis", "urlifyBool_w", [e])
348 354
349 | EFfiApp ("Basis", "sqlifyInt", [((EPrim (Prim.Int n), _), _)]) => 355 | EFfiApp ("Basis", "sqlifyInt", [((EPrim (Prim.Int n), _), _)]) =>
350 EPrim (Prim.String (sqlifyInt n)) 356 EPrim (Prim.String (Prim.Normal, sqlifyInt n))
351 | EFfiApp ("Basis", "sqlifyIntN", [((ENone _, _), _)]) => 357 | EFfiApp ("Basis", "sqlifyIntN", [((ENone _, _), _)]) =>
352 EPrim (Prim.String "NULL") 358 EPrim (Prim.String (Prim.Normal, "NULL"))
353 | EFfiApp ("Basis", "sqlifyIntN", [((ESome (_, (EPrim (Prim.Int n), _)), _), _)]) => 359 | EFfiApp ("Basis", "sqlifyIntN", [((ESome (_, (EPrim (Prim.Int n), _)), _), _)]) =>
354 EPrim (Prim.String (sqlifyInt n)) 360 EPrim (Prim.String (Prim.Normal, sqlifyInt n))
355 361
356 | EFfiApp ("Basis", "sqlifyFloat", [((EPrim (Prim.Float n), _), _)]) => 362 | EFfiApp ("Basis", "sqlifyFloat", [((EPrim (Prim.Float n), _), _)]) =>
357 EPrim (Prim.String (sqlifyFloat n)) 363 EPrim (Prim.String (Prim.Normal, sqlifyFloat n))
358 | EFfiApp ("Basis", "sqlifyBool", [(b as (_, loc), _)]) => 364 | EFfiApp ("Basis", "sqlifyBool", [(b as (_, loc), _)]) =>
359 optExp (ECase (b, 365 optExp (ECase (b,
360 [((PCon (Enum, PConFfi {mod = "Basis", datatyp = "bool", con = "True", arg = NONE}, NONE), loc), 366 [((PCon (Enum, PConFfi {mod = "Basis", datatyp = "bool", con = "True", arg = NONE}, NONE), loc),
361 (EPrim (Prim.String (#trueString (Settings.currentDbms ()))), loc)), 367 (EPrim (Prim.String (Prim.Normal, #trueString (Settings.currentDbms ()))), loc)),
362 ((PCon (Enum, PConFfi {mod = "Basis", datatyp = "bool", con = "False", arg = NONE}, NONE), loc), 368 ((PCon (Enum, PConFfi {mod = "Basis", datatyp = "bool", con = "False", arg = NONE}, NONE), loc),
363 (EPrim (Prim.String (#falseString (Settings.currentDbms ()))), loc))], 369 (EPrim (Prim.String (Prim.Normal, #falseString (Settings.currentDbms ()))), loc))],
364 {disc = (TFfi ("Basis", "bool"), loc), 370 {disc = (TFfi ("Basis", "bool"), loc),
365 result = (TFfi ("Basis", "string"), loc)}), loc) 371 result = (TFfi ("Basis", "string"), loc)}), loc)
366 | EFfiApp ("Basis", "sqlifyString", [((EPrim (Prim.String n), _), _)]) => 372 | EFfiApp ("Basis", "sqlifyString", [((EPrim (Prim.String (_, n)), _), _)]) =>
367 EPrim (Prim.String (sqlifyString n)) 373 EPrim (Prim.String (Prim.Normal, sqlifyString n))
368 | EFfiApp ("Basis", "sqlifyChar", [((EPrim (Prim.Char n), _), _)]) => 374 | EFfiApp ("Basis", "sqlifyChar", [((EPrim (Prim.Char n), _), _)]) =>
369 EPrim (Prim.String (sqlifyChar n)) 375 EPrim (Prim.String (Prim.Normal, sqlifyChar n))
370 376
371 | EWrite (ECase (discE, pes, {disc, ...}), loc) => 377 | EWrite (ECase (discE, pes, {disc, ...}), loc) =>
372 optExp (ECase (discE, 378 optExp (ECase (discE,
373 map (fn (p, e) => (p, (EWrite e, loc))) pes, 379 map (fn (p, e) => (p, (EWrite e, loc))) pes,
374 {disc = disc, 380 {disc = disc,
386 {disc = disc, 392 {disc = disc,
387 result = ran}), loc) 393 result = ran}), loc)
388 end 394 end
389 395
390 | EWrite (EQuery {exps, tables, state, query, 396 | EWrite (EQuery {exps, tables, state, query,
391 initial = (EPrim (Prim.String ""), _), 397 initial = (EPrim (Prim.String (k, "")), _),
392 body = (EStrcat ((EPrim (Prim.String s), _), 398 body = (EStrcat ((EPrim (Prim.String (_, s)), _),
393 (EStrcat ((ERel 0, _), 399 (EStrcat ((ERel 0, _),
394 e'), _)), _)}, loc) => 400 e'), _)), _)}, loc) =>
395 if CharVector.all Char.isSpace s then 401 if (case k of Prim.Normal => s = "" | Prim.Html => CharVector.all Char.isSpace s) then
396 EQuery {exps = exps, tables = tables, query = query, 402 EQuery {exps = exps, tables = tables, query = query,
397 state = (TRecord [], loc), 403 state = (TRecord [], loc),
398 initial = (ERecord [], loc), 404 initial = (ERecord [], loc),
399 body = (optExp (EWrite e', loc), loc)} 405 body = (optExp (EWrite e', loc), loc)}
400 else 406 else
401 e 407 e
402 408
403 | EWrite (EQuery {exps, tables, state, query, 409 | EWrite (EQuery {exps, tables, state, query,
404 initial = (EPrim (Prim.String ""), _), 410 initial = (EPrim (Prim.String (_, "")), _),
405 body}, loc) => 411 body}, loc) =>
406 let 412 let
407 fun passLets (depth, (e', _), lets) = 413 fun passLets (depth, (e', _), lets) =
408 case e' of 414 case e' of
409 EStrcat ((ERel x, _), e'') => 415 EStrcat ((ERel x, _), e'') =>
437 body = (optExp (EWrite e', loc), loc)}*) 443 body = (optExp (EWrite e', loc), loc)}*)
438 444
439 | EWrite (ELet (x, t, e1, e2), loc) => 445 | EWrite (ELet (x, t, e1, e2), loc) =>
440 optExp (ELet (x, t, e1, (EWrite e2, loc)), loc) 446 optExp (ELet (x, t, e1, (EWrite e2, loc)), loc)
441 447
442 | EWrite (EPrim (Prim.String ""), loc) => 448 | EWrite (EPrim (Prim.String (_, "")), loc) =>
443 ERecord [] 449 ERecord []
444 450
445 | ESignalBind ((ESignalReturn e1, loc), e2) => 451 | ESignalBind ((ESignalReturn e1, loc), e2) =>
446 optExp (EApp (e2, e1), loc) 452 optExp (EApp (e2, e1), loc)
447 453
448 | EFfiApp ("Basis", "blessData", [((se as EPrim (Prim.String s), loc), _)]) => 454 | EFfiApp ("Basis", "blessData", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
449 (if checkData s then 455 (if checkData s then
450 () 456 ()
451 else 457 else
452 ErrorMsg.errorAt loc ("Invalid HTML5 data-* attribute " ^ s); 458 ErrorMsg.errorAt loc ("Invalid HTML5 data-* attribute " ^ s);
453 se) 459 se)
454 460
455 | EFfiApp ("Basis", "bless", [((se as EPrim (Prim.String s), loc), _)]) => 461 | EFfiApp ("Basis", "bless", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
456 (if checkUrl s then 462 (if checkUrl s then
457 () 463 ()
458 else 464 else
459 ErrorMsg.errorAt loc ("Invalid URL " ^ s ^ " passed to 'bless'"); 465 ErrorMsg.errorAt loc ("Invalid URL " ^ s ^ " passed to 'bless'");
460 se) 466 se)
461 | EFfiApp ("Basis", "checkUrl", [((se as EPrim (Prim.String s), loc), _)]) => 467 | EFfiApp ("Basis", "checkUrl", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
462 (if checkUrl s then 468 (if checkUrl s then
463 ESome ((TFfi ("Basis", "string"), loc), (se, loc)) 469 ESome ((TFfi ("Basis", "string"), loc), (se, loc))
464 else 470 else
465 ENone (TFfi ("Basis", "string"), loc)) 471 ENone (TFfi ("Basis", "string"), loc))
466 | EFfiApp ("Basis", "blessMime", [((se as EPrim (Prim.String s), loc), _)]) => 472 | EFfiApp ("Basis", "blessMime", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
467 (if Settings.checkMime s then 473 (if Settings.checkMime s then
468 () 474 ()
469 else 475 else
470 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'blessMime'"); 476 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'blessMime'");
471 se) 477 se)
472 | EFfiApp ("Basis", "checkMime", [((se as EPrim (Prim.String s), loc), _)]) => 478 | EFfiApp ("Basis", "checkMime", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
473 (if Settings.checkMime s then 479 (if Settings.checkMime s then
474 ESome ((TFfi ("Basis", "string"), loc), (se, loc)) 480 ESome ((TFfi ("Basis", "string"), loc), (se, loc))
475 else 481 else
476 ENone (TFfi ("Basis", "string"), loc)) 482 ENone (TFfi ("Basis", "string"), loc))
477 | EFfiApp ("Basis", "atom", [((se as EPrim (Prim.String s), loc), _)]) => 483 | EFfiApp ("Basis", "atom", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
478 (if checkAtom s then 484 (if checkAtom s then
479 () 485 ()
480 else 486 else
481 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'atom'"); 487 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'atom'");
482 se) 488 se)
483 | EFfiApp ("Basis", "css_url", [((se as EPrim (Prim.String s), loc), _)]) => 489 | EFfiApp ("Basis", "css_url", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
484 (if checkCssUrl s then 490 (if checkCssUrl s then
485 () 491 ()
486 else 492 else
487 ErrorMsg.errorAt loc ("Invalid URL " ^ s ^ " passed to 'css_url'"); 493 ErrorMsg.errorAt loc ("Invalid URL " ^ s ^ " passed to 'css_url'");
488 se) 494 se)
489 | EFfiApp ("Basis", "property", [((se as EPrim (Prim.String s), loc), _)]) => 495 | EFfiApp ("Basis", "property", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
490 (if checkProperty s then 496 (if checkProperty s then
491 () 497 ()
492 else 498 else
493 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'property'"); 499 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'property'");
494 se) 500 se)
495 | EFfiApp ("Basis", "blessRequestHeader", [((se as EPrim (Prim.String s), loc), _)]) => 501 | EFfiApp ("Basis", "blessRequestHeader", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
496 (if Settings.checkRequestHeader s then 502 (if Settings.checkRequestHeader s then
497 () 503 ()
498 else 504 else
499 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'blessRequestHeader'"); 505 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'blessRequestHeader'");
500 se) 506 se)
501 | EFfiApp ("Basis", "checkRequestHeader", [((se as EPrim (Prim.String s), loc), _)]) => 507 | EFfiApp ("Basis", "checkRequestHeader", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
502 (if Settings.checkRequestHeader s then 508 (if Settings.checkRequestHeader s then
503 ESome ((TFfi ("Basis", "string"), loc), (se, loc)) 509 ESome ((TFfi ("Basis", "string"), loc), (se, loc))
504 else 510 else
505 ENone (TFfi ("Basis", "string"), loc)) 511 ENone (TFfi ("Basis", "string"), loc))
506 | EFfiApp ("Basis", "blessResponseHeader", [((se as EPrim (Prim.String s), loc), _)]) => 512 | EFfiApp ("Basis", "blessResponseHeader", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
507 (if Settings.checkResponseHeader s then 513 (if Settings.checkResponseHeader s then
508 () 514 ()
509 else 515 else
510 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'blessResponseHeader'"); 516 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'blessResponseHeader'");
511 se) 517 se)
512 | EFfiApp ("Basis", "checkResponseHeader", [((se as EPrim (Prim.String s), loc), _)]) => 518 | EFfiApp ("Basis", "checkResponseHeader", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
513 (if Settings.checkResponseHeader s then 519 (if Settings.checkResponseHeader s then
514 ESome ((TFfi ("Basis", "string"), loc), (se, loc)) 520 ESome ((TFfi ("Basis", "string"), loc), (se, loc))
515 else 521 else
516 ENone (TFfi ("Basis", "string"), loc)) 522 ENone (TFfi ("Basis", "string"), loc))
517 | EFfiApp ("Basis", "blessEnvVar", [((se as EPrim (Prim.String s), loc), _)]) => 523 | EFfiApp ("Basis", "blessEnvVar", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
518 (if Settings.checkEnvVar s then 524 (if Settings.checkEnvVar s then
519 () 525 ()
520 else 526 else
521 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'blessEnvVar'"); 527 ErrorMsg.errorAt loc ("Invalid string " ^ s ^ " passed to 'blessEnvVar'");
522 se) 528 se)
523 | EFfiApp ("Basis", "checkEnvVar", [((se as EPrim (Prim.String s), loc), _)]) => 529 | EFfiApp ("Basis", "checkEnvVar", [((se as EPrim (Prim.String (_, s)), loc), _)]) =>
524 (if Settings.checkEnvVar s then 530 (if Settings.checkEnvVar s then
525 ESome ((TFfi ("Basis", "string"), loc), (se, loc)) 531 ESome ((TFfi ("Basis", "string"), loc), (se, loc))
526 else 532 else
527 ENone (TFfi ("Basis", "string"), loc)) 533 ENone (TFfi ("Basis", "string"), loc))
528 534
529 | EFfiApp ("Basis", "checkString", [((EPrim (Prim.String s), loc), _)]) => 535 | EFfiApp ("Basis", "checkString", [((EPrim (Prim.String (_, s)), loc), _)]) =>
530 let 536 let
531 fun uwify (cs, acc) = 537 fun uwify (cs, acc) =
532 case cs of 538 case cs of
533 [] => String.concat (rev acc) 539 [] => String.concat (rev acc)
534 | #"(" :: #"_" :: cs => uwify (cs, "(uw_" :: acc) 540 | #"(" :: #"_" :: cs => uwify (cs, "(uw_" :: acc)
549 555
550 val s = case String.explode s of 556 val s = case String.explode s of
551 #"_" :: cs => uwify (cs, ["uw_"]) 557 #"_" :: cs => uwify (cs, ["uw_"])
552 | cs => uwify (cs, []) 558 | cs => uwify (cs, [])
553 in 559 in
554 EPrim (Prim.String s) 560 EPrim (Prim.String (Prim.Normal, s))
555 end 561 end
556 562
557 | EFfiApp ("Basis", "viewify", [((EPrim (Prim.String s), loc), _)]) => 563 | EFfiApp ("Basis", "viewify", [((EPrim (Prim.String (_, s)), loc), _)]) =>
558 let 564 let
559 fun uwify (cs, acc) = 565 fun uwify (cs, acc) =
560 case cs of 566 case cs of
561 [] => String.concat (rev acc) 567 [] => String.concat (rev acc)
562 | #"A" :: #"S" :: #" " :: #"_" :: cs => uwify (cs, "AS uw_" :: acc) 568 | #"A" :: #"S" :: #" " :: #"_" :: cs => uwify (cs, "AS uw_" :: acc)
574 end 580 end
575 | c :: cs => uwify (cs, str c :: acc) 581 | c :: cs => uwify (cs, str c :: acc)
576 582
577 val s = uwify (String.explode s, []) 583 val s = uwify (String.explode s, [])
578 in 584 in
579 EPrim (Prim.String s) 585 EPrim (Prim.String (Prim.Normal, s))
580 end 586 end
581 587
582 | EFfiApp ("Basis", "unAs", [((EPrim (Prim.String s), _), _)]) => 588 | EFfiApp ("Basis", "unAs", [((EPrim (Prim.String (_, s)), _), _)]) =>
583 EPrim (Prim.String (unAs s)) 589 EPrim (Prim.String (Prim.Normal, unAs s))
584 | EFfiApp ("Basis", "unAs", [(e', _)]) => 590 | EFfiApp ("Basis", "unAs", [(e', _)]) =>
585 let 591 let
586 fun parts (e as (_, loc)) = 592 fun parts (e as (_, loc)) =
587 case #1 e of 593 case #1 e of
588 EStrcat (s1, s2) => 594 EStrcat (s1, s2) =>
589 (case (parts s1, parts s2) of 595 (case (parts s1, parts s2) of
590 (SOME p1, SOME p2) => SOME (p1 @ p2) 596 (SOME p1, SOME p2) => SOME (p1 @ p2)
591 | _ => NONE) 597 | _ => NONE)
592 | EPrim (Prim.String s) => SOME [(EPrim (Prim.String (unAs s)), loc)] 598 | EPrim (Prim.String (_, s)) => SOME [(EPrim (Prim.String (Prim.Normal, unAs s)), loc)]
593 | EFfiApp ("Basis", f, [_]) => 599 | EFfiApp ("Basis", f, [_]) =>
594 if String.isPrefix "sqlify" f then 600 if String.isPrefix "sqlify" f then
595 SOME [e] 601 SOME [e]
596 else 602 else
597 NONE 603 NONE
605 | [] => raise Fail "MonoOpt impossible nil") 611 | [] => raise Fail "MonoOpt impossible nil")
606 | NONE => e 612 | NONE => e
607 end 613 end
608 614
609 | EFfiApp ("Basis", "str1", [((EPrim (Prim.Char ch), _), _)]) => 615 | EFfiApp ("Basis", "str1", [((EPrim (Prim.Char ch), _), _)]) =>
610 EPrim (Prim.String (str ch)) 616 EPrim (Prim.String (Prim.Normal, str ch))
611 | EFfiApp ("Basis", "attrifyString", [((EFfiApp ("Basis", "str1", [e]), _), _)]) => 617 | EFfiApp ("Basis", "attrifyString", [((EFfiApp ("Basis", "str1", [e]), _), _)]) =>
612 EFfiApp ("Basis", "attrifyChar", [e]) 618 EFfiApp ("Basis", "attrifyChar", [e])
613 | EFfiApp ("Basis", "attrifyString_w", [((EFfiApp ("Basis", "str1", [e]), _), _)]) => 619 | EFfiApp ("Basis", "attrifyString_w", [((EFfiApp ("Basis", "str1", [e]), _), _)]) =>
614 EFfiApp ("Basis", "attrifyChar_w", [e]) 620 EFfiApp ("Basis", "attrifyChar_w", [e])
615 621