@gsg, - -, , , . -, ocamllex:
12.7
ocamllex: , , ocamllex, 32767 . , lexer . , , . [...]
http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual026.html#toc111
.
lookup " " , (: Map HashTbl), . , , , :
{
type token = Case | Test | Ident of string
module KeywordTable =
Map.Make(struct
type t = string
let compare a b =
String.(compare (lowercase a) (lowercase b))
end)
let keyword_table =
List.fold_left
(fun (k, v) -> KeywordTable.add k v))
[
"case", Case;
"test", Test;
]
KeywordTable.empty
}
let ident_char = ['a'-'z' 'A'-'Z' '_']
rule next_token = parse
| ident_char+ as s {
try KeywordTable.find keyword_table s
with Not_found -> Ident s
}