<br><br><div class="gmail_quote">On Wed, Jan 30, 2013 at 4:12 AM, Alain Frisch <span dir="ltr"><<a href="mailto:alain@frisch.fr" target="_blank">alain@frisch.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 01/30/2013 03:34 AM, Hongbo Zhang wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote></div>
This looks very bad to me:<br>
<br>
1. You loose all support from your editor (indentation, coloring, parentheses matching). Am I the only one who finds this really problematic? With quotations, my emacs looks like notepad... Indentation and coloring do find typos on the fly; automatic indentation makes it easy to copy/paste code from one context to another one.<br>
</blockquote><div>Weird, my emacs works pretty well for me, I choose "{| |}" since it's more friendly to emacs. <b>On the contrary, quotation is great for IDE integration, since when you type {:lex||}, the IDE knows the context already</b></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
2. Quotation "with OCaml code in them" does not combine well with other AST rewriters. If you have a -ppx filter implementing, say, macro expansion (in patterns and expressions), would you apply it before or after the one expanding the {:lex| ... |} quotations? Probably both. (And won't be able to benefit of macro on patterns for the "regexps".)<br>
</blockquote><div>Ast Rewriter is <b>bad </b>for arbitrary code generation, its neat case is something like bisect. And Ast Rewriter is not composable at all, suppose you have two AST Rewriters A,B ,there are no guarantee that A.B == B.A, it just gives you an illusion that it works, probably it silently fails.</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
3. How do you implement the expander? Somehow, you need to parse the content of the quotation (stored as a string in the AST), which involves non trivial stuff, like a parser being able to parse OCaml code mixed with something else. Personally, I don't know how to implement the quotation expander with the parsing technologies I'm familiar with.<br>
<br></blockquote><div>when you design your DSL, the left part is pretty easy to parse, when you see the delimiter "->", invoking an existing parser. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
For me quotations (in position of expression) are useful only for one thing: escape from the lexical conventions of OCaml string literals. Otherwise, strings are just fine. There are very few cases where with actually matters. A decent example might be something like Pa_tyxml, allowing to write XML code in XML syntax within OCaml sources. But even there, I'm not absolutely sure that quotations are the best solution: would it really be so bad to use normal OCaml strings (with an attribute):<br>
<br>
(@xml)"<div>xyz</div>"<br>
<br>
or OCaml syntax interpreted specially:<br>
<br>
(@xml)(div "xyz")<br>
<br>
instead of the current:<br>
<br>
<:html5< <div>xyz</div> >><br>
<br>
<br></blockquote><div>They all work great for me, but since they all work, why not only introduce one,<b> I am happy to see the less ad-hoc rules.</b></div><div>I did not mention that in Fan, we already support {:|? ?|} , like Perl you can supply an extra matching char to handle more complex cases.</div>
<div><br></div><div>Anyway, I think it would great to get the Abstract Syntax right before the details on concrete syntax.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But maybe for some cases (embedding a language with a lot of double quoted and backslashes), escaping from the lexical conventions of OCaml string literals might really be useful. This could be actually be the case for standard string literals, with no special syntactic processing. So why not simply address this need by allowing an alternative syntax for string literals, where no special character is interpreted? The opening delimiter would define the closing delimiter. For instance:<br>
<br>
{xxx{ ..... }xxx}<br>
<br>
(here I've assumed that { } are hard-coded, but xxx could be replaced say, by any sequence of identifier/digit/operator characters). In the AST, this could be represented as a normal string literal (or maybe we should keep the "xxx" annotation, to avoid having to put an extra attribute in front of the literal).<br>
<br>
<br>
I've yet to be convinced that quotations really have other interesting uses than escaping from lexical conventions of OCaml string literals...<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
Alain<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>-- Regards, Hongbo