| 1 |
From Coq Require Import List. |
| 2 |
From Coq Require Import Ascii. |
| 3 |
From Coq Require Import String. |
| 4 |
Require Import Crypto.Util.Strings.String. |
| 5 |
Import ListNotations. |
| 6 |
Local Open Scope list_scope. |
| 7 |
Local Open Scope char_scope. |
| 8 |
|
| 9 |
Definition subscript_map := |
| 10 |
Eval cbv in |
| 11 |
List.combine |
| 12 |
["("; ")"; "+"; "-"; |
| 13 |
"0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9"; |
| 14 |
"="; |
| 15 |
"a"; "e"; "h"; "i"; "j"; "k"; "l"; "m"; "n"; "o"; "p"; "r"; "s"; "t"; "u"; "v"; "x"; "y"]%char |
| 16 |
["₍"; "₎"; "₊"; "₋"; |
| 17 |
"₀"; "₁"; "₂"; "₃"; "₄"; "₅"; "₆"; "₇"; "₈"; "₉"; |
| 18 |
"₌"; |
| 19 |
"ₐ"; "ₑ"; "ₕ"; "ᵢ"; "ⱼ"; "ₖ"; "ₗ"; "ₘ"; "ₙ"; "ₒ"; "ₚ"; "ᵣ"; "ₛ"; "ₜ"; "ᵤ"; "ᵥ"; "ₓ"; "ᵧ"]%string. |
| 20 |
|
| 21 |
Module Ascii. |
| 22 |
Definition to_subscript_opt (c : ascii) : option string |
| 23 |
:= option_map snd (find (fun '(ch, _) => Ascii.eqb c ch) subscript_map). |
| 24 |
Definition to_subscript (c : ascii) : string |
| 25 |
:= match to_subscript_opt c with |
| 26 |
| Some s => s |
| 27 |
| None => String c EmptyString |
| 28 |
end. |
| 29 |
End Ascii. |
| 30 |
|
| 31 |
Module Export WORKAROUND_EXTRACTION_DONT_SHADOW_OCAML_STRING. |
| 32 |
Module String. |
| 33 |
Definition to_subscript (s : string) : string |
| 34 |
:= string_of_list_ascii (List.flat_map (fun a => list_ascii_of_string (Ascii.to_subscript a)) (list_ascii_of_string s)). |
| 35 |
End String. |
| 36 |
End WORKAROUND_EXTRACTION_DONT_SHADOW_OCAML_STRING. |