Nested Quasis

Waldemar Horwat waldemar at google.com
Fri Feb 3 12:58:00 PST 2012


On 02/02/2012 06:27 PM, Waldemar Horwat wrote:
> On 02/02/2012 04:15 PM, Mark S. Miller wrote:
>>
>>
>> On Thu, Feb 2, 2012 at 2:00 PM, Waldemar Horwat <waldemar at google.com <mailto:waldemar at google.com>> wrote:
>>
>> OK. This introduces yet another lexing context, in which all productions *except* QuasiMiddle and QuasiEnd are disallowed, and white space and comment handling is funny. That works if the expressions must be one of the two forms:
>>
>> $id
>> ${expr}
>>
>> Is that the exhaustive list, or are we looking at other forms such as $$, $id.id <http://id.id>, $id[expr], etc.?
>>
>>
>>
>> I'll let Mike speak for the details of what he really wants to propose. But here are the answers from E:
>>
>> escapes with the quasi literal text are taken care of by the QuasiChar production, much like the existing definition of DoubleStringCharacter:
>>
>> QuasiChar ::
>> SourceCharacter but not one of $ or `
>> $ $
>> $ `
>> $ \ EscapeSequence
>>
>> So that `$$` === "$", `$`` === "`", and `$\n` === "\n", respectively.
>>
>> Regarding `...$id.id...` and `...$id[expr]...`, only the first id in each case in in the quasiHole. All the text afterwards is part of the QuasiClose.
>
> Good. I'll have to think about this a bit more, but there's a chance you converted me.

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)

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

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

     Waldemar


More information about the es-discuss mailing list