equal
deleted
inserted
replaced
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 enforce_case: bool -> string -> string |
34 val desymbolize: bool option -> string -> string |
35 val desymbolize: bool option -> string -> string |
35 end; |
36 end; |
36 |
37 |
37 structure Name: NAME = |
38 structure Name: NAME = |
38 struct |
39 struct |
148 fun variant_list used names = #1 (make_context used |> fold_map variant names); |
149 fun variant_list used names = #1 (make_context used |> fold_map variant names); |
149 |
150 |
150 |
151 |
151 (* names conforming to typical requirements of identifiers in the world outside *) |
152 (* names conforming to typical requirements of identifiers in the world outside *) |
152 |
153 |
|
154 fun enforce_case' false cs = |
|
155 (if forall Symbol.is_ascii_upper cs then map else nth_map 0) Symbol.to_ascii_lower cs |
|
156 | enforce_case' true cs = |
|
157 nth_map 0 Symbol.to_ascii_upper cs; |
|
158 |
|
159 fun enforce_case upper = implode o enforce_case' upper o raw_explode; |
|
160 |
153 fun desymbolize perhaps_upper "" = |
161 fun desymbolize perhaps_upper "" = |
154 if the_default false perhaps_upper then "X" else "x" |
162 if the_default false perhaps_upper then "X" else "x" |
155 | desymbolize perhaps_upper s = |
163 | desymbolize perhaps_upper s = |
156 let |
164 let |
157 val xs as (x :: _) = Symbol.explode s; |
165 val xs as (x :: _) = Symbol.explode s; |
169 if is_valid x then x :: xs |
177 if is_valid x then x :: xs |
170 else |
178 else |
171 (case Symbol.decode x of |
179 (case Symbol.decode x of |
172 Symbol.Sym name => "_" :: raw_explode name @ sep xs |
180 Symbol.Sym name => "_" :: raw_explode name @ sep xs |
173 | _ => sep xs); |
181 | _ => sep xs); |
174 fun upper_lower cs = |
182 val upper_lower = Option.map enforce_case' perhaps_upper |> the_default I; |
175 case perhaps_upper of |
|
176 NONE => cs |
|
177 | SOME true => nth_map 0 Symbol.to_ascii_upper cs |
|
178 | SOME false => |
|
179 (if forall Symbol.is_ascii_upper cs then map else nth_map 0) |
|
180 Symbol.to_ascii_lower cs; |
|
181 in fold_rev desymb ys [] |> desep |> upper_lower |> implode end; |
183 in fold_rev desymb ys [] |> desep |> upper_lower |> implode end; |
182 |
184 |
183 end; |
185 end; |