2

I am having an issue with using the deriving-ocsigen syntax extension in my camlp4 parser. My parser is called pa_debug.ml

Here's the tags file:

<pa_debug.ml>: pp(camlp4orf.opt), package(deriving-ocsigen.syntax), syntax(camlp4o)

When compiled with

ocamlbuild -libs dynlink,camlp4lib,deriving -cflags -I,+camlp4,-dtypes -lflags -I,+camlp4,-dtypes -use-ocamlfind pa_debug.cmo

I get the following error:

Warning: -pp overrides the effect of -syntax partly
File "pa_debug.ml", line 103, characters 66-67:
While expanding quotation "expr" in a position of "expr":
Parse error: [expr] expected after [infix operator (level 0) (comparison operators, and some others)] (in [expr])

The error occurs in the second line of this snippet of code:

...
let fun_id = get_fun_id bi in
let app = <:expr< Debug.ho_1 $str:fun_id$ (Show.show<int>) (Show.show<int>) >> in
let debug_fun_body = mk_appln _loc app new_patts in
...

In the code, I am typing to use the deriving's syntax in a quotation. But it seems that the preprocessor does not understand the presence of "<" and ">" comparison operators in the quotation. If I use the Show.show<int> syntax in another file without quotations, it compiles without errors.

I've seen a solution to fix the -pp overrides the effect of -syntax problem but I don't understand it. Can someone please explain it to me or suggest some other way to fix it?

Jason Yeo
  • 3,602
  • 3
  • 30
  • 38
  • 2
    It would be easier to help if we had access to the `pa_debug.ml` file, to try to see which compilation lines actually work. What I can say at a first look is that your use of `ocamlbuild` is unusual: it's supposed to be a high-level compilation manager, and your use of `-cflags -I...` looks like you're trying *not* to use `ocamlbuild`. I suspect it would work better if you either moved to a dumber tool with these low-level options (eg. `ocamlfind`), or used the tagging capacity of `ocamlbuild` in a more natural way. – gasche May 14 '13 at 08:28
  • @gasche I'm not sure how ocamlbuild works. Are you saying that I should remove the entire `-cflags...` option? – Jason Yeo May 15 '13 at 17:15
  • 1
    I think there are better ways to do what your `-clfags` do; see [this blog post](http://gallium.inria.fr/blog/quick-tip-the-ocamlbuild-documentation-option/) for how to find out about `ocamlbuild` tags to use instead. I'm not saying you should blindly remove them, though. – gasche May 15 '13 at 17:53

1 Answers1

0

Now that you posted your code snippet, I believe the problem is with your use of Camlp4 extensions inside quotations. I would need to check whether that's allowed in the general case (there is a question of whether the quotation parser uses the predefined parser, or is also extended with the previous extensions passed to the compiler), but also of whether the particular extension you're using works with the revised syntax, which you use through your invocation of camlp4orf (or means that the ambient code is in original syntax, while the in-quotation code is in revised syntax, which is sometimes preferred in quotations because it is less ambiguous -- f means "full", the usual extensions (stream parsers, etc.) are activated).

If "deriving" wasn't thought to be used in revised syntax, then revised quotations may not work at all. In any case, that is probably a problem specific to Camlp4, rather than something ocamlbuild-related.

gasche
  • 31,259
  • 3
  • 78
  • 100
  • I don't understand your last sentence. If deriving is in the revised syntax, does that mean that I can use it in the quotations? – Jason Yeo May 20 '13 at 19:21
  • Actually I tried to use the deriving's `Show.show` syntax outside of quotations and it doesn't work. Does this have to do with the `-pp overrides the effect of -syntax partly` warning? – Jason Yeo May 20 '13 at 20:24