src/Pure/name.ML
changeset 56811 b66639331db5
parent 55949 4766342e8376
child 56812 baef1c110f12
equal deleted inserted replaced
56810:4ccfe99c160b 56811:b66639331db5
    29   val invent: context -> string -> int -> string list
    29   val invent: context -> string -> int -> string list
    30   val invent_names: context -> string -> 'a list -> (string * 'a) list
    30   val invent_names: context -> string -> 'a list -> (string * 'a) list
    31   val invent_list: string list -> string -> int -> string list
    31   val invent_list: string list -> string -> int -> string list
    32   val variant: string -> context -> string * context
    32   val variant: string -> context -> string * context
    33   val variant_list: string list -> string list -> string list
    33   val variant_list: string list -> string list -> string list
    34   val desymbolize: bool -> string -> string
    34   val desymbolize: bool option -> string -> string
    35 end;
    35 end;
    36 
    36 
    37 structure Name: NAME =
    37 structure Name: NAME =
    38 struct
    38 struct
    39 
    39 
   148 fun variant_list used names = #1 (make_context used |> fold_map variant names);
   148 fun variant_list used names = #1 (make_context used |> fold_map variant names);
   149 
   149 
   150 
   150 
   151 (* names conforming to typical requirements of identifiers in the world outside *)
   151 (* names conforming to typical requirements of identifiers in the world outside *)
   152 
   152 
   153 fun desymbolize upper "" = if upper then "X" else "x"
   153 fun desymbolize perhaps_upper "" =
   154   | desymbolize upper s =
   154       if the_default false perhaps_upper then "X" else "x"
       
   155   | desymbolize perhaps_upper s =
   155       let
   156       let
   156         val xs as (x :: _) = Symbol.explode s;
   157         val xs as (x :: _) = Symbol.explode s;
   157         val ys =
   158         val ys =
   158           if Symbol.is_ascii_letter x orelse Symbol.is_symbolic x then xs
   159           if Symbol.is_ascii_letter x orelse Symbol.is_symbolic x then xs
   159           else "x" :: xs;
   160           else "x" :: xs;
   169           else
   170           else
   170             (case Symbol.decode x of
   171             (case Symbol.decode x of
   171               Symbol.Sym name => "_" :: raw_explode name @ sep xs
   172               Symbol.Sym name => "_" :: raw_explode name @ sep xs
   172             | _ => sep xs);
   173             | _ => sep xs);
   173         fun upper_lower cs =
   174         fun upper_lower cs =
   174           if upper then nth_map 0 Symbol.to_ascii_upper cs
   175           case perhaps_upper of
   175           else
   176             NONE => cs
   176             (if forall Symbol.is_ascii_upper cs then map else nth_map 0)
   177           | SOME true => nth_map 0 Symbol.to_ascii_upper cs
   177               Symbol.to_ascii_lower cs;
   178           | SOME false =>
       
   179               (if forall Symbol.is_ascii_upper cs then map else nth_map 0)
       
   180                 Symbol.to_ascii_lower cs;
   178       in fold_rev desymb ys [] |> desep |> upper_lower |> implode end;
   181       in fold_rev desymb ys [] |> desep |> upper_lower |> implode end;
   179 
   182 
   180 end;
   183 end;