[wg-camlp4] My uses of syntax extension
Leo White
lpw25 at cam.ac.uk
Mon Jan 28 17:00:56 GMT 2013
On Jan 28 2013, Alain Frisch wrote:
>On 01/28/2013 05:44 PM, Fabrice Le Fessant wrote:
>> On 01/28/2013 05:26 PM, Leo White wrote:
>>>
>>>> In my ocaml-templates approach, the "html" parser would just receive a
>>>> string "<body attr=$x$> Hello, World <\body>", and call its parser,
>>>> that would have to understand anti-quotations, by returning a node
>>>> Pquotation("ocaml", "x") telling the typer that it should call the
>>>> ocaml parser on the string "x"...
>>>
>>> The problem with this method is that it does not support nested
>>> anti-quotations, or any other occurrence of the closing delimiter (the
>>> second "$") within the expression. You don't know whether "x" is the
>>> expression that needs to be parsed without asking the OCaml parser.
>>
>> Of course. For that, anyway, you need a "standard" of quotations and
>> anti-quotations, i.e. all parsers must obey the rule that
>> anti-quotations are between $...$ and quotations between <:XXX< ... >>.
>> Then, you don't need to know the syntax within the (anti-)quotations,
>> you can delegate parsing at the time the parsetree is needed.
>
>We need to be careful about lexical conventions: do we lex strings and
>comments as the standard lexer within quotations, for instance? Do we
>provide a mechanism to escape the closing delimiters?
I don't think that we should lex anything other than the closing delimeter,
that is, after all, the idea of a quotation.
Rather than providing an escape mechanism, it would be easier to provide
multiple options for the delimers. For instance we could allow <:foo ?<
(where ? is any character) to be matched by >?>, this makes it easy to
avoid clashes.
We could also allow <:foo ?{ ... }?>, <:foo ?( ... )?> etc.
More information about the wg-camlp4
mailing list