summaryrefslogtreecommitdiff
path: root/src/lib/parser.mly
blob: 70590a0ff0c9fdf8d631d80c283d41202be51ecb (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
(*

See [1] for the theory behind the analysis


[1] https://fr.m.wiktionary.org/wiki/Annexe:Prononciation/fran%C3%A7ais#Structure_syllabique


   *)



%{
    open Modifiers.Sig

%}
%start<Sounds.t List.t> main

%%

occlusiv:
  | P               { Sounds.p }
  | B               { Sounds.b }

  | T               { Sounds.t }
  | D               { Sounds.d }

  | K               { Sounds.k }
  | G               { Sounds.g }

fricativ:
  | S               { Sounds.s }
  | SZ              { Sounds.sz }
  | Z               { Sounds.z }

  | F               { Sounds.f }
  | V               { Sounds.v }

  | X               { Sounds.ch }
  | J               { Sounds.j  }

obstruent:
  | occlusiv        { $1 }
  | fricativ        { $1 }

liquid:
  | L               { Sounds.l }
  | R               { Sounds.r }

nasal:
  | N               { Sounds.n }
  | M               { Sounds.m }


initial_nasal:
  | nasal           { $1 }
  | G N             { Sounds.gn }

opening_consonant:
  | occlusiv            { $1, None }
  | fricativ            { $1, None }
  | initial_nasal       { $1, None }
  | liquid              { $1, None }

opening_double:
  | obstruent liquid    { $1, Some $2 }
  | occlusiv fricativ   { $1, Some $2 }

(* Each voyel as two associated sounds, depending there is a followng sound or
   not *)
voyels:
  | A               { Sounds.a          }
  | A I             { Sounds.voyel_ai   }
  | E I             { Sounds.voyel_ai   }
  | I               { Sounds.i          }
  | E               { Sounds.schwa } 
  | E_ACUTE E?      { Sounds.e  `Closed }
  | E_AGRAVE        { Sounds.e  `Opened }
  | E U             { Sounds.eu `Opened }
  | O               { Sounds.o          }
  | U               { Sounds.voyel_y    }
  | OU              { Sounds.voyel_u    }
  (* This semi voyel can never be separated *)
  | W voyels        { Sounds.diphtongue Sounds.semi_voyel_w $2 }

voyels_semi:
  | voyels          { $1 }
  | I voyels        { Sounds.diphtongue Sounds.semi_voyel_y $2 }
  | Y voyels        { Sounds.diphtongue Sounds.semi_voyel_y $2 }
  | U voyels        { Sounds.diphtongue Sounds.semi_voyel_u $2 }

ending_consonant: 
  | Nothing         { Some (Sounds.none) }
  | occlusiv        { Some $1 }
  | liquid          { Some $1 }
  | nasal           { Some $1 }


%inline consonant_group(opening)
  : f = fricativ
    o = opening 
    { 
        { ending = None 
        ; opening = f::(fst o)::[]
        ; following = snd o  }
    }
  | o = opening 
    { 
        { ending = None 
        ; opening = [ fst o ]
        ; following = snd o  }
    }
  | e = ending_consonant
    Sep?
    o = opening
    { 
        { ending = Some e
        ; opening = [ fst o ]
        ; following = snd o  }
    }
  | e = ending_consonant
    Sep?
    f = fricativ
    o = opening
    { 
        { ending = Some e
        ; opening = f::[ fst o ]
        ; following = snd o }
    }


(** Exclude a semi voyel in both consonant and voyel position *)
syllable:
  | c = consonant_group(opening_consonant)?
    v = voyels_semi
    Sep?
    { (v, c) }
  | c = consonant_group(opening_double)
    v = voyels
    Sep?
    { (v, Some c) }


syllables:
  | { [] }
  | ss = syllables 
    s = syllable { s::ss }
    

word:
  | Sep? syllables consonant_group(opening_consonant)? 
        { Process.rebuild $3 $2 }

words: 
  | word { $1::[] }
  | ww=words Space w=word  { w:: [Sounds.space $2] ::ww }

main: 
  | words EOL        
        { List.concat (List.rev $1) }