@@ -846,12 +846,52 @@ class Parser {
846
846
* | identifier
847
847
*/
848
848
Expression parseAssignableExpression (bool primaryAllowed) {
849
- if (_matchesKeyword (Keyword .SUPER )) {
850
- return parseAssignableSelector (
851
- astFactory.superExpression (getAndAdvance ()), false ,
852
- allowConditional: false );
849
+ //
850
+ // A primary expression can start with an identifier. We resolve the
851
+ // ambiguity by determining whether the primary consists of anything other
852
+ // than an identifier and/or is followed by an assignableSelector.
853
+ //
854
+ Expression expression = parsePrimaryExpression ();
855
+ bool isOptional =
856
+ primaryAllowed || _isValidAssignableExpression (expression);
857
+ while (true ) {
858
+ while (_isLikelyArgumentList ()) {
859
+ TypeArgumentList typeArguments = _parseOptionalTypeArguments ();
860
+ ArgumentList argumentList = parseArgumentList ();
861
+ Expression currentExpression = expression;
862
+ if (currentExpression is SimpleIdentifier ) {
863
+ expression = astFactory.methodInvocation (
864
+ null , null , currentExpression, typeArguments, argumentList);
865
+ } else if (currentExpression is PrefixedIdentifier ) {
866
+ expression = astFactory.methodInvocation (
867
+ currentExpression.prefix,
868
+ currentExpression.period,
869
+ currentExpression.identifier,
870
+ typeArguments,
871
+ argumentList);
872
+ } else if (currentExpression is PropertyAccess ) {
873
+ expression = astFactory.methodInvocation (
874
+ currentExpression.target,
875
+ currentExpression.operator ,
876
+ currentExpression.propertyName,
877
+ typeArguments,
878
+ argumentList);
879
+ } else {
880
+ expression = astFactory.functionExpressionInvocation (
881
+ expression, typeArguments, argumentList);
882
+ }
883
+ if (! primaryAllowed) {
884
+ isOptional = false ;
885
+ }
886
+ }
887
+ Expression selectorExpression = parseAssignableSelector (
888
+ expression, isOptional || (expression is PrefixedIdentifier ));
889
+ if (identical (selectorExpression, expression)) {
890
+ return expression;
891
+ }
892
+ expression = selectorExpression;
893
+ isOptional = true ;
853
894
}
854
- return _parseAssignableExpressionNotStartingWithSuper (primaryAllowed);
855
895
}
856
896
857
897
/**
@@ -4457,7 +4497,7 @@ class Parser {
4457
4497
*
4458
4498
* selector ::=
4459
4499
* assignableSelector
4460
- * | argumentList
4500
+ * | argumentPart
4461
4501
*/
4462
4502
Expression parsePostfixExpression () {
4463
4503
Expression operand = parseAssignableExpression (true );
@@ -4583,8 +4623,6 @@ class Parser {
4583
4623
} else if (keyword == Keyword .THIS ) {
4584
4624
return astFactory.thisExpression (getAndAdvance ());
4585
4625
} else if (keyword == Keyword .SUPER ) {
4586
- // TODO(paulberry): verify with Gilad that "super" must be followed by
4587
- // unconditionalAssignableSelector in this case.
4588
4626
return parseAssignableSelector (
4589
4627
astFactory.superExpression (getAndAdvance ()), false ,
4590
4628
allowConditional: false );
@@ -5416,7 +5454,7 @@ class Parser {
5416
5454
operator , astFactory.superExpression (getAndAdvance ()));
5417
5455
}
5418
5456
return astFactory.prefixExpression (
5419
- operator , _parseAssignableExpressionNotStartingWithSuper (false ));
5457
+ operator , parseAssignableExpression (false ));
5420
5458
} else if (type == TokenType .PLUS ) {
5421
5459
_reportErrorForCurrentToken (ParserErrorCode .MISSING_IDENTIFIER );
5422
5460
return createSyntheticIdentifier ();
@@ -6381,6 +6419,21 @@ class Parser {
6381
6419
return false ;
6382
6420
}
6383
6421
6422
+ /**
6423
+ * Return `true` if the given [expression] is a primary expression that is
6424
+ * allowed to be an assignable expression without any assignable selector.
6425
+ */
6426
+ bool _isValidAssignableExpression (Expression expression) {
6427
+ if (expression is SimpleIdentifier ) {
6428
+ return true ;
6429
+ } else if (expression is PropertyAccess ) {
6430
+ return expression.target is SuperExpression ;
6431
+ } else if (expression is IndexExpression ) {
6432
+ return expression.target is SuperExpression ;
6433
+ }
6434
+ return false ;
6435
+ }
6436
+
6384
6437
/**
6385
6438
* Increments the error reporting lock level. If level is more than `0` , then
6386
6439
* [reportError] wont report any error.
@@ -6519,61 +6572,6 @@ class Parser {
6519
6572
keyword, leftParen, expression, comma, message, rightParen);
6520
6573
}
6521
6574
6522
- /**
6523
- * Parse an assignable expression given that the current token is not 'super'.
6524
- * The [primaryAllowed] is `true` if the expression is allowed to be a primary
6525
- * without any assignable selector. Return the assignable expression that was
6526
- * parsed.
6527
- */
6528
- Expression _parseAssignableExpressionNotStartingWithSuper (
6529
- bool primaryAllowed) {
6530
- //
6531
- // A primary expression can start with an identifier. We resolve the
6532
- // ambiguity by determining whether the primary consists of anything other
6533
- // than an identifier and/or is followed by an assignableSelector.
6534
- //
6535
- Expression expression = parsePrimaryExpression ();
6536
- bool isOptional = primaryAllowed || expression is SimpleIdentifier ;
6537
- while (true ) {
6538
- while (_isLikelyArgumentList ()) {
6539
- TypeArgumentList typeArguments = _parseOptionalTypeArguments ();
6540
- ArgumentList argumentList = parseArgumentList ();
6541
- Expression currentExpression = expression;
6542
- if (currentExpression is SimpleIdentifier ) {
6543
- expression = astFactory.methodInvocation (
6544
- null , null , currentExpression, typeArguments, argumentList);
6545
- } else if (currentExpression is PrefixedIdentifier ) {
6546
- expression = astFactory.methodInvocation (
6547
- currentExpression.prefix,
6548
- currentExpression.period,
6549
- currentExpression.identifier,
6550
- typeArguments,
6551
- argumentList);
6552
- } else if (currentExpression is PropertyAccess ) {
6553
- expression = astFactory.methodInvocation (
6554
- currentExpression.target,
6555
- currentExpression.operator ,
6556
- currentExpression.propertyName,
6557
- typeArguments,
6558
- argumentList);
6559
- } else {
6560
- expression = astFactory.functionExpressionInvocation (
6561
- expression, typeArguments, argumentList);
6562
- }
6563
- if (! primaryAllowed) {
6564
- isOptional = false ;
6565
- }
6566
- }
6567
- Expression selectorExpression = parseAssignableSelector (
6568
- expression, isOptional || (expression is PrefixedIdentifier ));
6569
- if (identical (selectorExpression, expression)) {
6570
- return expression;
6571
- }
6572
- expression = selectorExpression;
6573
- isOptional = true ;
6574
- }
6575
- }
6576
-
6577
6575
/**
6578
6576
* Parse a block when we need to check for an open curly brace and recover
6579
6577
* when there isn't one. Return the block that was parsed.
0 commit comments