1signature INPUT = 2sig 3 val trans : string -> MathTypes.mlist 4 val overline : MathTypes.mlist -> MathTypes.noad 5 val underline : MathTypes.mlist -> MathTypes.noad 6 val fraction : MathTypes.mlist -> MathTypes.mlist -> MathTypes.noad 7 val atop : MathTypes.mlist -> MathTypes.mlist -> MathTypes.noad 8 val sup : MathTypes.mlist -> MathTypes.mlist -> MathTypes.noad 9 val sub : MathTypes.mlist -> MathTypes.mlist -> MathTypes.noad 10 val supsub : MathTypes.mlist -> MathTypes.mlist -> MathTypes.mlist -> MathTypes.noad 11 val sum : MathTypes.mlist option -> MathTypes.mlist option -> MathTypes.noad 12 val int : MathTypes.mlist option -> MathTypes.mlist option -> MathTypes.noad 13 val math : MathTypes.kind -> MathTypes.mlist -> MathTypes.noad 14 val style : BasicTypes.style -> MathTypes.noad 15 val choice : MathTypes.mlist -> MathTypes.mlist -> MathTypes.mlist -> MathTypes.mlist -> MathTypes.noad 16 val accent : string -> MathTypes.mlist -> MathTypes.noad 17 val sqrt : MathTypes.mlist -> MathTypes.noad 18 val delim : string -> BasicTypes.delim 19end 20(*----------*) 21 22structure Input: INPUT = 23struct 24 open BasicTypes; open MathTypes 25 open Char 26 27 val sumsym = MathChar (Op, EX, 80) 28 val intsym = MathChar (Op, EX, 82) 29 30 fun sym ch = 31 if isAlpha ch then (Ord, MI, ord ch) else 32 if isDigit ch orelse ch = #"@" then (Ord, RM, ord ch) else 33 if ch = #"(" orelse ch = #"[" then (Open, RM, ord ch) else 34 if ch = #")" orelse ch = #"]" then (Close, RM, ord ch) else 35 if ch = #"=" orelse ch = #":" then (Rel, RM, ord ch) else 36 if ch = #"<" orelse ch = #">" then (Rel, MI, ord ch) else 37 if contains "!?;" ch then (Punct, RM, ord ch) else 38 case ch of 39 #"," => (Punct, MI, 59) 40 | #"+" => (Bin, RM, 43) 41 | #"-" => (Bin, SY, 0) 42 | #"*" => (Bin, SY, 3) 43 | #"." => (Bin, SY, 1) 44 | _ => raise (NotImplemented ("Character " ^ toString ch)) 45 46 fun trans str = map (MathChar o sym) (String.explode str) 47 48 val overline = Overline 49 val underline = Underline 50 51 fun fraction num den = 52 GenFraction {num = num, den = den, thickness = NONE, left = NONE, right = NONE} 53 54 fun atop top bot = 55 GenFraction {num = top, den = bot, thickness = SOME 0, left = NONE, right = NONE} 56 57 fun sup a b = Script {nucleus = a, supOpt = SOME b, subOpt = NONE} 58 fun sub a b = Script {nucleus = a, supOpt = NONE, subOpt = SOME b} 59 fun supsub a b c = Script {nucleus = a, supOpt = SOME b, subOpt = SOME c} 60 61 fun bigop sym subopt supopt = 62 BigOp (default, {nucleus = [sym], supOpt = supopt, subOpt = subopt}) 63 64 val sum = bigop sumsym 65 val int = bigop intsym 66 67 fun math kind ml = Kind (kind, ml) 68 69 val style = Style 70 71 fun choice d t s ss = Choice (fn D => d | T => t | S => s | SS => ss) 72 73 fun accent "hat" base = Accent (RM, 94, base) 74 | accent "check" base = Accent (RM, 20, base) 75 | accent "tilde" base = Accent (RM, 126, base) 76 | accent "widehat" base = Accent (EX, 98, base) 77 | accent _ _ = raise (BasicTypes.NotImplemented "math accent") 78 79 fun sqrt ml = Radical (SOME (SY, 112, EX, 112), ml) 80 81 fun delim "lparen" = SOME (RM, 40, EX, 0) 82 | delim "rparen" = SOME (RM, 41, EX, 1) 83 | delim "lbracket" = SOME (RM, 91, EX, 2) 84 | delim "rbracket" = SOME (RM, 93, EX, 3) 85 | delim "langle" = SOME (SY, 104, EX, 10) 86 | delim "rangle" = SOME (SY, 105, EX, 11) 87 | delim "null" = NONE 88 | delim _ = raise (BasicTypes.NotImplemented "delim") 89 90end 91