From 0cd73b8e77148ab03d39033d3e71a9c90f7b6097 Mon Sep 17 00:00:00 2001 From: Nick Mancuso Date: Sat, 8 Aug 2020 10:32:29 -0400 Subject: [PATCH] minor: reformatting of grammar related to (#6615) --- .../tools/checkstyle/grammar/java.g | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java.g b/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java.g index a205115bc10..fe3315bd737 100644 --- a/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java.g +++ b/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java.g @@ -120,8 +120,7 @@ tokens { PATTERN_VARIABLE_DEF; RECORD_DEF; LITERAL_record="record"; RECORD_COMPONENTS; RECORD_COMPONENT_DEF; COMPACT_CTOR_DEF; - TEXT_BLOCK_LITERAL_BEGIN; TEXT_BLOCK_CONTENT; - TEXT_BLOCK_LITERAL_END; + TEXT_BLOCK_LITERAL_BEGIN; TEXT_BLOCK_CONTENT; TEXT_BLOCK_LITERAL_END; } { @@ -1503,31 +1502,38 @@ unaryExpression unaryExpressionNotPlusMinus : BNOT^ unaryExpression | LNOT^ unaryExpression + | castExpression + ; - | ( // subrule allows option to shut off warnings - options { - // "(int" ambig with postfixExpr due to lack of sequence - // info in linear approximate LL(k). It's ok. Shut up. - generateAmbigWarnings=false; - } - : // If typecast is built in type, must be numeric operand - // Also, no reason to backtrack if type keyword like int, float... - (LPAREN builtInTypeSpec[true] RPAREN unaryExpression) => - lpb:LPAREN^ {#lpb.setType(TYPECAST);} builtInTypeSpec[true] RPAREN - unaryExpression - - // Have to backtrack to see if operator follows. If no operator - // follows, it's a typecast. No semantic checking needed to parse. - // if it _looks_ like a cast, it _is_ a cast; else it's a "(expr)" - | (LPAREN typeCastParameters RPAREN unaryExpressionNotPlusMinus)=> - lp:LPAREN^ {#lp.setType(TYPECAST);} typeCastParameters RPAREN - unaryExpressionNotPlusMinus - - | (LPAREN typeCastParameters RPAREN lambdaExpression) => - lpl:LPAREN^ {#lpl.setType(TYPECAST);} typeCastParameters RPAREN - lambdaExpression - - | postfixExpression +castExpression + : ( // subrule allows option to shut off warnings + options { + // "(int" ambig with postfixExpr due to lack of sequence + // info in linear approximate LL(k). It's ok. Shut up. + generateAmbigWarnings=false; + } + : // If typecast is built in type, must be numeric operand + // Also, no reason to backtrack if type keyword like int, float... + (LPAREN builtInTypeSpec[true] RPAREN unaryExpression) => + lpb:LPAREN^ {#lpb.setType(TYPECAST);} builtInTypeSpec[true] RPAREN + unaryExpression + + // This lambda/castExpression must stay above the unaryExpressionNotPlusMinus + // typecast rule below, or typecasting w/ lambdas breaks because IDENT is + // misidentified as a postfixExpression and not as part of the lambdaExpression. + // See https://github.com/checkstyle/checkstyle/pull/8449#issuecomment-658278145 + | (LPAREN typeCastParameters RPAREN lambdaExpression) => + lpl:LPAREN^ {#lpl.setType(TYPECAST);} + typeCastParameters RPAREN lambdaExpression + + // Have to backtrack to see if operator follows. If no operator + // follows, it's a typecast. No semantic checking needed to parse. + // if it _looks_ like a cast, it _is_ a cast; else it's a "(expr)" + | (LPAREN typeCastParameters RPAREN unaryExpressionNotPlusMinus)=> + lp:LPAREN^ {#lp.setType(TYPECAST);} typeCastParameters RPAREN + unaryExpressionNotPlusMinus + + | postfixExpression ) ;