ocamlcamlp4js-of-ocaml

js_of_ocaml Camlp4 Parse error in type definition


I'm trying to build this program using js_of_ocaml. According to this answer, I've got the following line in my makefile

OCAMLC      = ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -g -dtypes

However, when I try to build, I get the following error:

ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -g -dtypes   -c types.ml
> File "types.ml", line 472, characters 11-12:
> Parse error: [type_longident] expected after ")" (in [type_ident_and_parameters])
> File "types.ml", line 1:

The offending line of the file is this:

type ('t,'v) parser = ('t list -> 'v -> unit) -> 't list -> unit

I'm still pretty new to OCaml, so I'm not totally sure what's going on. What does the -syntax camlp4o do? What kinds of things in the source might I need to change to be compatible with js_of_ocaml?


Solution

  • camlp4o provides the same syntax as the vanilla OCaml syntax, but with slight incompatibility: parser is a special keyword in camlp4o. This is why parser is rejected if you use camlp4o syntax.

    You can workaround this problem by renaming parser, or using PPX syntax extension of js_of_ocaml instead of CamlP4. Please check https://ocsigen.org/js_of_ocaml/api/Ppx_js for details of this newer syntax helper for js_of_ocaml.