[wg-camlp4] Meta Programming from the view of the implementaion
Alain Frisch
alain at frisch.fr
Wed Jan 30 10:46:37 GMT 2013
On 01/30/2013 10:31 AM, Leo White wrote:
> I don't really see the difference between:
>
>> {xxx{ ..... }xxx}
>
> and
>
>> <:html5< <div>xyz</div> >>
The differences are:
- The closing delimiter is defined by the opening one, so you don't
need any escaping convention. (Imagine you want to write HTML code
containing ">>".)
- This is usable for regular strings, independently from any -ppx
manipulation. In my experience, I faced quite often situations where it
would have been convenient to write string literals but without OCaml's
lexical convention.
For instance, imagine that instead of relying on OCaml patterns for
writing Sedlex's regular expressions, I wanted to use a more compact
notation. I could simply use strings:
(@sedlex) match lexbuf with
| "xml_letter+" -> ...
| ...
And I would probably arrange to reduce the need for using the double
quote character, allowing to write string literals with single quotes:
(@sedlex) match lexbuf with
| "'with'" -> ...
| ...
But I could as well prefer to allow double quotes, using the alternative
syntax for string literals:
(@sedlex) match lexbuf with
| {{ xml_letter+ }} -> ...
| {{ "with" }} -> ...
| ...
if "xxx" is allowed to be empty in {xxx{...}xxx}. There is no quotation
to name here, this is implied by the surrounding attribute @sedlex
(which could be made non-ignorable).
As a side note, whatever syntax we choose for quotations / non-parsed
strings, we should avoid the one currently used by Camlp4, because for
some time, people will continue to use both Camlp4 and -ppx rewriters.
Alain
More information about the wg-camlp4
mailing list