block lambda revival

Brendan Eich brendan at
Tue May 24 12:29:00 PDT 2011

I've updated the grammar to fix the bugs Waldemar and Jon pointed out:

ElementList :                               // See 11.1.4
    Elisionopt InitialValue
    ElementList , Elisionopt InitialValue

PropertyAssignment :                        // See 11.1.5
    PropertyName : InitialValue

ArgumentList :                              // See 11.2
    ArgumentList , InitialValue

Initialiser :                               // See 12.2
    = InitialValue

InitialiserNoIn :                           // See 12.2
    = InitialValueNoIn

InitialValue :

Statement :
    LeftHandSideExpression = CallWithBlockArguments
    LeftHandSideExpression AssignmentOperator CallWithBlockArguments

PrimaryExpression :
    ( CallWithBlockArguments )

CallWithBlockArguments :
    MemberExpression [no LineTerminator here] BlockArguments

BlockArguments :
    BlockArguments [no LineTerminator here] BlockLambda
    BlockArguments [no LineTerminator here] ( Expression )

BlockLambda :
    { | BlockParameterListopt | StatementListopt }

BlockParameterList :
    BlockParameterList , BlockParameter

BlockParameter :
    Identifier BlockParameterInitialiseropt
    Pattern BlockParameterInitialiseropt

BlockParameterInitialiser :
    = BitwiseXorExpression

The idea is to restrict paren-free block-lambda-argument-bearing calls (we knew those were trouble if not confined!) to only certain contexts:

  * as an initial value for
    * a property in an initialiser,
    * an argument in a parenthesized call,
    * a parameter default value,
    * a variable declaration initialiser;
  * the entirety of the expression in an expression statement;
  * the right-hand side of an assignment operator following a left-hand-side expression, the assignment making a complete expression statement;
  * parenthesized as a primary expression.

So you can go paren-free in the obvious places. Anywhere hinky, like the condition of an if statement (see and thanks to Waldemar for pointing this out) you have to parenthesize.

This seems to check out without conflicts in Bison, although I tested only a reduced sub-grammar of ES5.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list