Reputation: 1418
I am using camlp5 with the MLast
module. I would like to know the syntax for antiquotations of nesting depth greater than 1. I'll explain with a mock example. Suppose I have
let f1 e = <:expr< 3 * $e$ >>
let f2 e = <:expr< $e$ + 1 >>
let f3 e = <:expr< $e$ / 2 >>
let f123 e = f3 (f2 (f1 e))
How can I define f123
in one go? For only two parts I could do
let f12 e = <:expr< $<:expr< 3 * \$e\$ >>$ + 1 >>
Note the mandatory backslashes in the inner antiquotation. But for three parts? Neither of the following works:
let f123 e = <:expr< $<:expr< \$<:expr< 3* \$e\$ >>\$ + 1 >>$ / 2 >>
let f123 e = <:expr< $<:expr< \$<:expr< 3* \\$e\\$ >>\$ + 1 >>$ / 2 >>
let f123 e = <:expr< $<:expr< \$<:expr< 3* \\\$e\\\$ >>\$ + 1 >>$ / 2 >>
The respective error messages are:
Uncaught exception: Pcaml.Qerror ("expr", 1, _)
Uncaught exception: Pcaml.Qerror ("expr", 1, _)
Parse error: end of input expected after [expr] (in [expr_eoi])
I couldn't find anything in the docs.
(P.S. Of course I know that in this specific example I could omit the inner antiquotation/quotation pairs. That is beside the point; it is due to the oversimplification inherent in the mock example.)
Upvotes: 2
Views: 75