Implicitly escaped $ (or not) in quasis?

Mark S. Miller erights at google.com
Tue Jun 26 10:45:10 PDT 2012


Hi Allen, I agree that the current implicit literal semantics is
confusing, and that these are the two sensible alternatives. In E I
chose alternative #1 with a somewhat different escaping syntax.
However, now that you point it out, I see the advantages of #2. I
think I now prefer #2 but can live with either.

Btw, as long as we're discussing this, let's re-raise what I consider
the more important syntactic issue: In the curly form, we should allow
any valid JS expression between the curlies. Last time it seemed we
had agreement on everything except how to specify grammar. From my
experiments with trying quasis, I think this is a crucial usability
issue


On Tue, Jun 26, 2012 at 10:19 AM, Allen Wirfs-Brock
<allen at wirfs-brock.com> wrote:
> I'm working on incorporating quasis into the ES6 draft and there is an issue
> I want to discuss:
>
> In the wiki proposal[1]  $  is used as the prefix for substitutions that may
> be of two forms:
>    `xyz$foo 1234`      //$foo substitues the value of the variable foo
>    `xyz${foo} 1234`    ${expr} generally substitues the result of evaluating
> expr, so ${foo} substitutes the value of foo
>
> Both of the above examples will produce the same result.
>
> The wiki grammar has this production for dealing with $:
>
>    LiteralCharacter :: $ [lookahead ∉ {, IdentifierStart ]
>
> In other words, a $ is a literal part of the quasi text if it that is not
> immediately followed by a { or an IdentifierStart character.
>
> IdentifierStart includes lots of different things including $  itself and
> many non-roman characters.
>
> For example, under these rules can you (our human readers) identify which of
> the following is intended to be literal text and which contains a variable
> substitution:
>    `I say: $ᐭ`     // ᐭ is U+142B
>    `I say: $⏅`     // ⏅ is U+23C5
>
> Or, perhaps more routinely:
>
>    `$1234`   // this is all literal text
>    `$$1234`  //this is a substitution for the variable $1234
>
> I can think of two alternative way to eliminate these potentially confusing
> situations:
>
> 1)  Eliminate the literal use of $ entirely.  The valid uses then are either
> ${expr} or $IndentifierName.  Any other occurrence of $ within the literal
> part of a Quasi would have to be escaped.  eg:
>      `$99.95`   //syntax error
>      `\$99.95`   // same as: "$99.95"
>
> 2) Eliminate the $IdentifierName form entirely.  Use ${IdentifierName}
> instead.  Any occurrence of $ not followed by { is a literal $.   eg:
>     `$99.95`   // same as: "$99.95"
>     `$$1234`  //same as "$$1234"
>     `$foo`        //same as "$foo"
>     `${foo}`     //substitutes the value of the variable foo
>     `${`            //syntax error
>
> Of these two alternatives,  I favor the second over the first and over the
> current wiki specification.  I think alternative 2 makes the overall
>  language simpler for users to learn and to read as it has only one clearly
> delimitated form of substitution.  It eliminates the need to learn and
> recognize two different forms and the possibility of confusion when non
> ascii characters are being used.  It also allows $ to be used literally,
> which I suspect is quite common in some locales. This alternative also is
> simpler to specify and requires fewer parsing irregularities.
>
> There are a couple down sides I see for alternative 2, relative to
> alternative one.  It means that the most common form for substitution
> expression ( a single identifier) requires two more characters.  It also may
> cause some confusion for people who are used to languages that support
> $identifier substitution syntax in strings.   Personally, I think the
> advantages of this approach out weight these disadvantages. Other my
> disagree.
>
> So, I propose that we go with alternative 2.  Thoughts?
>
> Allen
>
> [1] http://wiki.ecmascript.org/doku.php?id=harmony:quasis#literalportion
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
    Cheers,
    --MarkM


More information about the es-discuss mailing list