10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-06-01 19:05:18 +02:00
QCaml/particles/lib/nuclei_lexer.mll

43 lines
932 B
OCaml
Raw Normal View History

2024-02-28 10:34:39 +01:00
(** Lexer to read xyz files *)
2023-04-24 19:01:42 +02:00
2017-12-31 18:27:58 +01:00
{
2018-01-17 15:56:57 +01:00
open Xyz_parser
2017-12-31 18:27:58 +01:00
}
let eol = ['\n']
let white = [' ' '\t']+
let word = [^' ' '\t' '\n']+
let letter = ['A'-'Z' 'a'-'z']
2020-12-29 18:06:54 +01:00
let integer = ['0'-'9']+
let real = '-'? (integer '.' integer | integer '.' | '.' integer) (['e' 'E'] ('+'|'-')? integer)?
2017-12-31 18:27:58 +01:00
rule read_all = parse
| eof { EOF }
| eol { EOL }
| white as w { SPACE w }
| integer as i { INTEGER (int_of_string i) }
| real as f { FLOAT (float_of_string f) }
| word as w { WORD w }
{
2018-01-18 17:39:10 +01:00
(* DEBUG
let () =
let ic = open_in "h2o.xyz" in
2017-12-31 18:27:58 +01:00
let lexbuf = Lexing.from_channel ic in
while true do
2018-01-18 17:39:10 +01:00
let s =
2017-12-31 18:27:58 +01:00
match read_all lexbuf with
| EOL -> "EOL"
| SPACE w -> "SPACE("^w^")"
| INTEGER i -> "INTEGER("^(string_of_int i)^")"
| FLOAT f -> "FLOAT("^(string_of_float f)^")"
| WORD w -> "WORD("^w^")"
| EOF -> "EOF"
in
print_endline s
2018-01-18 17:39:10 +01:00
done;
*)
2017-12-31 18:27:58 +01:00
}