Nested Quasis

Mark S. Miller erights at google.com
Fri Feb 3 20:07:41 PST 2012


On Fri, Feb 3, 2012 at 12:58 PM, Waldemar Horwat <waldemar at google.com>wrote:

> On 02/02/2012 06:27 PM, Waldemar Horwat wrote:
>
[...]

> Note that this is more complex than just having the parser switch modes
> for the treatment of / as division vs. regexp.  Here comments and white
> space are also affected, which can in turn the structure of the lexer
> upside down.  The kinds of cases I'm thinking of are:
>
> `abc$/*comment*/identifier//
> `
> (here we have a /**/ comment and a // comment)
>

There is no valid quasiHole above, so the whole thing matches a QuasiOnly.
The QuasiOnly includes all characters between the backticks. Nothing is
taken to be a comment, just like it wouldn't be if it appeared within a
string.



> `abc$/**/{/**//re//**/}/**/**def`
> vs:
> `abc$/**/{/**//re//**/}/*def`
> (in the former all four "/**/"'s are comments.  Not sure what the latter
> would do.)
>

Same thing. There is no valid quasiHole here.


>
> `abc$id def`
> `abc$ id def`
> (the lexer removes spaces before all tokens, so the quasi would not
> contain a space before the "def")


The first has a valid quasiHole, and so would parse as QuasiOpen("abc"),
Identifier("id"), QuasiClose(" def"). (Note space captured in the
QuasiClose text.)

The second has no valid quasiHole, and so the whole thing would again parse
as a QuasiOnly.

I think of, for example, QuasiMiddle as being much like DoubleStringChars.
Once you're lexing that, all spaces are significant. As a lexing context, I
don't really see how quasis are weirder than strings.

However, from your example, I think I see what you're getting at. I forgot
to state that a quasiExpr is only started if a QuasiOpen or QuasiMiddle
ends with an (unescaped by previous $\ ) $ followed *immediately*, with no
intervening characters, by either an Identifier or a "{". I don't see this
as weirder than having a string terminate by (\ ") but not by (\"). The "
is only processed specially if it comes immediately after an (unescaped by
previous \ ) \ .

Similarly, you go back into quasi context *immediately* following the
identifier or matching } respectively, i.e., exactly when the quasiHole
production is over.

-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120203/d15ddba9/attachment.html>


More information about the es-discuss mailing list