-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_all.mly
124 lines (107 loc) · 3.02 KB
/
parse_all.mly
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
%{
(* open PhaseGraph *)
(* module F = Formula *)
%}
(** Reserved Symbols *)
%token EOF
(** Formula tokens *)
%token DIESE BEMOL MAJEUR MINEUR DO RE MI FA SOL LA SI PT VIRG PV
%token <string> ID
%token <int> INT
(** unrecognized token *)
%token UNKNOWN
/* %start <Formula.t> formula_main */
%start <Note.t> note_eof
/* %start <Accord.t> accord */
%start <Note.t list> note_list
%start <Gamme.gammeStandard> gamme_name_eof
%start <Chiffrage.t> chiffrage_eof
%start <(int*Chiffrage.t list) list> portee_eof
%%
(* Generic lists with separator and an optional final separator.
See http://gallium.inria.fr/blog/lr-lists/ for explanations. *)
flexible_list(delim, X):
| (* nothing *) { [] }
| x = X { [x] }
| x = X delim xs = flexible_list(delim, X) { x :: xs }
;
(* Same as flexible_list but with the optional separator is at start
(e.g. match foo with | ... | ... end) *)
flexible_list_on_start(delim, X):
| (* nothing *) { [] }
| x = X { [x] }
| xs = flexible_list_on_start(delim, X) delim x = X { x :: xs }
;
(* ********************* FORMULA ******************** *)
note_list:
/* | l=list(note) EOF { l } */
| n=note EOF { [n] }
| n=note l=note_list { n::l }
;
(* Formulas that can appear in a list without being inside parenthesis *)
note_eof:
| n = note EOF { n }
;
gamme_name_eof:
| g=gamme_name EOF { g }
(* Formulas that can appear in a list without being inside parenthesis *)
note:
| n = note_simple { n }
| n = note_simple DIESE { Note.diesify n }
| n = note_simple BEMOL { Note.bemolify n }
/* | n = note_simple BECARE { becarify n } */
;
chiffrage_eof:
| c=chiffrage_complet EOF { c }
;
chiffrage_complet:
| n = note
l=list(chiffrage) {
let updated_indics =
(* l has dummy notes in relative chiffrages replace them by n *)
List.map Chiffrage.(
function
| (Diese (Relative (_,i))) -> (Diese (Relative (n,i)))
| (Bemol (Relative (_,i))) -> (Bemol (Relative (n,i)))
| (Exact (Relative (_,i))) -> (Exact (Relative (n,i)))
| c -> c)
l in
Chiffrage.{basse=n; indics = updated_indics} }
;
chiffrage:
| n = note_simple { Chiffrage.(Exact (Absolu n)) }
| n = note_simple DIESE { Chiffrage.(Diese (Absolu n)) }
| n = note_simple BEMOL { Chiffrage.(Bemol (Absolu n)) }
| i = INT DIESE {let dummy_note = Note.C in Chiffrage.(Diese (Relative (dummy_note,i)))}
| i = INT BEMOL {let dummy_note = Note.C in Chiffrage.(Bemol (Relative (dummy_note,i)))}
| i = INT {let dummy_note = Note.C in Chiffrage.(Exact (Relative (dummy_note,i)))}
;
gamme_name:
| n=note MAJEUR { Gamme.Majeur n }
| n=note MINEUR { Gamme.Mineur n }
| n=note g=ID { Gamme.parseName n g }
;
note_simple:
| DO {Note.C}
| RE {Note.D}
| MI {Note.E}
| FA {Note.F}
| SOL{Note.G}
| LA {Note.A}
| SI {Note.B}
;
portee_eof:
p=portee EOF {p}
;
portee:
| { [] }
| m = mesure p = portee {m::p}
;
mesure:
| n = mes_num c=chiffrage_complet PV { (fst n,[c]) }
| n = mes_num c1=chiffrage_complet VIRG c2=chiffrage_complet PV { (fst n, [c1;c2]) }
;
mes_num:
| i=INT PT {(i,0)}
| i=INT VIRG j=INT PT {(i,j)}
;