From a917d88909981508f5d7883cc0f7d5b92fe7d434 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 1 Jan 2026 18:17:08 +0100 Subject: [PATCH] Enhance whitespace handling in parser Removes warnings generated by javacc plugin --- velocity-custom-parser-example/pom.xml | 2 +- velocity-engine-core/src/main/parser/Parser.jjt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/velocity-custom-parser-example/pom.xml b/velocity-custom-parser-example/pom.xml index 7c609b23e..652f1ca0f 100644 --- a/velocity-custom-parser-example/pom.xml +++ b/velocity-custom-parser-example/pom.xml @@ -148,7 +148,7 @@ ${parser.debug} ${parser.debug} ${parser.debug} - ${maven.compiler.target} + 1.8 true ${parser.package}.node ${project.build.directory}/parser/org/apache/velocity/runtime/parser diff --git a/velocity-engine-core/src/main/parser/Parser.jjt b/velocity-engine-core/src/main/parser/Parser.jjt index 4e790735c..39e9521dd 100644 --- a/velocity-engine-core/src/main/parser/Parser.jjt +++ b/velocity-engine-core/src/main/parser/Parser.jjt @@ -1576,7 +1576,7 @@ boolean Statement(boolean afterNewline) #void : | LOOKAHEAD( { getToken(1).kind == WORD || getToken(1).kind == BRACKETED_WORD || afterNewline && getToken(1).kind == WHITESPACE && ( getToken(2).kind == WORD || getToken(2).kind == BRACKETED_WORD ) } ) afterNewline = Directive(afterNewline) { return afterNewline; } | afterNewline = Text() { return afterNewline; } | () #Text { return true; } -| ((() { afterNewline = false; } ) (() { afterNewline = true; })? ) #Text { return afterNewline; } +| ((() { afterNewline = false; } ) (LOOKAHEAD(2) () { afterNewline = true; })? ) #Text { return afterNewline; } | () #Text { return false; } | () #Text { return true; } | LOOKAHEAD(2) EndingZeroWidthWhitespace() { return afterNewline; } @@ -2113,11 +2113,11 @@ void IntegerRange() : {} */ void IndexParameter() #void: {} { - (|)* + (LOOKAHEAD(2) (|))* ( Expression() ) - (|)* + (LOOKAHEAD(2) (|))* } @@ -2493,7 +2493,7 @@ void MultiplicativeExpression() #void : {} void UnaryExpression() #void : {} { - ( | )* + (LOOKAHEAD(2) ( | ))* ( UnaryExpression() #NotNode(1) | PrimaryExpression() #NegateNode(1) @@ -2503,7 +2503,7 @@ void UnaryExpression() #void : {} void PrimaryExpression() #void : {} { - ( | )* + (LOOKAHEAD(2) ( | ))* ( StringLiteral() | Reference() @@ -2516,7 +2516,7 @@ void PrimaryExpression() #void : {} | False() | Expression() ) - ( | )* + (LOOKAHEAD(2) ( | ))* } /* ======================================================================