-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.ml
72 lines (62 loc) · 2.2 KB
/
parse.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(* Pour les messages d'erreur du parseur de formule *)
let print_position outx lexbuf =
let open Lexing in
let pos = lexbuf.lex_curr_p in
Format.fprintf outx "%s:%d:%d" pos.pos_fname
pos.pos_lnum (pos.pos_cnum - pos.pos_bol + 1)
let parse_notes_with_error lexbuf: Note.t list =
try Parse_all.note_list Lex.next_token lexbuf with
| Lex.Error (lb,msg) as e ->
Format.eprintf " Lexical error, %a: %s@.@?" print_position lb msg;
raise e
| Parse_all.Error as e ->
Format.eprintf "syntax error, %a: @.@?" print_position lexbuf;
raise e
let parse_gamme_name_with_error lexbuf: Gamme.gammeStandard =
try Parse_all.gamme_name_eof Lex.next_token lexbuf with
| Lex.Error (lb,msg) as e ->
Format.eprintf " Lexical error, %a: %s@.@?" print_position lb msg;
raise e
| Parse_all.Error as e ->
Format.eprintf "syntax error, %a: @.@?" print_position lexbuf;
raise e
let parse_chiffrage_with_error lexbuf: Chiffrage.t =
try Parse_all.chiffrage_eof Lex.next_token lexbuf with
| Lex.Error (lb,msg) as e ->
Format.eprintf " Lexical error, %a: %s@.@?" print_position lb msg;
raise e
| Parse_all.Error as e ->
Format.eprintf "syntax error, %a: @.@?" print_position lexbuf;
raise e
let parse_portee_with_error lexbuf: (int*Chiffrage.t list) list =
try Parse_all.portee_eof Lex.next_token lexbuf with
| Lex.Error (lb,msg) as e ->
Format.eprintf " Lexical error, %a: %s@.@?" print_position lb msg;
raise e
| Parse_all.Error as e ->
Format.eprintf "syntax error, %a: @.@?" print_position lexbuf;
raise e
let parseNoteFile fname =
let ic = open_in fname in
let lb = Lexing.from_channel ic in
let form = parse_notes_with_error lb in
close_in ic;
form
let parseGammeFile fname =
let ic = open_in fname in
let lb = Lexing.from_channel ic in
let form = parse_gamme_name_with_error lb in
close_in ic;
form
let parseStringNotes s =
let lb = Lexing.from_string s in
let form = parse_notes_with_error lb in
form
let parseStringGamme s =
let lb = Lexing.from_string s in
let form = parse_gamme_name_with_error lb in
form
let parseStringChiffrage s =
let lb = Lexing.from_string s in
let form = parse_chiffrage_with_error lb in
form