Thunked Substitution Body

This defines the substitution body of a quasi using the PrimaryExpression syntactic production and thunks the resulting expression so that quasi handlers can conditionally & multiple evaluate substitution bodies. Determining where a substitution ends requires, in the general case, the ability to parse an EcmaScript expression.

//SusbstitutionBody// ::

  • PrimaryExpression

//SubstitutionModifier// ::

  • ε

SVE

Production Result
QuasiLiteral :: QuasiTag`LiteralPortion QuasiLiteralTail SVE(QuasiLiteralTail)
QuasiLiteralTail :: Substitution LiteralPortion QuasiLiteralTail array-concat(single-element-array(SVE(Substitution)), SVE(QuasiLiteralTail))
QuasiLiteralTail :: ` an empty array
Substitution :: $Identifier thunk(PrimaryExpression : Identifier)
Substitution :: ${SubstitutionModifier SubstitutionBody} SVE(SubstitutionBody)
SubstitutionBody :: PrimaryExpression thunk(PrimaryExpression)

The thunk operator takes an Expression production and returns a (CallExpression, (MemberExpression, (FunctionExpression, (an empty parameter list, (FunctionBody, (ReturnStatement, (the input))))), the IdentifierName bind)), ThisExpression)). So thunk given 1 + 1 produces function () { return 1 + 1 }.bind(this) or using the abbreviated syntax #{ 1 + 1 }.

The SVE is an expression that evaluates the specified expression in the scope in which the quasi appears. The SVE of the quasi literal is the array of the SVE for each substitution body.

E.g. the SVE of quasitag`literalPortion0 $x literalPortion1 ${y + z} literalPortion2` is [#{ x }, #{ y + z }].

It is an error for arguments to be free in the SVE.

 
strawman/quasis-substitutions-thunk.txt · Last modified: 2011/03/28 22:06 by mikesamuel
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki