summaryrefslogtreecommitdiff
path: root/src/prim.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-01-02 17:08:39 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2012-01-02 17:08:39 -0500
commitfe2d1fe8ab56f83796a80bcb370d7420e693ab2a (patch)
treefd1b94c909fc8c4b2c176406f157cbe8812f5984 /src/prim.sml
parentb01b8ee2e96e7fec30380991ba723558db3666f2 (diff)
Fix handling of quotes in generating C literals
Diffstat (limited to 'src/prim.sml')
-rw-r--r--src/prim.sml16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/prim.sml b/src/prim.sml
index 96880487..94801e7f 100644
--- a/src/prim.sml
+++ b/src/prim.sml
@@ -70,12 +70,24 @@ fun pad (n, ch, s) =
else
str ch ^ pad (n-1, ch, s)
+fun quoteDouble ch =
+ case ch of
+ #"'" => str ch
+ | _ => Char.toCString ch
+
+fun toCChar ch =
+ case ch of
+ #"\"" => str ch
+ | _ => Char.toCString ch
+
+val toCString = String.translate quoteDouble
+
fun p_t_GCC t =
case t of
Int n => string (int2s n)
| Float n => string (float2s n)
- | String s => box [string "\"", string (String.toCString s), string "\""]
- | Char ch => box [string "'", string (Char.toCString ch), string "'"]
+ | String s => box [string "\"", string (toCString s), string "\""]
+ | Char ch => box [string "'", string (toCChar ch), string "'"]
fun equal x =
case x of