[wg-camlp4] On domain-specific foreign syntaxes

Alain Frisch alain.frisch at lexifi.com
Fri Feb 1 07:38:18 GMT 2013


On 1/31/2013 7:04 PM, Leo White wrote:
>>   {:lid x|..|x}
> I would be perfectly happy with "<" + ">" instead of |, or anything else
> which doesn't interfere with the {:lid expr } syntax. As long as its a
> single-character and it is not "{" + "}".

In OCaml, delimiters are built from those symbols:  {...}, (...), [...], 
sometimes combined with other characters as in [|...|].  It is probably 
a good idea to keep using one of these kinds of parentheses as outer 
delimiters, both to make it clear in the syntax that they are indeed 
matched delimiters, and also to benefit from basic editor support (for 
matching parentheses), when quotations are not recognized as such.  I 
don't have a concrete proposal for a syntax, though.

Something else: I suggest that the "marker" (lid in your examples) for 
extension node (whether they are combined with quotations or not) could 
rather be a general expression than just an identifier (maybe with a 
lighter syntax for the simple identifier case).  (In the Parsetree, we 
would have "Pexp_extension of expression * expression" instead of 
"Pexp_extension string * expression".)  This is to support passing 
arguments to the "expander".  Of course, those arguments could be 
encoded in the "content", but I believe it makes sense to distinguish 
those two concepts.  In particular, if you use the combined extension + 
quotation form, you probably want parsed arguments even with unparsed 
content:

  {:(html ~strict ~antiquot:'$') |<div class=$x/>|}


> Considering a parser is probably more effort to write than an AST
> transformer, I don't think you need to worry too much.

(Requiring more effort is unfortunately often valued as a good thing!)


Alain


More information about the wg-camlp4 mailing list