ce/token.ml

33 lines
540 B
OCaml

type t =
| Value of Ast.Value.t
| Ident of string
| Plus
| Minus
| Asterisk
| Slash
| Carret
| Percent
| LParen
| RParen
| Equal
let tokens = ref [
"+", Plus;
"-", Minus;
"*", Asterisk;
"/", Slash;
"^", Carret;
"%", Percent;
"(", LParen;
")", RParen;
"=", Equal;
]
let to_string = function
| Value v -> Ast.Value.to_string v
| Ident s -> s
| t ->
begin match List.find_opt (fun (_, tok) -> t = tok) !tokens with
| None -> failwith "Token.to_string"
| Some (s, _) -> s
end