diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-09-07 22:33:45 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2021-09-07 22:33:45 +0200 |
commit | 80b77d19cee0f3df4457005eead1128b90754a48 (patch) | |
tree | 52a36a9f68a2ba06631c1a1a48576afb9c617cc8 /src/lib/repr | |
parent | 96a225fb5fa24a71e1b76e0369126b3bcfab5f81 (diff) |
Added tests
Diffstat (limited to 'src/lib/repr')
-rw-r--r-- | src/lib/repr/tengwar.ml | 271 |
1 files changed, 271 insertions, 0 deletions
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 + *) |