zapashcanon 1 month ago
parent
commit
4149ae70e5
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 2
      src/dune
  2. 6
      src/menhir_parser.mly
  3. 14
      src/wutf8.ml

2
src/dune

@ -19,7 +19,7 @@
types
wutf8)
(private_modules convert float32 float64 lexer menhir_parser stack wutf8)
(libraries integers menhirLib ocaml_intrinsics ppxlib sedlex)
(libraries integers menhirLib ocaml_intrinsics ppxlib sedlex uutf)
(preprocess
(pps sedlex.ppx))
(instrumentation

6
src/menhir_parser.mly

@ -34,6 +34,12 @@ open Types
(* Helpers *)
let utf8_name ==
| name = NAME; {
Wutf8.check_utf8 name;
name
}
let par(X) ==
| LPAR; ~ = X; RPAR; <>

14
src/wutf8.ml

@ -51,3 +51,17 @@ and decode' = function
(((b1 land 0x07) lsl 18) + (con b2 lsl 12) + (con b3 lsl 6) + con b4)
:: decode' bs
| _ -> raise Utf8
let check_utf8 s =
let open Uutf in
let decoder = decoder ~encoding:`UTF_8 (`String s) in
let rec loop () =
match decode decoder with
| `Malformed _s ->
Debug.debug Format.err_formatter "GOT: `%S`" s;
failwith "malformed UTF-8 encoding"
| `Await -> assert false
| `End -> ()
| `Uchar _ -> loop ()
in
loop ()

Loading…
Cancel
Save