40 lines
967 B
OCaml
40 lines
967 B
OCaml
module Token = struct
|
|
type token_type =
|
|
| ILLEGAL
|
|
| EOF
|
|
(* Identifiers and literals *)
|
|
| IDENT of string
|
|
| INTEGER of int
|
|
| FLOAT of float
|
|
| BOOL of bool
|
|
| STRING of string
|
|
| BINARY of Bytes.t
|
|
| NULL
|
|
(* -- Delimiters *)
|
|
| COLON
|
|
| COMMA
|
|
| LBRACE
|
|
| RBRACE
|
|
| LBRACKET
|
|
| RBRACKET
|
|
|
|
let equal (a:token_type) (b:token_type) = (=) a b
|
|
|
|
let token_to_string = function
|
|
| ILLEGAL -> "ILLEGAL"
|
|
| EOF -> "EOF"
|
|
| IDENT a -> "IDENT " ^ a
|
|
| INTEGER a -> "INTEGER " ^ Int.to_string a
|
|
| FLOAT a -> "FLOAT " ^ Float.to_string a
|
|
| BOOL a -> "BOOL " ^ Bool.to_string a
|
|
| STRING a -> "STRING " ^ a
|
|
| BINARY a -> "BINARY " ^ Bytes.fold_left (fun acc b -> acc ^ Printf.sprintf "\\x%2x" (Char.code b)) "" a
|
|
| NULL -> "NULL"
|
|
| COMMA -> "COMMA"
|
|
| COLON -> "COLON"
|
|
| LBRACE -> "LBRACE"
|
|
| RBRACE -> "RBRACE"
|
|
| LBRACKET -> "LBRACKET"
|
|
| RBRACKET -> "RBRACKET"
|
|
end
|