summaryrefslogtreecommitdiffabout
diff options
context:
space:
mode:
authorArmaël Guéneau <armael.gueneau@ens-lyon.org>2020-11-02 22:42:42 (CET)
committer Armaël Guéneau <armael.gueneau@ens-lyon.org>2020-11-02 22:42:42 (CET)
commit59b58e009eea6a487cf049e191d6b717e4045971 (patch)
tree4949675116e92adf485744eb38a0c139cff13650
parentd9240e053ae4c8c51df4031431f3065173be4b55 (diff)
downloaddict-59b58e009eea6a487cf049e191d6b717e4045971.tar.gz
dict-59b58e009eea6a487cf049e191d6b717e4045971.tar.bz2
Upgrade to dune and containers (batteries stopped being jsoo friendly?)
-rw-r--r--.merlin7
-rw-r--r--Makefile12
-rw-r--r--_tags1
-rw-r--r--dict.ml25
-rw-r--r--dune12
5 files changed, 29 insertions, 28 deletions
diff --git a/.merlin b/.merlin
deleted file mode 100644
index 4ed16c9..0000000
--- a/.merlin
+++ /dev/null
@@ -1,7 +0,0 @@
-B _build
-PKG batteries
-PKG js_of_ocaml-tyxml
-PKG js_of_ocaml-ppx
-PKG js_of_ocaml-lwt
-PKG react
-PKG lwt
diff --git a/Makefile b/Makefile
index 2e2df35..5195574 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,13 @@
-dict: dict_init.ml
- ocamlbuild -use-ocamlfind -plugin-tag "package(js_of_ocaml-ocamlbuild)" dict.js
+.PHONY: dict deploy clean
-dict_init.ml: init/*
- ocaml-crunch init -o dict_init.ml -m plain
+dict:
+ dune build
deploy: dict
mkdir -p public
- cp _build/dict.js public/
+ cp _build/default/dict.bc.js public/dict.js
cp -r css public/
cp index.html public/
clean:
- ocamlbuild -clean
- rm -f dict_init.ml
+ dune clean
diff --git a/_tags b/_tags
deleted file mode 100644
index dd8b9a8..0000000
--- a/_tags
+++ /dev/null
@@ -1 +0,0 @@
-true: package(batteries), package(js_of_ocaml,js_of_ocaml-ppx,js_of_ocaml-tyxml,js_of_ocaml-lwt), package(lwt)
diff --git a/dict.ml b/dict.ml
index a5ef097..95c204b 100644
--- a/dict.ml
+++ b/dict.ml
@@ -1,4 +1,4 @@
-open Batteries
+open Containers
open Js_of_ocaml
open Js_of_ocaml_tyxml
open Js_of_ocaml_lwt
@@ -9,11 +9,11 @@ let langs = ["Toki-pona"; "English"]
let dict_name = "toki.txt"
let parse_dict s =
- String.split_on_string ~by:"\n" s
+ String.split ~by:"\n" s
|> List.filter (fun l ->
try Scanf.sscanf l " #" false with
End_of_file | Scanf.Scan_failure _ -> true)
- |> List.map (String.split_on_string ~by:"::" %> List.map String.strip)
+ |> List.map Fun.(String.split ~by:"::" %> List.map String.trim)
|> List.filter (fun l -> not (List.for_all String.is_empty l))
(** Reactive values *)
@@ -36,7 +36,7 @@ let results :
let open Tyxml_js.Html5 in
React.S.l2 (fun dict search ->
let len_search = String.length search in
- let search = String.lowercase search in
+ let search = String.lowercase_ascii search in
let len = String.length search in
let res_compare x y =
@@ -47,22 +47,21 @@ let results :
let matching = ref false in
let l' =
List.map (fun s ->
- String.Exceptionless.find (String.lowercase s) search
- |> Option.map_default (fun i ->
+ let i = String.find (String.lowercase_ascii s) ~sub:search in
+ if i = -1 then ([txt s], None)
+ else begin
matching := true;
let s' =
- [txt (String.slice ~first:0 ~last:i s);
- b [txt (String.slice ~first:i ~last:(i + len) s)];
- txt (String.slice ~first:(i + len) s)] in
+ [txt (String.sub s 0 i);
+ b [txt (String.sub s i len)];
+ txt (String.sub s (i + len) (String.length s - i - len))] in
(s', Some (i, String.length s))
- ) ([txt s], None)
+ end
) l in
if !matching then
Some (
List.split l'
- |> Tuple2.map2 (List.filter_map identity
- %> List.stable_sort res_compare
- %> List.hd)
+ |> Pair.map2 Fun.(List.filter_map id %> List.stable_sort res_compare %> List.hd)
)
else None
) dict
diff --git a/dune b/dune
new file mode 100644
index 0000000..ae1c471
--- /dev/null
+++ b/dune
@@ -0,0 +1,12 @@
+(executable
+ (name dict)
+ (modes js)
+ (libraries containers js_of_ocaml-lwt js_of_ocaml-tyxml)
+ (preprocess (pps js_of_ocaml-ppx))
+ (link_flags (:standard -no-check-prims))
+)
+
+(rule
+ (targets dict_init.ml)
+ (deps (source_tree init))
+ (action (run ocaml-crunch init -o dict_init.ml -m plain)))