Move lambda out of primary prefix

This commit is contained in:
Clément Fournier
2019-05-24 19:08:06 +02:00
parent cfc31e42e9
commit 13f052dcf2

View File

@ -1717,6 +1717,7 @@ int Modifiers() #void:
} }
{ {
( (
LOOKAHEAD(2)
( (
"public" { modifiers |= AccessNode.PUBLIC; } "public" { modifiers |= AccessNode.PUBLIC; }
| "static" { modifiers |= AccessNode.STATIC; } | "static" { modifiers |= AccessNode.STATIC; }
@ -1730,7 +1731,7 @@ int Modifiers() #void:
| "volatile" { modifiers |= AccessNode.VOLATILE; } | "volatile" { modifiers |= AccessNode.VOLATILE; }
| "strictfp" { modifiers |= AccessNode.STRICTFP; } | "strictfp" { modifiers |= AccessNode.STRICTFP; }
| "default" { modifiers |= AccessNode.DEFAULT; checkForBadDefaultImplementationUsage(); } | "default" { modifiers |= AccessNode.DEFAULT; checkForBadDefaultImplementationUsage(); }
| LOOKAHEAD("@" <IDENTIFIER>) Annotation() | Annotation()
) )
)* )*
{ {
@ -2252,6 +2253,10 @@ void Expression() #AssignmentExpression(>1):
// as a workaround. // as a workaround.
{AssignmentOp op = null;} {AssignmentOp op = null;}
{ {
LOOKAHEAD( <IDENTIFIER> "->", {!inSwitchLabel} ) LambdaExpression()
| LOOKAHEAD( "(" <IDENTIFIER> ( "," <IDENTIFIER> )* ")" "->" , {!inSwitchLabel} ) LambdaExpression()
| LOOKAHEAD( LambdaParameterList() "->", {!inSwitchLabel} ) LambdaExpression()
|
ConditionalExpression() ConditionalExpression()
[ [
LOOKAHEAD(2) op=AssignmentOperator() {jjtThis.setOp(op);} Expression() LOOKAHEAD(2) op=AssignmentOperator() {jjtThis.setOp(op);} Expression()
@ -2438,11 +2443,20 @@ void UnaryExpressionNotPlusMinus() #UnaryExpression((jjtn000.getImage() != null)
("(" AnnotatedType() ")" UnaryExpression()) #CastExpression ("(" AnnotatedType() ")" UnaryExpression()) #CastExpression
// here we avoid looking ahead for a whole unary expression, instead just testing the token after ")" // here we avoid looking ahead for a whole unary expression, instead just testing the token after ")"
| LOOKAHEAD("(" TypeAnnotationList() IntersectionType(true) ")" UnaryExprNotPmStart() ) | LOOKAHEAD("(" TypeAnnotationList() IntersectionType(true) ")" UnaryExprNotPmStart() )
("(" TypeAnnotationList() IntersectionType(true) ")" UnaryExpressionNotPlusMinus()) #CastExpression ("(" TypeAnnotationList() IntersectionType(true) ")" CastSubject()) #CastExpression
| PostfixExpression() | PostfixExpression()
| SwitchExpression() | SwitchExpression()
} }
private void CastSubject() #void:
{}
{
LOOKAHEAD( <IDENTIFIER> "->", {!inSwitchLabel} ) LambdaExpression()
| LOOKAHEAD( "(" <IDENTIFIER> ( "," <IDENTIFIER> )* ")" "->" , {!inSwitchLabel} ) LambdaExpression()
| LOOKAHEAD( LambdaParameterList() "->", {!inSwitchLabel} ) LambdaExpression()
| UnaryExpressionNotPlusMinus()
}
private void UnaryExprNotPmStart() #void: private void UnaryExprNotPmStart() #void:
{} {}
{ {
@ -2500,14 +2514,6 @@ void PrimaryPrefix() #void :
| "." "class" #ClassLiteral(1) | "." "class" #ClassLiteral(1)
) )
// todo we can probably simplify the lambda lookaheads
// by moving them out of primary prefix!
| LOOKAHEAD( <IDENTIFIER> "->", {!inSwitchLabel} ) LambdaExpression()
| LOOKAHEAD( "(" <IDENTIFIER> ( "," <IDENTIFIER> )* ")" "->" , {!inSwitchLabel} ) LambdaExpression()
| LOOKAHEAD( LambdaParameterList() "->", {!inSwitchLabel} ) LambdaExpression()
| ("(" Expression() ")") #ParenthesizedExpression | ("(" Expression() ")") #ParenthesizedExpression
| AmbiguousName() [ LOOKAHEAD(Step2Lahead()) PrimaryStep2() ] | AmbiguousName() [ LOOKAHEAD(Step2Lahead()) PrimaryStep2() ]
} }