Commits

Sébastien Ferré committed b032c2b

definition and use of 'term_escaped'.

Comments (0)

Files changed (1)

              then power10 (p-1) *. 10.
              else power10 (p+1) /. 10.
 
+let term_escaped : string -> string =
+  fun s ->
+    let s1 = String.escaped s in
+    let l1 = String.length s1 in
+    let buf = Buffer.create (2 * l1) in
+    for i=0 to l1-1 do
+      if s1.[i] = '\''
+      then Buffer.add_string buf "\\\'"
+      else Buffer.add_char buf s1.[i]
+    done;
+    Buffer.contents buf
+
 let pp_print_token : formatter -> Token.t -> Token.t -> unit =
   fun ff pred -> function
     | BackQuote -> pp_print_string ff "`"
 	if !b then String.iter (function 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' -> () | _ -> b:= false) s;
 	if !b
 	then pp_print_string ff s
-	else pp_print_string ff ("'" ^ String.escaped s ^ "'")
+	else pp_print_string ff ("'" ^ term_escaped s ^ "'")
     | Char c -> pp_print_string ff ("`" ^ Char.escaped c ^ "`")
     | PP_tilda -> pp_print_string ff " "
     | PP_space -> pp_print_space ff ()