From a046b8f93de5d89e6f57c3e5b710026d87c044b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 13 Oct 2016 14:14:34 -0300 Subject: [PATCH 1/2] Simplify lambda parsing - Handle less scenarios - Have scenarios be defined more broadly (ie: allow more than 3 params) - This improves parsing performance by roughly ~10% --- pmd-java/etc/grammar/Java.jjt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 5b2b631c37..7588c36ce9 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1,4 +1,8 @@ /** + * Improve lambda detection in PrimaryPrefix to improve parsing performance. + * + * Juan Martin Sotuyo Dodero 10/2016 + *==================================================================== * Fix for an expression within an additive expression that was * wrongly taken as a cast expression. * Bug #1484 @@ -1809,12 +1813,9 @@ void PrimaryPrefix() : | LOOKAHEAD(2) "this" {jjtThis.setUsesThisModifier();} | "super" {jjtThis.setUsesSuperModifier();} | LOOKAHEAD( "(" ")" "->" ) LambdaExpression() -| LOOKAHEAD( "->" ) LambdaExpression() -| LOOKAHEAD( "(" VariableDeclaratorId() ")" "->" ) LambdaExpression() -| LOOKAHEAD( "(" VariableDeclaratorId() "," VariableDeclaratorId() ["," VariableDeclaratorId()] ")" "->" ) LambdaExpression() -| LOOKAHEAD( "(" FormalParameter() ")" "->" ) LambdaExpression() -| LOOKAHEAD( "(" FormalParameter() "," FormalParameter() ["," FormalParameter() ] ")" "->" ) LambdaExpression() -| LOOKAHEAD( LambdaExpression() ) LambdaExpression() +| LOOKAHEAD( VariableDeclaratorId() "->" ) LambdaExpression() +| LOOKAHEAD( "(" VariableDeclaratorId() ( "," VariableDeclaratorId() )* ")" "->" ) LambdaExpression() +| LOOKAHEAD( FormalParameters() "->" ) LambdaExpression() | LOOKAHEAD(3) "(" Expression() ")" | AllocationExpression() | LOOKAHEAD( ResultType() "." "class" ) ResultType() "." "class" From 478ed3463c1563c6eecce1ed629fa8fc547dd1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Fri, 14 Oct 2016 09:24:06 -0300 Subject: [PATCH 2/2] Simplify lambda pursing even further - Remove a redundant case - Restrict grammar according to spec with a simpler scenario --- pmd-java/etc/grammar/Java.jjt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 7588c36ce9..65f9f91c4f 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1812,8 +1812,7 @@ void PrimaryPrefix() : Literal() | LOOKAHEAD(2) "this" {jjtThis.setUsesThisModifier();} | "super" {jjtThis.setUsesSuperModifier();} -| LOOKAHEAD( "(" ")" "->" ) LambdaExpression() -| LOOKAHEAD( VariableDeclaratorId() "->" ) LambdaExpression() +| LOOKAHEAD( "->" ) LambdaExpression() | LOOKAHEAD( "(" VariableDeclaratorId() ( "," VariableDeclaratorId() )* ")" "->" ) LambdaExpression() | LOOKAHEAD( FormalParameters() "->" ) LambdaExpression() | LOOKAHEAD(3) "(" Expression() ")"