Mercurial > urweb
comparison src/jscomp.sml @ 943:e2194a6793ae
Fix JavaScript char literals; don't generate demo links to nonexistent files
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 15 Sep 2009 13:07:57 -0400 |
parents | 36f787c02287 |
children | 5be3d19b59f3 |
comparison
equal
deleted
inserted
replaced
942:280f81731426 | 943:e2194a6793ae |
---|---|
535 (str "ERROR", st)) | 535 (str "ERROR", st)) |
536 | 536 |
537 val strcat = strcat loc | 537 val strcat = strcat loc |
538 | 538 |
539 fun jsPrim p = | 539 fun jsPrim p = |
540 case p of | 540 let |
541 Prim.String s => | 541 fun jsChar ch = |
542 str ("\"" | 542 case ch of |
543 ^ String.translate (fn #"'" => | 543 #"'" => |
544 if mode = Attribute then | 544 if mode = Attribute then |
545 "\\047" | 545 "\\047" |
546 else | 546 else |
547 "'" | 547 "'" |
548 | #"\"" => "\\\"" | 548 | #"\"" => "\\\"" |
549 | #"<" => | 549 | #"<" => "\\074" |
550 (*if mode = Script then | 550 | #"\\" => "\\\\" |
551 "<" | 551 | #"\n" => "\\n" |
552 else*) | 552 | #"\r" => "\\r" |
553 "\\074" | 553 | #"\t" => "\\t" |
554 | #"\\" => "\\\\" | 554 | ch => |
555 | #"\n" => "\\n" | 555 if Char.isPrint ch then |
556 | #"\r" => "\\r" | 556 String.str ch |
557 | #"\t" => "\\t" | 557 else |
558 | ch => | 558 "\\" ^ padWith (#"0", |
559 if Char.isPrint ch then | 559 Int.fmt StringCvt.OCT (ord ch), |
560 String.str ch | 560 3) |
561 else | 561 in |
562 "\\" ^ padWith (#"0", | 562 case p of |
563 Int.fmt StringCvt.OCT (ord ch), | 563 Prim.String s => |
564 3)) s | 564 str ("\"" ^ String.translate jsChar s ^ "\"") |
565 ^ "\"") | 565 | Prim.Char ch => str ("'" ^ jsChar ch ^ "'") |
566 | Prim.Char ch => str ("'" ^ String.str ch ^ "'") | 566 | _ => str (Prim.toString p) |
567 | _ => str (Prim.toString p) | 567 end |
568 | 568 |
569 fun jsPat depth inner (p, _) succ fail = | 569 fun jsPat depth inner (p, _) succ fail = |
570 case p of | 570 case p of |
571 PWild => succ | 571 PWild => succ |
572 | PVar _ => strcat [str ("(_" ^ Int.toString (len + inner) ^ "=d" | 572 | PVar _ => strcat [str ("(_" ^ Int.toString (len + inner) ^ "=d" |