diff options
-rw-r--r-- | src/lib/modifiers/mute.ml | 6 | ||||
-rw-r--r-- | src/lib/repr/tengwar.ml | 149 | ||||
-rw-r--r-- | src/lib/sounds/sounds.ml | 29 | ||||
-rw-r--r-- | src/lib/sounds/sounds.mli | 5 |
4 files changed, 95 insertions, 94 deletions
diff --git a/src/lib/modifiers/mute.ml b/src/lib/modifiers/mute.ml index 7b58336..2a307e0 100644 --- a/src/lib/modifiers/mute.ml +++ b/src/lib/modifiers/mute.ml @@ -9,9 +9,9 @@ let process = fun init -> let ((v, c) , ending) = init in let is_voyel = Sounds.is_voyel v in - match is_voyel, c with - | false, Some c -> - let c = { c with Sig.opening = List.map ~f:Sounds.muted c.Sig.opening } in + match is_voyel, c, ending with + | false, Some c, None -> + let c = { c with Sig.opening = List.map ~f:Sounds.mute c.Sig.opening } in ((v, Some c) , ending) | _ -> init diff --git a/src/lib/repr/tengwar.ml b/src/lib/repr/tengwar.ml index c913574..e198964 100644 --- a/src/lib/repr/tengwar.ml +++ b/src/lib/repr/tengwar.ml @@ -8,8 +8,10 @@ type position = | Pos2 | Pos3 | Pos4 - | Lower1 - | Lower2 + | Lower5 (* Position for the Lambe (Theta inside) *) + | Lower_1_2 (* Position for the Harma *) + | Lower_3_1 (* Position for the Calma *) + | Lower_4_2 (* Position for the Thule *) (** Consonant category *) type category = @@ -23,7 +25,7 @@ type voyel = ; app : (position -> string) } type consonant = - { position : position * position + { position : position ; muted: string option ; repr : string ; primary : bool @@ -46,12 +48,10 @@ let empty_glyph = let pair : voyel -> consonant -> string = fun voyel consonant -> - match voyel.position with - | `Above -> voyel.app (fst consonant.position) - | `Below -> voyel.app (snd consonant.position) + voyel.app consonant.position let portant = - { position = Pos4, Lower1 + { position = Pos4 ; muted = None ; category = I ; primary = false @@ -88,6 +88,7 @@ let combine_glyph | Some _, Some _ -> Error () | None, any -> Ok any | any, None -> Ok any in + (* Combine only if everything is ok *) match tengwa, above, below with | Ok tengwa, Ok tehta_above, Ok tehta_below -> Some { tengwa; tehta_above; tehta_below} @@ -105,7 +106,7 @@ type application = (t -> t list) and t = | Consonant of consonant | Voyel of voyel - | Nasal of application + | Application of application | Repr of string | Glyph of glyph | Nothing @@ -118,30 +119,24 @@ let a' = { opened = true ; position = `Above ; app = function - | Pos1 -> "#" + | Pos1 | Lower_1_2 |Lower5 -> "#" | Pos2 -> "E" - | Pos3 -> "D" - | Pos4 -> "C" - | Lower1 -> "" - | Lower2 -> "" + | Pos3 | Lower_3_1 -> "D" + | Pos4 | Lower_4_2 -> "C" } let a = Voyel a' let app_e = function - | Pos1 -> "$" + | Pos1 | Lower_1_2 | Lower5 -> "$" | Pos2 -> "R" - | Pos3 -> "F" - | Pos4 -> "V" - | Lower1 -> "" - | Lower2 -> "" + | Pos3 | Lower_3_1 -> "F" + | Pos4 | Lower_4_2 -> "V" and app_eu = function - | Pos1 -> "Ü" + | Pos1 | Lower_1_2 | Lower5 -> "Ü" | Pos2 -> "Ý" - | Pos3 -> "Þ" - | Pos4 -> "ß" - | Lower1 -> "" - | Lower2 -> "" + | Pos3 | Lower_3_1 -> "Þ" + | Pos4 | Lower_4_2 -> "ß" let e_opened = Voyel { opened = true ; position = `Above ; app = app_e } @@ -152,12 +147,11 @@ and schwa = Voyel { opened = true ; position = `Below ; app = function - | Pos1 -> "È" - | Pos2 -> "É" + | Pos1 | Lower_3_1 -> "È" + | Pos2 | Lower_1_2 | Lower_4_2 -> "É" | Pos3 -> "Ê" | Pos4 -> "Ë" - | Lower1 -> "Ë" - | Lower2 -> "L" + | Lower5 -> "L" } and eu_opened = Voyel { opened = true ; position = `Above ; app = app_eu } @@ -167,12 +161,10 @@ and o' = { opened = true ; position = `Above ; app = function - | Pos1 -> "^" + | Pos1 | Lower_1_2 | Lower5 -> "^" | Pos2 -> "Y" - | Pos3 -> "H" - | Pos4 -> "N" - | Lower1 -> "" - | Lower2 -> "" + | Pos3 | Lower_3_1 -> "H" + | Pos4 | Lower_4_2 -> "N" } let o = Voyel o' @@ -181,12 +173,10 @@ and i' = { opened = true ; position = `Above ; app = function - | Pos1 -> "%" + | Pos1 | Lower_1_2 | Lower5 -> "%" | Pos2 -> "T" - | Pos3 -> "G" - | Pos4 -> "B" - | Lower1 -> "" - | Lower2 -> "" + | Pos3 | Lower_3_1 -> "G" + | Pos4 | Lower_4_2 -> "B" } let i = Voyel i' @@ -195,12 +185,10 @@ and y' = { opened = true ; position = `Above ; app = function - | Pos1 -> "Ø" + | Pos1 | Lower_1_2 | Lower5 -> "Ø" | Pos2 -> "Ù" - | Pos3 -> "Ú" - | Pos4 -> "Û" - | Lower1 -> "" - | Lower2 -> "" + | Pos3 | Lower_3_1 -> "Ú" + | Pos4 | Lower_4_2 -> "Û" } let y = Voyel y' @@ -209,142 +197,147 @@ and u = Voyel { opened = true ; position = `Above ; app = function - | Pos1 -> "&" + | Pos1 | Lower_1_2 | Lower5 -> "&" | Pos2 -> "U" - | Pos3 -> "J" - | Pos4 -> "M" - | Lower1 -> "" - | Lower2 -> "" + | Pos3 | Lower_3_1 -> "J" + | Pos4 | Lower_4_2 -> "M" } and p = Consonant - { position = Pos2, Lower1 + { position = Pos2 ; muted = Some "y" ; category = II ; primary = true ; repr = "q" } and b = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = Some "y" ; category = II ; primary = true ; repr = "w" } and t = Consonant - { position = Pos2, Lower1 + { position = Pos2 ; muted = Some "6" ; category = I ; primary = true ; repr = "1" } and d = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = Some "6" ; category = I ; primary = true ; repr = "2" } and k = Consonant - { position = Pos3, Lower1 + { position = Lower_3_1 ; muted = Some "h" ; category = III ; primary = true ; repr = "a" } and g = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = Some "h" ; category = III ; primary = true ; repr = "s" } and f = Consonant - { position = Pos3, Lower1 + { position = Pos3 ; muted = None ; category = II ; primary = true ; repr = "e" } and v = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = None ; category = II ; primary = true ; repr = "r" } and ch = Consonant - { position = Pos1, Lower1 + { position = Lower_1_2 ; muted = None ; category = III ; primary = true ; repr = "d" } and j = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = None ; category = III ; primary = true ; repr = "f" } and s = Consonant - { position = Pos4, Lower1 + { position = Lower_4_2 ; muted = Some "i" ; category = I ; primary = true ; repr = "3" } and z = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = None ; category = I ; primary = true ; repr = "4" } and m = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = None ; category = II ; primary = true ; repr = "t" } and n = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = None ; category = I ; primary = true ; repr = "5" } and gn = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = None ; category = III ; primary = false ; repr = "b" } +and ng = Consonant + { position = Pos1 + ; muted = None + ; category = III + ; primary = true + ; repr = "g" } + and r = Consonant - { position = Pos2, Lower1 + { position = Pos2 ; muted = Some "u" ; category = I ; primary = false ; repr = "7" } and semi_voyel_w = Consonant - { position = Pos3, Lower1 + { position = Pos3 ; muted = None ; category = II ; primary = false ; repr = "." } and semi_voyel_y = Consonant - { position = Pos1, Lower1 + { position = Pos1 ; muted = None ; category = II ; primary = false ; repr = "l" } and semi_voyel_u = Consonant - { position = Pos2, Lower1 + { position = Pos2 ; muted = None ; category = II ; primary = false @@ -352,7 +345,7 @@ and semi_voyel_u = Consonant let l = let default = - { position = Pos1, Lower2 + { position = Lower5 ; muted = None ; category = II ; primary = false @@ -360,7 +353,7 @@ let l = Consonant default let nasal letter = - Nasal + Application ( function | Consonant { category = II; _} as f -> let Consonant c = m [@@warning "-8"] in @@ -370,7 +363,7 @@ let nasal letter = ; tehta_above = Some letter } in g::f::[] | Consonant { category = III; _} as f -> - let Consonant c = gn [@@warning "-8"] in + let Consonant c = ng [@@warning "-8"] in let g = Glyph {empty_glyph with tengwa = Some c @@ -397,11 +390,10 @@ let muted | Consonant c -> begin match c.muted with | None -> t - | Some s -> Consonant {c with repr = s} + | Some s -> Consonant {c with repr = s ; position = Pos2} end | _ -> t - let diphtongue : t -> t -> t = fun t1 t2 -> @@ -411,7 +403,7 @@ let diphtongue let semi_voyel = Glyph { empty_glyph with tengwa = Some c} in - Nasal (fun t -> semi_voyel::t2::t::[]) + Application (fun t -> semi_voyel::t2::t::[]) | _ -> print_endline "Ignoring diphtongue"; Nothing @@ -437,19 +429,18 @@ let fold _fold (Some {empty_glyph with tengwa = Some c}) tl - | None, Voyel ({position = `Above; _} as v) -> + | None, Voyel v -> _fold - (Some {empty_glyph with tehta_above = Some v}) - tl - | None, Voyel ({position = `Below; _} as v) -> - _fold - (Some {empty_glyph with tehta_below = Some v}) + (Some ( + add_voyel_to_glyph + {empty_glyph with tehta_above = Some v} + v) ) tl | None, Repr r -> Buffer.add_string buff r; _fold None tl - | any, Nasal n -> + | any, Application n -> let next, rest = match tl with | [] -> Nothing, [] | other::ll -> other, ll in diff --git a/src/lib/sounds/sounds.ml b/src/lib/sounds/sounds.ml index cc801dd..aad7cf0 100644 --- a/src/lib/sounds/sounds.ml +++ b/src/lib/sounds/sounds.ml @@ -116,14 +116,11 @@ let voyel_u = let p = { none with - code = Consonant_P - ; mutable_ = false } + code = Consonant_P } let b = { none with - code = Consonant_B - ; mutable_ = false - } + code = Consonant_B } let t = { none with @@ -143,6 +140,11 @@ let g = { none with code = Consonant_G } +(** f is alway pronounend in ending consonant. Know exeception are : + - cerf + - clef + - nerf + - serf *) let f = { none with code = Consonant_F @@ -227,18 +229,23 @@ let rec nasal t = | Voyel, _ -> Some { t with nasal = true } | _ -> None -let muted f = - (* f is alway pronounend in endding consonant. Know exeception are : - - cerf - - clef - - nerf - - serf *) +let is_muted t = + match t.code with + | Muted _ -> true + | _ -> false + +let mute f = match f.mutable_ with | false -> f | true -> { none with code = Muted f } +let unmute t = + match t.code with + | Muted t -> t + | _ -> t + let repr : (module Sig.REPR) -> t list -> string = fun m letters -> diff --git a/src/lib/sounds/sounds.mli b/src/lib/sounds/sounds.mli index 3b7b760..fb902cb 100644 --- a/src/lib/sounds/sounds.mli +++ b/src/lib/sounds/sounds.mli @@ -1,7 +1,6 @@ module Sig = Sig type t -val muted : t -> t val a : t val e : [`Closed | `Opened] -> t @@ -75,5 +74,9 @@ val semi_voyel_u: t val is_voyel : t -> bool val is_nasal : t -> bool +val is_muted : t -> bool +val mute : t -> t +val unmute: t -> t + val repr : (module Sig.REPR) -> t list -> string |