Nested Quasis
John Tamplin
jat at google.com
Thu Feb 2 12:21:14 PST 2012
I think this could take the same approach as Dart in dealing with embedded
expressions -
http://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/compiler/java/com/google/dart/compiler/parser/DartScanner.java?r=1805#898
Basically, the scanner returns token sequences like:
"foo" => STRING(foo)
"foo $bar baz" => STRING_SEGMENT(foo ) STRING_EMBED_EXPR_START
IDENTIFIER(bar) STRING_EMBED_EXPR_END
which the parser then handles normally, with rules like:
string-expression : STRING | string-interpolation ;
string-interpolation : ( STRING_SEGMENT? embedded-exp? )*
STRING_LAST_SEGMENT ; // a simplification
embedded-exp : STRING_EMBED_EXP_START expression STRING_EMBED_EXP_END ;
I don't know if this would cause ambiguities in the JS grammar, or if it
would have other issues applying it to quasis in JS, but it keeps a clean
separation between the scanner and parser (it does require some additional
state in the scanner, since these can be nested).
--
John A. Tamplin
Software Engineer (GWT), Google
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120202/b6056319/attachment.html>
More information about the es-discuss
mailing list