summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-09-07 22:33:45 +0200
committerSébastien Dailly <sebastien@chimrod.com>2021-09-07 22:33:45 +0200
commit80b77d19cee0f3df4457005eead1128b90754a48 (patch)
tree52a36a9f68a2ba06631c1a1a48576afb9c617cc8 /src/lib
parent96a225fb5fa24a71e1b76e0369126b3bcfab5f81 (diff)
Added tests
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/lexer.mll1
-rw-r--r--src/lib/modifiers/e.ml9
-rw-r--r--src/lib/parser.mly3
-rw-r--r--src/lib/prononciation.mly4
-rw-r--r--src/lib/reader.ml1
-rw-r--r--src/lib/repr/tengwar.ml271
6 files changed, 281 insertions, 8 deletions
diff --git a/src/lib/lexer.mll b/src/lib/lexer.mll
index 50c25a7..2d6224c 100644
--- a/src/lib/lexer.mll
+++ b/src/lib/lexer.mll
@@ -51,6 +51,7 @@ rule letter = parse
| "el" ending { EL_ }
| "ent" ending { ENT_ }
| "ient" ending { IENT_ }
+| "ie" ending { IE_ }
| "x" ending { X_ }
(* This rule looks for a single line, terminated with '\n' or eof.
diff --git a/src/lib/modifiers/e.ml b/src/lib/modifiers/e.ml
index bd4a940..2779544 100644
--- a/src/lib/modifiers/e.ml
+++ b/src/lib/modifiers/e.ml
@@ -8,9 +8,12 @@ let ending_e
= fun init ->
let ((v, c) , ending) = init in
+ (*
if v = Sounds.diphtongue Sounds.semi_voyel_y Sounds.schwa then
((Sounds.i, c), ending)
- else if v = Sounds.schwa then (
+ else
+ *)
+ if v = Sounds.schwa then (
match c, ending with
(* If there is no consonant, and just a final e, remove it *)
| None, None -> ((Sounds.none, c), ending)
@@ -25,10 +28,6 @@ let process
let ((v, c) , ending) = init in
match ending with
- | None when v = Sounds.schwa ->
- (* If there is no more consononant in the syllabe, change the e
- into eu, like in sera *)
- ((Sounds.eu `Closed, c) , ending)
| Some _ when v = Sounds.schwa ->
(* If there is an ending consonant, change the e into E like essai *)
((Sounds.e `Opened, c) , ending)
diff --git a/src/lib/parser.mly b/src/lib/parser.mly
index 42623c7..9d44b1f 100644
--- a/src/lib/parser.mly
+++ b/src/lib/parser.mly
@@ -60,7 +60,7 @@ consonant:
| nasal { $1 }
semi_voyel:
- | Y { Sounds.semi_voyel_y }
+ (* | Y { Sounds.semi_voyel_y } *)
| W { Sounds.semi_voyel_w }
opening_consonant:
@@ -95,6 +95,7 @@ voyels_semi:
| W A { Sounds.diphtongue Sounds.semi_voyel_w Sounds.a}
| W I { Sounds.diphtongue Sounds.semi_voyel_w Sounds.i}
| I voyels { Sounds.diphtongue Sounds.semi_voyel_y $2 }
+ | Y voyels { Sounds.diphtongue Sounds.semi_voyel_y $2 }
ending_consonant:
| Nothing { Some (Sounds.none) }
diff --git a/src/lib/prononciation.mly b/src/lib/prononciation.mly
index 75d9d8b..614f120 100644
--- a/src/lib/prononciation.mly
+++ b/src/lib/prononciation.mly
@@ -112,6 +112,8 @@ letters
| N N { N :: [] }
| O I { W :: A :: [] }
+ | O IE_ { W :: A :: [] }
+ | O IENT_ { W :: A :: [] }
| O I N { W :: I :: N :: [] }
| P { P :: [] }
@@ -137,7 +139,7 @@ letters
ending:
| X_ { S::EOL::[]}
| IENT_ { I::T::EOL::[]}
- | IE_ { I::EOL::[]}
+ | IE_ { I::EOL::[]}
| ENT_ { E::T::EOL::[]}
| ERF_ { E_AGRAVE::R::EOL::[]}
| EL_ { E_AGRAVE::L::EOL::[]}
diff --git a/src/lib/reader.ml b/src/lib/reader.ml
index b816d6d..6621730 100644
--- a/src/lib/reader.ml
+++ b/src/lib/reader.ml
@@ -55,4 +55,3 @@ let process
|> build_processor in
try loop content (Parser.Incremental.main lexbuf.lex_curr_p)
with Lexer.Error msg -> Error msg
-
diff --git a/src/lib/repr/tengwar.ml b/src/lib/repr/tengwar.ml
new file mode 100644
index 0000000..4d9ad5e
--- /dev/null
+++ b/src/lib/repr/tengwar.ml
@@ -0,0 +1,271 @@
+(** Glyph position for the diacritc *)
+type position =
+ | Pos1
+ | Pos2
+ | Pos3
+ | Pos4
+
+(** Consonant category *)
+type category =
+ | I
+ | II
+ | III
+
+type voyel =
+ { opened : bool
+ ; app : (position -> string) }
+
+type consonant =
+ { position : position
+ ; repr : string
+ ; primary : bool
+ ; category : category }
+
+
+type nasal = (t -> string)
+
+and t =
+ | Consonant of consonant
+ | Voyel of voyel
+ | Nasal of nasal
+
+let none = ""
+
+let a =
+ { opened = true
+ ; app = function
+ | Pos1 -> "#"
+ | Pos2 -> "E"
+ | Pos3 -> "D"
+ | Pos4 -> "C" }
+
+and a_nasal = Nasal
+ (fun f -> match f with
+ | Consonant c -> begin match c.primary, c.position, c.category with
+ | true, Pos1, _ -> "{#"
+ | true, _, _ -> "[E"
+ | false, _, I -> "5#"
+ | false, _, II -> "t#"
+ | false, _, III -> "g#"
+ end
+ | _ -> "`pC"
+
+ )
+
+let app_e = function
+ | Pos1 -> "$"
+ | Pos2 -> "R"
+ | Pos3 -> "F"
+ | Pos4 -> "V"
+
+and app_eu = function
+ | Pos1 -> "Ü"
+ | Pos2 -> "Ý"
+ | Pos3 -> "Þ"
+ | Pos4 -> "ß"
+
+let e_opened = { opened = true ; app = app_e }
+and e_closed = { opened = false ; app = app_e }
+and schwa = "°"
+
+and eu_opened = { opened = true ; app = app_eu }
+and eu_closed = { opened = false ; app = app_eu }
+
+and o =
+ { opened = true
+ ; app = function
+ | Pos1 -> "^"
+ | Pos2 -> "Y"
+ | Pos3 -> "H"
+ | Pos4 -> "N" }
+
+and o_nasal = Nasal
+ (fun f -> match f with
+ | Consonant c -> begin match c.primary, c.position, c.category with
+ | true, Pos1, _ -> "{^"
+ | true, _, _ -> "[Y"
+ | false, _, I -> "5^"
+ | false, _, II -> "t^"
+ | false, _, III -> "g^"
+ end
+ | _ -> "`pN"
+ )
+
+and i =
+ { opened = true
+ ; app = function
+ | Pos1 -> "%"
+ | Pos2 -> "T"
+ | Pos3 -> "G"
+ | Pos4 -> "B" }
+
+and i_nasal = Nasal
+ (fun f -> match f with
+ | Consonant c -> begin match c.primary, c.position, c.category with
+ | true, Pos1, _ -> "{$"
+ | true, _, _ -> "[T"
+ | false, _, I -> "5$"
+ | false, _, II -> "t$"
+ | false, _, III -> "g$"
+ end
+ | _ -> "`pV"
+ )
+
+and y =
+ { opened = true
+ ; app = function
+ | Pos1 -> "Ø"
+ | Pos2 -> "Ù"
+ | Pos3 -> "Ú"
+ | Pos4 -> "Û" }
+
+and y_nasal = Nasal
+ (fun f -> match f with
+ | Consonant c -> begin match c.primary, c.position, c.category with
+ | true, Pos1, _ -> "{Ø"
+ | true, _, _ -> "[Ù"
+ | false, _, I -> "5Ø"
+ | false, _, II -> "tØ"
+ | false, _, III -> "gØ"
+ end
+ | _ -> "`pÛ"
+
+ )
+
+and u =
+ { opened = true
+ ; app = function
+ | Pos1 -> "&"
+ | Pos2 -> "U"
+ | Pos3 -> "J"
+ | Pos4 -> "M" }
+
+and p = Consonant
+ { position = Pos2
+ ; category = II
+ ; primary = true
+ ; repr = "q" }
+and b = Consonant
+ { position = Pos1
+ ; category = II
+ ; primary = true
+ ; repr = "w" }
+
+and t = Consonant
+ { position = Pos2
+ ; category = I
+ ; primary = true
+ ; repr = "1" }
+and d = Consonant
+ { position = Pos1
+ ; category = I
+ ; primary = true
+ ; repr = "2" }
+
+and k = Consonant
+ { position = Pos3
+ ; category = III
+ ; primary = true
+ ; repr = "a" }
+and g = Consonant
+ { position = Pos1
+ ; category = III
+ ; primary = true
+ ; repr = "s" }
+
+and f = Consonant
+ { position = Pos3
+ ; category = II
+ ; primary = true
+ ; repr = "e" }
+
+and v = Consonant
+ { position = Pos1
+ ; category = II
+ ; primary = true
+ ; repr = "r" }
+
+and ch = Consonant
+ { position = Pos1
+ ; category = III
+ ; primary = true
+ ; repr = "d" }
+and j = Consonant
+ { position = Pos1
+ ; category = III
+ ; primary = true
+ ; repr = "f" }
+
+and s = Consonant
+ { position = Pos3
+ ; category = I
+ ; primary = true
+ ; repr = "3" }
+
+and z = Consonant
+ { position = Pos1
+ ; category = I
+ ; primary = true
+ ; repr = "4" }
+
+and m = Consonant
+ { position = Pos1
+ ; category = II
+ ; primary = true
+ ; repr = "t" }
+
+and n = Consonant
+ { position = Pos1
+ ; category = I
+ ; primary = true
+ ; repr = "5" }
+
+and gn = Consonant
+ { position = Pos1
+ ; category = III
+ ; primary = false
+ ; repr = "b" }
+
+and l = Consonant
+ { position = Pos1
+ ; category = II
+ ; primary = false
+ ; repr = "j" }
+
+and r = Consonant
+ { position = Pos2
+ ; category = I
+ ; primary = false
+ ; repr = "7" }
+
+and semi_voyel_w = Consonant
+ { position = Pos3
+ ; category = II
+ ; primary = false
+ ; repr = "." }
+
+and semi_voyel_y = Consonant
+ { position = Pos1
+ ; category = II
+ ; primary = false
+ ; repr = "l" }
+ (*
+
+let muted
+ : t -> t
+ = fun t ->
+ Printf.sprintf "(%s)" t
+
+let diphtongue
+ : t -> t -> t
+ = fun t1 t2 ->
+ Printf.sprintf "[%s%s]" t1 t2
+
+let fold
+ : t list -> string
+ = fun elems ->
+ let buff = Buffer.create 16 in
+ List.iter elems
+ ~f:(fun f -> Buffer.add_string buff f);
+ Buffer.contents buff
+ *)