Re: js_of_ocaml and ocamllex
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
Le 21/11/2015 20:02, Sébastien Dailly [email protected] [ocaml_beginners] a écrit : > > > Hello, > > I'm looking for a documentation for js_of_ocaml > > - Reading a local file with the File api > - Send the data to ocamllex/menhir > > is there some examples available ? > Hello, I'm trying to experiment Lexer and refill function but does not understand how it works : I've used the example provided by the document : > { > type token = EOL | INT of int | PLUS > > module Make (M : sig > type 'a t > val return: 'a -> 'a t > val bind: 'a t -> ('a -> 'b t) -> 'b t > val fail : exn -> 'a t > > (* Set up lexbuf *) > val on_refill : Lexing.lexbuf -> unit t > end) > = struct > > let refill_handler k lexbuf arg = > M.bind (M.on_refill lexbuf) (fun () -> k lexbuf arg) > > } > > refill {refill_handler} > > rule token = parse > | [' ' '\t'] > { token lexbuf } > | '\n' > { M.return EOL } > | ['0'-'9']+ as i > { M.return (INT (int_of_string i)) } > | '+' > { M.return PLUS } > | _ > { M.fail (Failure "unexpected character") } > { > end > } with a simple example : main.ml : > > module L = Lexer.Make(struct > include Lwt > > let on_refill lexer = > Lwt.return_unit > > end) But this does not compile, and I don't understand this error message : $ ocamlbuild -pkgs lwt main.native File "lexer.ml", line 152, characters 9-55: Error: This expression has type token M.t but an expression was expected of type 'a -> 'b M.t What did I did wrong ? It seems that the errors comes from the generated lexer. Thanks for your help ! -- Sébastien