summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-08-27 17:20:59 +0200
committerSébastien Dailly <sebastien@chimrod.com>2021-08-27 17:20:59 +0200
commit26faec7a69051f639b50c8e8741f0823c6be52a2 (patch)
treea610d0306bf3e0c84f7993be7c290965fcab1900 /src
parentc8b49eed4cf92e7d2dd01dce779ef84ccae733eb (diff)
Managed diphtongues
Diffstat (limited to 'src')
-rw-r--r--src/lib/lexer.mll2
-rw-r--r--src/lib/modifiers/nasal.ml35
-rw-r--r--src/lib/parser.mly14
-rw-r--r--src/lib/process.ml16
-rw-r--r--src/lib/prononciation.mly19
-rw-r--r--src/lib/sounds/sounds.ml67
-rw-r--r--src/lib/tokens.mly5
-rw-r--r--src/test/test.ml10
8 files changed, 117 insertions, 51 deletions
diff --git a/src/lib/lexer.mll b/src/lib/lexer.mll
index f8a7f2c..07305d8 100644
--- a/src/lib/lexer.mll
+++ b/src/lib/lexer.mll
@@ -13,6 +13,8 @@ rule letter = parse
| 'c' { C }
| 'd' { D }
| 'e' { E }
+| '\232' { E_ACUTE }
+| '\xC3' '\xA8' { E_AGRAVE }
| '\233' { E_ACUTE }
| '\xC3' '\xA9' { E_ACUTE }
| 'f' { F }
diff --git a/src/lib/modifiers/nasal.ml b/src/lib/modifiers/nasal.ml
index da24863..b9874c9 100644
--- a/src/lib/modifiers/nasal.ml
+++ b/src/lib/modifiers/nasal.ml
@@ -9,15 +9,28 @@ let process
let module T = (val m:Sounds.T with type t = el) in
let (((v1, v2), c) , ending) = init in
let ending = Option.bind ending (fun x -> x) in
- match ending with
- | None -> init
- | Some ending ->
- match T.is_nasal ending with
- | false -> init
- | true ->
- (* Remove the ending consonant, and transform the voyel into
- the nasal form *)
- ( ( (T.nasal v1, T.nasal v2)
- , c )
- , None )
+ let opening = Option.map (fun v -> v.Sig.opening) c in
+ let is_voyel = T.is_voyel v1 && T.is_voyel v2 in
+ match ending, is_voyel, opening with
+ | Some ending, _, _ when T.is_nasal ending ->
+ (* Remove the ending consonant, and transform the voyel into
+ the nasal form *)
+ ( ( (T.nasal v1, T.nasal v2)
+ , c )
+ , None )
+ | None, false, Some (opening::tl) when T.is_nasal opening ->
+ (* If there is no voyel here, transform the opening consonant as an
+ ending consonant for the next syllabus *)
+ let c = Option.map
+ (fun c ->
+ { c with
+ Sig.opening = tl
+ ; Sig.ending = (Some (Some opening))
+ }) c in
+ ( ( (T.nasal v1, T.nasal v2)
+ , c )
+ , None )
+ | _ ->
+ (* Return the element unchanged *)
+ init
diff --git a/src/lib/parser.mly b/src/lib/parser.mly
index 2a94839..f12e2cc 100644
--- a/src/lib/parser.mly
+++ b/src/lib/parser.mly
@@ -28,7 +28,7 @@ occlusiv:
| D { T.d }
| K { T.k }
- | G { T.none }
+ | G { T.g }
fricativ:
| S { T.s () }
@@ -75,14 +75,18 @@ opening_consonant:
(* Each voyel as two associated sounds, depending there is a followng sound or
not *)
voyels:
- | A { T.a `Opened , T.a `Opened }
+ | A { T.a , T.a }
| A I { T.e `Opened , T.e `Opened }
- | I { T.i `Opened , T.i `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.u , T.u }
+ | OU { T.u' , T.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}
nasal_voyels:
| A N { T.a' () , T.a' () }
@@ -113,12 +117,14 @@ consonant_group:
syllable:
| c = consonant_group?
v = voyels
+ Sep?
{ (v, c) }
syllables:
| { [] }
- | ss = syllables s = syllable { s::ss }
+ | ss = syllables
+ s = syllable { s::ss }
word:
diff --git a/src/lib/process.ml b/src/lib/process.ml
index a74c44b..8c463b5 100644
--- a/src/lib/process.ml
+++ b/src/lib/process.ml
@@ -32,7 +32,6 @@ module M(T:Sounds.T) = struct
= function
| [] -> acc
| hd::tl ->
-
let modifier = (Modifiers.vocalize_s) :: (Modifiers.nasal) :: m in
let (voyel, consonants), ending_consonant =
apply_modifiers
@@ -41,18 +40,17 @@ module M(T:Sounds.T) = struct
let voyel = change_voyel ((voyel, consonants), ending_consonant) in
(* Add the last consonant and the voyel *)
- let m, acc = match ending_consonant with
- | None -> modifier, voyel::acc
+ let acc = match ending_consonant with
+ | None -> voyel::acc
| Some s ->
- let default = modifier, voyel :: acc in
+ let default = voyel :: acc in
match s with
| None -> default
| Some s ->
-
- modifier, voyel :: s::acc in
+ voyel :: s::acc in
match consonants with
- | None -> _rebuild ~m acc None tl
+ | None -> _rebuild ~m:[] acc None tl
| Some {ending; opening; following} ->
let acc = match following with
@@ -60,8 +58,8 @@ module M(T:Sounds.T) = struct
| Some s -> s::acc in
match opening with
- | [] ->_rebuild ~m acc ending tl
- | opening -> _rebuild ~m (opening @ acc) ending tl
+ | [] ->_rebuild ~m:[] acc ending tl
+ | opening -> _rebuild ~m:[] (opening @ acc) ending tl
(** Rebuild the list in the normal order
diff --git a/src/lib/prononciation.mly b/src/lib/prononciation.mly
index 3195078..5dbf153 100644
--- a/src/lib/prononciation.mly
+++ b/src/lib/prononciation.mly
@@ -14,14 +14,15 @@
%%
initial_voyel:
- | A { A }
- | A U { O }
- | E { E }
- | I { I }
- | O { O }
- | U { U }
- | U I { UI }
- | E_ACUTE { E_ACUTE }
+ | A { A }
+ | A U { O }
+ | E { E }
+ | I { I }
+ | O { O }
+ | O U { OU }
+ | U { U }
+ | E_ACUTE { E_ACUTE }
+ | E_AGRAVE { E_AGRAVE }
voyel:
| initial_voyel { $1 }
@@ -57,6 +58,8 @@ letters:
| letters N { N :: $1 }
| letters N N { N :: $1 }
+ | letters O I N { N :: I :: W :: $1 }
+ | letters O I { A :: W :: $1 }
| letters P { P :: $1 }
| letters P H { F :: $1 }
diff --git a/src/lib/sounds/sounds.ml b/src/lib/sounds/sounds.ml
index a2035b7..6126dd4 100644
--- a/src/lib/sounds/sounds.ml
+++ b/src/lib/sounds/sounds.ml
@@ -3,15 +3,18 @@ module type T = sig
type t
val muted : t -> t
- val a : [`Closed | `Opened] -> t
+ val a : t
val e : [`Closed | `Opened] -> t
val eu : [`Closed | `Opened] -> t
val o : [`Closed | `Opened] -> t
val schwa : unit -> t
- val i : [`Closed | `Opened] -> t
+ val i : t
val u : t
+ val u' : t
+ (** Create a diphtongue from a semi-voyel and a voyel *)
+ val diphtongue: t -> t -> t
val nasal: t -> t
@@ -22,6 +25,7 @@ module type T = sig
val t: t
val d: t
val k: t
+ val g: t
val f: t
val s: unit -> t
val sz: unit -> t
@@ -43,7 +47,10 @@ module type T = sig
| None
| SZ
| Voyel_A
+ | Voyel_I
| Voyel_O
+ | SemiVoyel_W
+ | Diphtonge of code * code
val code : t -> code
@@ -58,7 +65,10 @@ module T = struct
| None
| SZ
| Voyel_A
+ | Voyel_I
| Voyel_O
+ | SemiVoyel_W
+ | Diphtonge of code * code
type t =
{ code : code
@@ -79,7 +89,9 @@ module Repr = struct
and o_nasal = "§"
and i = "i"
+ and i_nasal = "5"
and u = "y"
+ and u' = "u"
and p = "p"
and b = "b"
@@ -112,6 +124,7 @@ module S = struct
let is_voyel t = t.kind = Voyel
let is_nasal t = t.nasal
+
let none =
{ repr = ""
; muted = false
@@ -122,20 +135,17 @@ module S = struct
let voyel =
{ none with kind = Voyel }
- let code t = t.code
- let nasal t =
- match t.code with
- | Voyel_A -> { t with repr = Repr.a_nasal ; nasal = true }
- | Voyel_O -> { t with repr = Repr.o_nasal ; nasal = true }
- | _ -> t
+ let diphtongue v1 v2 =
+ { voyel with
+ repr = (v1.repr) ^ (v2.repr)
+ ; code = Diphtonge (v1.code, v2.code)
+ }
- let muted f =
- { none with
- repr = "(" ^ f.repr ^ ")"
- ; muted = true }
- let a _ =
+ let code t = t.code
+
+ let a =
{ voyel with repr = Repr.a ; code = Voyel_A }
let e = function
@@ -153,12 +163,15 @@ module S = struct
let o _ =
{ voyel with repr = Repr.o ; code = Voyel_O }
- let i _ =
- { voyel with repr = Repr.i }
+ let i =
+ { voyel with repr = Repr.i ; code = Voyel_I }
let u =
{ voyel with repr = Repr.u }
+ let u' =
+ { voyel with repr = Repr.u' }
+
let p =
{ none with repr = Repr.p }
@@ -174,6 +187,9 @@ module S = struct
let k =
{ none with repr = Repr.k }
+ let g =
+ { none with repr = Repr.g }
+
let f =
{ none with repr = Repr.f }
@@ -202,7 +218,26 @@ module S = struct
{ none with repr = Repr.r }
let semi_voyel_w =
- { none with repr = Repr.w }
+ { none with
+ repr = Repr.w
+ ; code = SemiVoyel_W}
+
+ let nasal t =
+ match t.code with
+ | Voyel_A -> { t with repr = Repr.a_nasal ; nasal = true }
+ | Voyel_O -> { t with repr = Repr.o_nasal ; nasal = true }
+ | Voyel_I -> { t with repr = Repr.i_nasal ; nasal = true }
+ | Diphtonge (SemiVoyel_W, Voyel_A) ->
+ diphtongue
+ semi_voyel_w
+ { t with repr = Repr.i_nasal ; nasal = true }
+ | _ -> t
+
+ let muted f =
+ { none with
+ repr = "(" ^ f.repr ^ ")"
+ ; muted = true }
+
end
include S
diff --git a/src/lib/tokens.mly b/src/lib/tokens.mly
index 5466e90..0bceeac 100644
--- a/src/lib/tokens.mly
+++ b/src/lib/tokens.mly
@@ -6,6 +6,7 @@
%token D
%token E
%token E_ACUTE
+%token E_AGRAVE
%token F
%token G
%token H
@@ -16,6 +17,7 @@
%token M
%token N
%token O
+%token OU
%token Q
%token P
%token R
@@ -23,7 +25,6 @@
%token SZ
%token T
%token U
-%token UI
%token V
%token W (* semi voyel w *)
%token X
@@ -34,7 +35,7 @@
%nonassoc Low
-%right A E E_ACUTE I O U
+%right A E E_ACUTE I O U OU
%right C H J Q V W X Y Z
%right P B T D K G
diff --git a/src/test/test.ml b/src/test/test.ml
index a8ac890..852349d 100644
--- a/src/test/test.ml
+++ b/src/test/test.ml
@@ -58,12 +58,20 @@ let tests =
; "chanci", "S@si"
; "chat", "Sa(t)"
; "chipant", "Sip@(t)"
+ ; "co|incidant", "ko5sid@(t)"
+ ; "croire", "kRwaR°"
+ ; "ébrouas", "ebRua(s)"
+ ; "loin", "Lw5"
+ ; "groin", "gRw5"
; "pacha", "paSa"
; "péché", "peSe"
; "persai", "pERsE"
+ ; "plan", "pL@"
; "plat", "pLa(t)"
; "platte", "pLat°"
- ; "web", "wEb"
+ ; "toiture", "twatyR°"
+ ; "trois", "tRwa(s)"
+ ; "wèb", "wE(b)"
]
let () =