summaryrefslogtreecommitdiff
path: root/src/lib/parser.mly
blob: 68809fc548a2fa4d5d3cd24c52416d282ef1dd6c (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
(*

See [1] for the theory behind the analysis


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


   *)
%parameter<T:Sounds.T>



%{

    module P = Process.M(T)

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

%%

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

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

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

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

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

  | X               { T.ch }

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

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

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

consonant: 
  | occlusiv        { $1 }
  | fricativ        { $1 }
  | liquid          { $1 }
  | nasal           { $1 }

semi_voyel: 
  | Y               { T.semi_voyel_y }
  | W               { T.semi_voyel_w }

opening_consonant:
  | occlusiv            { $1, None }
  | fricativ            { $1, None }
  | nasal               { $1, None }
  | liquid              { $1, None }
  | obstruent liquid    { $1, Some $2 }
  | occlusiv fricativ   { $1, Some $2 }
  | consonant semi_voyel{ $1, Some $2 }
  | semi_voyel          { $1, None }


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

nasal_voyels:
  | A N             { T.a' ()      , T.a' ()      }
  %prec Low

ending_consonant: 
  | B               { Some (T.b ) }
  | T               { None }
  | liquid          { Some $1 }
  | nasal           { Some $1 }

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

syllable:
  | c = consonant_group?
    v = voyels
    Sep?
    { (v, c) }


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

word:
  | Sep? syllables consonant_group? EOL { P.rebuild $3 $2 }

main: 
  | word { $1 }