10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-27 14:53:32 +01:00
QCaml/Nuclei/Xyz_parser.mly

89 lines
2.0 KiB
OCaml
Raw Normal View History

2018-01-17 15:56:57 +01:00
/* Parses nuclear coordinates in xyz format */
2017-12-31 18:27:58 +01:00
%{
exception InputError of string
2018-02-13 17:36:25 +01:00
let make_angstrom x y z =
Angstrom.make {
Point.
x ; y ; z
}
let output_of f x y z =
let a = make_angstrom x y z in
fun e ->
{
Xyz_ast.
element = f e;
coord = a ;
}
let output_of_string = output_of Element.of_string
let output_of_int = output_of Element.of_int
2017-12-31 18:27:58 +01:00
%}
%token EOL
%token <string> SPACE
%token <string> WORD
%token <int> INTEGER
%token <float> FLOAT
%token EOF
2018-01-17 15:56:57 +01:00
%start input
2018-02-13 17:36:25 +01:00
%type <Xyz_ast.xyz_file> input
2017-12-31 18:27:58 +01:00
%% /* Grammar rules and actions follow */
2018-01-17 15:56:57 +01:00
input:
2018-01-02 22:33:17 +01:00
| integer title atoms_xyz {
2018-02-13 17:36:25 +01:00
{
number_of_atoms = $1;
file_title = $2;
nuclei = $3;
}
}
;
2017-12-31 18:27:58 +01:00
integer:
| INTEGER EOL { $1 }
| INTEGER SPACE EOL { $1 }
2018-02-11 18:12:58 +01:00
| SPACE INTEGER EOL { $2 }
| SPACE INTEGER SPACE EOL { $2 }
2018-02-13 17:36:25 +01:00
;
2017-12-31 18:27:58 +01:00
title:
| title_list EOL { $1 }
2018-02-13 17:36:25 +01:00
;
2017-12-31 18:27:58 +01:00
text:
2018-01-18 17:39:10 +01:00
| WORD { $1 }
| SPACE { $1 }
| FLOAT { (string_of_float $1)}
| INTEGER { (string_of_int $1)}
2018-02-13 17:36:25 +01:00
;
2017-12-31 18:27:58 +01:00
title_list:
| { "" }
2018-01-18 17:39:10 +01:00
| title_list text { ($1 ^ $2) }
2018-02-13 17:36:25 +01:00
;
2017-12-31 18:27:58 +01:00
2018-01-02 22:33:17 +01:00
atoms_xyz:
2017-12-31 18:27:58 +01:00
| atoms_list EOL { List.rev $1 }
| atoms_list EOF { List.rev $1 }
2018-02-13 17:36:25 +01:00
;
2018-02-11 18:12:58 +01:00
2017-12-31 18:27:58 +01:00
atoms_list:
| { [] }
2018-02-13 17:36:25 +01:00
| atoms_list WORD SPACE FLOAT SPACE FLOAT SPACE FLOAT EOL { output_of_string $4 $6 $8 $2 :: $1 }
| atoms_list WORD SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { output_of_string $4 $6 $8 $2 :: $1 }
| atoms_list INTEGER SPACE FLOAT SPACE FLOAT SPACE FLOAT EOL { output_of_int $4 $6 $8 $2 :: $1 }
| atoms_list INTEGER SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { output_of_int $4 $6 $8 $2 :: $1 }
| atoms_list SPACE WORD SPACE FLOAT SPACE FLOAT SPACE FLOAT EOL { output_of_string $5 $7 $9 $3 :: $1 }
| atoms_list SPACE WORD SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { output_of_string $5 $7 $9 $3 :: $1 }
| atoms_list SPACE INTEGER SPACE FLOAT SPACE FLOAT SPACE FLOAT EOL { output_of_int $5 $7 $9 $3 :: $1 }
| atoms_list SPACE INTEGER SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { output_of_int $5 $7 $9 $3 :: $1 }
;
2017-12-31 18:27:58 +01:00