summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2023-04-24 17:16:14 +0200
committerSébastien Dailly <sebastien@dailly.me>2023-04-24 17:16:14 +0200
commitcdbf2fd0587131c1b9427bbf040e3f3f7405fa72 (patch)
tree37806e1c029a8cc792c747b1a8b8650d5268187f /src
parent3b90a643b3820e97bf1dab28ce41dacc4ca2831f (diff)
Review the main script
Diffstat (limited to 'src')
-rw-r--r--src/js/tengwar.ml109
-rw-r--r--src/lib/repr/rousseau.ml (renamed from src/lib/repr/tengwar.ml)0
2 files changed, 52 insertions, 57 deletions
diff --git a/src/js/tengwar.ml b/src/js/tengwar.ml
index 31eb1ed..4c02eeb 100644
--- a/src/js/tengwar.ml
+++ b/src/js/tengwar.ml
@@ -13,7 +13,7 @@ let (let=?) : 'a option -> ('a -> unit) -> unit
type state =
{ text : (Sounds.t list, string) result
- ; font : [`Telcontar | `Annatar ]}
+ ; font : [`Telcontar | `Annatar ] }
module App = Application.Make(struct type t = state end)
@@ -49,62 +49,57 @@ let init =
}
let main id phon tengwar font =
- match (Jv.is_none id) with
- | true -> Console.(error [str "No element with id '%s' found"; id])
- | false ->
-
- let=? source = get_element_by_id id in
- let=? phon = get_element_by_id phon in
- let=? tengwar = get_element_by_id tengwar in
- let=? font = get_element_by_id font in
-
- let text_event =
- Evr.on_el
- Ev.input
- (fun _ ->
- App.E ( El.prop El.Prop.value source
- , (module SetText: App.Event with type t = SetText.t ))
- ) source in
-
- let font_event =
- Evr.on_el
- Ev.input
- (fun _ ->
- let value = El.prop El.Prop.value font in
- let str = Jstr.to_string value in
- App.E ( (str, tengwar)
- , (module SetFont: App.Event with type t = SetFont.t ))
- ) font in
-
- let ev = App.run
- init
- (E.select
- [ text_event
- ; font_event ]
- ) in
-
- let log state =
- let transcription = state.text in
- let res1 = Result.map
- (fun t-> Sounds.repr (module Repr.Default) t)
- transcription in
- let () = match res1 with
- | Ok response ->
- El.set_prop El.Prop.value (Jstr.of_string response) phon
- | Error _err -> () in
- let res2 = Result.map
- (fun t->
- match state.font with
- | `Annatar -> Sounds.repr (module Repr.Anatar) t
- | `Telcontar -> Sounds.repr (module Repr.Telcontar) t)
- transcription in
- let () = match res2 with
- | Ok response ->
- El.set_prop El.Prop.value (Jstr.of_string response) tengwar
- | Error _err -> () in
- ()
- in
- Logr.hold (S.log ev log)
+ let=? source = get_element_by_id id in
+ let=? phon = get_element_by_id phon in
+ let=? tengwar = get_element_by_id tengwar in
+ let=? font = get_element_by_id font in
+
+ let text_event =
+ Evr.on_el
+ Ev.input
+ (fun _ ->
+ App.E ( El.prop El.Prop.value source
+ , (module SetText: App.Event with type t = SetText.t )))
+ source in
+
+ let font_event =
+ Evr.on_el
+ Ev.input
+ (fun _ ->
+ let value = El.prop El.Prop.value font in
+ let str = Jstr.to_string value in
+ App.E ( (str, tengwar)
+ , (module SetFont: App.Event with type t = SetFont.t )))
+ font in
+
+ let ev = App.run
+ init
+ (E.select
+ [ text_event
+ ; font_event ]) in
+
+ let log state =
+ let transcription = state.text in
+ let res1 = Result.map
+ (fun t-> Sounds.repr (module Repr.Ipa) t)
+ transcription in
+ let () = match res1 with
+ | Ok response ->
+ El.set_prop El.Prop.value (Jstr.of_string response) phon
+ | Error _err -> () in
+ let res2 = Result.map
+ (fun t->
+ match state.font with
+ | `Annatar -> Sounds.repr (module Repr.Anatar) t
+ | `Telcontar -> Sounds.repr (module Repr.Telcontar) t)
+ transcription in
+ let () = match res2 with
+ | Ok response ->
+ El.set_prop El.Prop.value (Jstr.of_string response) tengwar
+ | Error _err -> () in
+ ()
+ in
+ Logr.hold (S.log ev log)
let () =
diff --git a/src/lib/repr/tengwar.ml b/src/lib/repr/rousseau.ml
index f9fde05..f9fde05 100644
--- a/src/lib/repr/tengwar.ml
+++ b/src/lib/repr/rousseau.ml