From commits-return-3836-archive-asf-public=cust-asf.ponee.io@velocity.apache.org Thu Aug 22 14:23:02 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 65E35180669 for ; Thu, 22 Aug 2019 16:23:01 +0200 (CEST) Received: (qmail 22686 invoked by uid 500); 22 Aug 2019 14:23:00 -0000 Mailing-List: contact commits-help@velocity.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@velocity.apache.org Delivered-To: mailing list commits@velocity.apache.org Received: (qmail 22665 invoked by uid 99); 22 Aug 2019 14:23:00 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Aug 2019 14:23:00 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id D99883A071B for ; Thu, 22 Aug 2019 14:22:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1865687 [1/2] - in /velocity/engine/trunk: ./ velocity-custom-parser-example/ velocity-engine-core/ velocity-engine-core/src/main/java/ velocity-engine-core/src/main/java/org/apache/velocity/runtime/ velocity-engine-core/src/main/java/org/... Date: Thu, 22 Aug 2019 14:22:59 -0000 To: commits@velocity.apache.org From: cbrisson@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190822142259.D99883A071B@svn01-us-west.apache.org> Author: cbrisson Date: Thu Aug 22 14:22:58 2019 New Revision: 1865687 URL: http://svn.apache.org/viewvc?rev=1865687&view=rev Log: [VELOCITY-917] Merge custom parser characters example back to trunk Added: velocity/engine/trunk/velocity-custom-parser-example/ - copied from r1865676, velocity/engine/branches/parser_experiments/velocity-custom-parser-example/ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserConfiguration.java - copied unchanged from r1865676, velocity/engine/branches/parser_experiments/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserConfiguration.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/Parser.java - copied unchanged from r1865676, velocity/engine/branches/parser_experiments/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/Parser.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/JJTParserState.java - copied unchanged from r1865676, velocity/engine/branches/parser_experiments/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/JJTParserState.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ParserTreeConstants.java - copied unchanged from r1865676, velocity/engine/branches/parser_experiments/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ParserTreeConstants.java velocity/engine/trunk/velocity-engine-core/src/main/parser/Parser.jjt - copied unchanged from r1865676, velocity/engine/branches/parser_experiments/velocity-engine-core/src/main/parser/Parser.jjt Modified: velocity/engine/trunk/ (props changed) velocity/engine/trunk/pom.xml velocity/engine/trunk/velocity-engine-core/pom.xml velocity/engine/trunk/velocity-engine-core/src/main/java/ (props changed) velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/NodeUtils.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java velocity/engine/trunk/velocity-engine-core/src/test/java/ (props changed) velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/TextblockTestCase.java velocity/engine/trunk/velocity-engine-examples/pom.xml velocity/engine/trunk/velocity-engine-scripting/pom.xml Propchange: velocity/engine/trunk/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Aug 22 14:22:58 2019 @@ -2,4 +2,5 @@ /velocity/engine/branches/VELOCITY-892:1844076-1854372 /velocity/engine/branches/VELOCITY-898:1843220-1843786 /velocity/engine/branches/VELOCITY-909:1854851-1855185 +/velocity/engine/branches/parser_experiments:1860001-1865676 /velocity/engine/trunk:992133,1032159 Modified: velocity/engine/trunk/pom.xml URL: http://svn.apache.org/viewvc/velocity/engine/trunk/pom.xml?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/pom.xml (original) +++ velocity/engine/trunk/pom.xml Thu Aug 22 14:22:58 2019 @@ -21,303 +21,324 @@ --> - 4.0.0 + 4.0.0 - - org.apache.velocity - velocity-master - 3 - - + + org.apache.velocity + velocity-master + 3 + + - velocity-engine-parent - 2.2-SNAPSHOT + velocity-engine-parent + 2.2-SNAPSHOT - Apache Velocity - http://velocity.apache.org/engine/devel/ - Apache Velocity is a general purpose template engine. - 2000 - pom + Apache Velocity + http://velocity.apache.org/engine/devel/ + Apache Velocity is a general purpose template engine. + 2000 + pom - - UTF-8 - 4.12 - 1.7.26 - 2.19.1 - https://issues.apache.org/jira/browse - 1.8 - 1.8 - + + UTF-8 + 4.12 + 1.7.26 + 2.19.1 + https://issues.apache.org/jira/browse + 1.8 + 1.8 + - - install - - - - maven-release-plugin - 2.5.3 - - false - true - deploy - -Papache-release - - - - maven-jar-plugin - 3.1.1 - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - org.apache.felix - maven-bundle-plugin - 3.5.0 - - - bundle-manifest - process-classes - - manifest - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - true - true - ${maven.compiler.source} - ${maven.compiler.target} - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.1.0 - - - none - - - - aggregate - - aggregate - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-bytecode-version - - enforce - - - - - ${maven.compiler.target} - - - [1.8,) - - - true - - - - ban-known-bad-maven-versions - - enforce - - - - - [3.0.5,) - Maven minimal expected version is 3.0.5. - - - - - - - - org.codehaus.mojo - extra-enforcer-rules - 1.0-beta-9 - - - - - + + install + + + + maven-release-plugin + 2.5.3 + + false + true + deploy + -Papache-release + + + + maven-jar-plugin + 3.1.1 + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + 3.5.0 + + + bundle-manifest + process-classes + + manifest + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.1 + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + com.google.code.maven-replacer-plugin + replacer + 1.5.3 + + + org.apache.maven.plugins + maven-clean-plugin + 3.1.0 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + true + ${maven.compiler.source} + ${maven.compiler.target} + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.0 + + + none + + + + aggregate + + aggregate + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-bytecode-version + + enforce + + + + + ${maven.compiler.target} + + + [1.8,) + + + true + + + + ban-known-bad-maven-versions + + enforce + + + + + [3.0.5,) + Maven minimal expected version is 3.0.5. + + + + + + + + org.codehaus.mojo + extra-enforcer-rules + 1.0-beta-9 + + + + + - - - velocity.apache.org - scpexe://people.apache.org/www/velocity.apache.org/engine/devel/ - - - + + + velocity.apache.org + scpexe://people.apache.org/www/velocity.apache.org/engine/devel/ + + + - - scm:svn:http://svn.apache.org/repos/asf/velocity/engine/trunk - scm:svn:https://svn.apache.org/repos/asf/velocity/engine/trunk - http://svn.apache.org/viewvc/velocity/engine/trunk - + + scm:svn:http://svn.apache.org/repos/asf/velocity/engine/trunk + scm:svn:https://svn.apache.org/repos/asf/velocity/engine/trunk + http://svn.apache.org/viewvc/velocity/engine/trunk + - - JIRA - ${jira.browse.url}/VELOCITY - - - velocity-engine-core - velocity-engine-examples - velocity-engine-scripting - + + JIRA + ${jira.browse.url}/VELOCITY + + + velocity-engine-core + velocity-engine-examples + velocity-engine-scripting + velocity-custom-parser-example + - - - - Adrian Tarau - - - Aki Nieminen - - - Alexey Pachenko - - - Anil K. Vijendran - - - Attila Szegedi - - - Bob McWhirter - - - Byron Foster - - - Candid Dauth - - - Christoph Reck - - - Darren Cruse - - - Dave Bryson - - - David Kinnvall - - - Dawid Weiss - - - Dishara Wijewardana - - - Eelco Hillenius - - - Fedor Karpelevitch - - - Felipe Maschio - - - Gal Shachor - - - Hervé Boutemy - - - Jarkko Viinamäki - - - Jeff Bowden - - - Jorgen Rydenius - - - Jose Alberto Fernandez - - - Kasper Nielsen - - - Kent Johnson - - - Kyle F. Downey - - - Leon Messerschmidt - - - Llewellyn Falco - - - Matt Raible - - - Matt Ryall - - - Matthijs Lambooy - - - Oswaldo Hernandez - - - Paulo Gaspar - - - Peter Romianowski - - - Robert Burrell Donkin - - - Robert Fuller - - - Sam Ruby - - - Sean Legassick - - - Serge Knystautas - - - Stephane Bailliez - - - Stephen Habermann - - - Sylwester Lachiewicz - - + + + + Adrian Tarau + + + Aki Nieminen + + + Alexey Pachenko + + + Anil K. Vijendran + + + Attila Szegedi + + + Bob McWhirter + + + Byron Foster + + + Candid Dauth + + + Christoph Reck + + + Darren Cruse + + + Dave Bryson + + + David Kinnvall + + + Dawid Weiss + + + Dishara Wijewardana + + + Eelco Hillenius + + + Fedor Karpelevitch + + + Felipe Maschio + + + Gal Shachor + + + Hervé Boutemy + + + Jarkko Viinamäki + + + Jeff Bowden + + + Jorgen Rydenius + + + Jose Alberto Fernandez + + + Kasper Nielsen + + + Kent Johnson + + + Kyle F. Downey + + + Leon Messerschmidt + + + Llewellyn Falco + + + Matt Raible + + + Matt Ryall + + + Matthijs Lambooy + + + Oswaldo Hernandez + + + Paulo Gaspar + + + Peter Romianowski + + + Robert Burrell Donkin + + + Robert Fuller + + + Sam Ruby + + + Sean Legassick + + + Serge Knystautas + + + Stephane Bailliez + + + Stephen Habermann + + + Sylwester Lachiewicz + + Modified: velocity/engine/trunk/velocity-engine-core/pom.xml URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/pom.xml?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/pom.xml (original) +++ velocity/engine/trunk/velocity-engine-core/pom.xml Thu Aug 22 14:22:58 2019 @@ -1,3 +1,4 @@ + - 4.0.0 - - org.apache.velocity - velocity-engine-parent - 2.2-SNAPSHOT - - - velocity-engine-core - Apache Velocity - Engine - - - - false - - - false - - false - - - org.hsqldb - hsqldb - 2.3.5 - org.hsqldb.jdbcDriver - jdbc:hsqldb:. - sa - - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.1.0 - - false - - ${*} - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.1 - - - shade - package - - shade - - - - - commons-io:commons-io - - - org.slf4j:slf4j-api - - - - - org.apache.commons.io - org.apache.velocity.shaded.commons.io - - - true - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.plugin.version} - - ${maven.test.skip} - - - test - ${test} - - - test.compare.dir - ${project.build.testOutputDirectory} - - - test.result.dir - ${project.build.directory}/results - - - org.slf4j.simpleLogger.defaultLogLevel - warn - - - org.slf4j.simpleLogger.logFile - ${project.build.directory}/velocity.log - - - test.jdbc.driver.className - ${test.jdbc.driver.className} - - - test.jdbc.uri - ${test.jdbc.uri} - - - test.jdbc.login - ${test.jdbc.login} - - - test.jdbc.password - ${test.jdbc.password} - - - - - - integration-test - integration-test - - test - - - false - - - - - - org.codehaus.mojo - javacc-maven-plugin - 2.6 - - - jjtree-javacc - - jjtree-javacc - - - - - false - true - ${parser.nodefiles} - true - ${parser.debug} - ${parser.debug} - ${parser.debug} - ${maven.compiler.target} - true - org.apache.velocity.runtime.parser.node - ${basedir}/src/main/parser - true - - - - org.apache.felix - maven-bundle-plugin - - - - org.apache.velocity.* - - - !org.apache.commons.io, - * - - - - - - - - - org.apache.commons - commons-lang3 - 3.8.1 - - - org.slf4j - slf4j-api - ${slf4j.version} - - - junit - junit - ${junit.version} - test - - - ${test.jdbc.driver.groupId} - ${test.jdbc.driver.artifactId} - ${test.jdbc.driver.version} - test - - - commons-io - commons-io - 2.6 - - - org.slf4j - slf4j-simple - ${slf4j.version} - test - - - - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - true - Low - Max - src/etc/build/findbugs-exclude.xml - target/site - - - - + 4.0.0 + + org.apache.velocity + velocity-engine-parent + 2.2-SNAPSHOT + + + velocity-engine-core + Apache Velocity - Engine + + + + false + org.apache.velocity.runtime.parser + Standard + * + @ + $ + # + + + org.hsqldb + hsqldb + 2.3.5 + org.hsqldb.jdbcDriver + jdbc:hsqldb:. + sa + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + + + generate-parser-grammar + generate-sources + + copy-resources + + + false + + + ${*} + + + + src/main/parser + true + + + ${project.build.directory}/parser + + + + + expose-parser-grammar + process-resources + + copy-resources + + + + + src/main/parser + false + + + ${project.build.outputDirectory}/org/apache/velocity/runtime/parser + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + shade + package + + shade + + + + + commons-io:commons-io + + + org.slf4j:slf4j-api + + + + + org.apache.commons.io + org.apache.velocity.shaded.commons.io + + + true + + + + + + + + org.codehaus.mojo + javacc-maven-plugin + 2.6 + + false + true + false + true + ${parser.debug} + ${parser.debug} + ${parser.debug} + ${maven.compiler.target} + true + org.apache.velocity.runtime.parser.node + ${project.build.directory}/parser + true + + + + + jjtree-javacc + + jjtree-javacc + + + + Parser.jjt + + + + + + + + + com.google.code.maven-replacer-plugin + replacer + + + patch-parser-files + process-sources + + replace + + + ${project.build.directory}/generated-sources/javacc/org/apache/velocity/runtime/parser/TokenMgrError.java + + + static final int + public static final int + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + org.apache.velocity.* + + + !org.apache.commons.io, + * + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + ${maven.test.skip} + + + test + ${test} + + + test.compare.dir + ${project.build.testOutputDirectory} + + + test.result.dir + ${project.build.directory}/results + + + org.slf4j.simpleLogger.defaultLogLevel + warn + + + org.slf4j.simpleLogger.logFile + ${project.build.directory}/velocity.log + + + test.jdbc.driver.className + ${test.jdbc.driver.className} + + + test.jdbc.uri + ${test.jdbc.uri} + + + test.jdbc.login + ${test.jdbc.login} + + + test.jdbc.password + ${test.jdbc.password} + + + + + + integration-test + integration-test + + test + + + false + + + + + + + + + + + org.apache.commons + commons-lang3 + 3.8.1 + + + org.slf4j + slf4j-api + ${slf4j.version} + + + junit + junit + ${junit.version} + test + + + ${test.jdbc.driver.groupId} + ${test.jdbc.driver.artifactId} + ${test.jdbc.driver.version} + test + + + commons-io + commons-io + 2.6 + + + org.slf4j + slf4j-simple + ${slf4j.version} + test + + + + + + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.4 + + true + Low + Max + src/etc/build/findbugs-exclude.xml + target/site + + + + Propchange: velocity/engine/trunk/velocity-engine-core/src/main/java/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Aug 22 14:22:58 2019 @@ -3,4 +3,5 @@ /velocity/engine/branches/VELOCITY-892/velocity-engine-core/src/main/java:1844076-1854372 /velocity/engine/branches/VELOCITY-898/velocity-engine-core/src/main/java:1843220-1843786 /velocity/engine/branches/VELOCITY-909/velocity-engine-core/src/main/java:1854851-1855185 +/velocity/engine/branches/parser_experiments/velocity-engine-core/src/main/java:1860001-1865676 /velocity/engine/trunk/src/java:1032134 Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java Thu Aug 22 14:22:58 2019 @@ -391,21 +391,21 @@ public interface RuntimeConstants extend /* * ---------------------------------------------------------------------- - * G E N E R A L R U N T I M E C O N F I G U R A T I O N + * P A R S E R C O N F I G U R A T I O N * ---------------------------------------------------------------------- */ - /** Whether to use string interning. */ - String RUNTIME_STRING_INTERNING = "runtime.string_interning"; - - /** Switch for the interpolation facility for string literals. */ - String INTERPOLATE_STRINGLITERALS = "runtime.interpolate_string_literals"; - - /** Switch for ignoring nulls in math equations vs throwing exceptions. */ - String STRICT_MATH = "runtime.strict_math"; + /** + * Property specifying the parser class to use + * @since 2.2 + */ + String PARSER_CLASS = "parser.class"; - /** Key upon which a context should be accessible within itself */ - String CONTEXT_AUTOREFERENCE_KEY = "context.self_reference_key"; + /** + * Default parser class + * @since 2.2 + */ + String DEFAULT_PARSER_CLASS = "org.apache.velocity.runtime.parser.StandardParser"; /** * The parser.pool.class property specifies the name of the {@link org.apache.velocity.util.SimplePool} @@ -424,6 +424,24 @@ public interface RuntimeConstants extend */ String PARSER_HYPHEN_ALLOWED = "parser.allow_hyphen_in_identifiers"; + /* + * ---------------------------------------------------------------------- + * G E N E R A L R U N T I M E C O N F I G U R A T I O N + * ---------------------------------------------------------------------- + */ + + /** Whether to use string interning. */ + String RUNTIME_STRING_INTERNING = "runtime.string_interning"; + + /** Switch for the interpolation facility for string literals. */ + String INTERPOLATE_STRINGLITERALS = "runtime.interpolate_string_literals"; + + /** Switch for ignoring nulls in math equations vs throwing exceptions. */ + String STRICT_MATH = "runtime.strict_math"; + + /** Key upon which a context should be accessible within itself */ + String CONTEXT_AUTOREFERENCE_KEY = "context.self_reference_key"; + /** * Space gobbling mode * @since 2.0 Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java Thu Aug 22 14:22:58 2019 @@ -61,6 +61,9 @@ import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import java.io.Writer; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; @@ -226,6 +229,18 @@ public class RuntimeInstance implements private LogContext logContext; /** + * Configured parser class + * @since 2.2 + */ + private Constructor parserConstructor; + + /** + * Configured replacement characters in parser grammar + * @since 2.2 + */ + private ParserConfiguration parserConfiguration; + + /** * Creates a new RuntimeInstance object. */ public RuntimeInstance() @@ -320,6 +335,7 @@ public class RuntimeInstance implements this.runtimeDirectivesShared = null; this.uberSpect = null; this.stringInterning = false; + this.parserConfiguration = new ParserConfiguration(); /* * create a VM factory, introspector, and application attributes @@ -384,6 +400,20 @@ public class RuntimeInstance implements hyphenAllowedInIdentifiers = getBoolean(PARSER_HYPHEN_ALLOWED, false); } + private char getConfiguredCharacter(String configKey, char defaultChar) + { + String configuredChar = getString(configKey); + if (configuredChar != null) + { + if (configuredChar.length() != 1) + { + throw new IllegalArgumentException(String.format("value of '%s' must be a single character string, but is '%s'", configKey, configuredChar)); + } + return configuredChar.charAt(0); + } + return defaultChar; + } + /** * Gets the classname for the Uberspect introspection package and * instantiates an instance. @@ -1142,6 +1172,29 @@ public class RuntimeInstance implements private void initializeParserPool() { /* + * First initialize parser class. If it's not valid or not found, it will generate an error + * later on in this method when parser creation is tester. + */ + String parserClassName = getString(PARSER_CLASS, DEFAULT_PARSER_CLASS); + Class parserClass; + try + { + parserClass = ClassUtils.getClass(parserClassName); + } + catch (ClassNotFoundException cnfe) + { + throw new VelocityException("parser class not found: " + parserClassName, cnfe); + } + try + { + parserConstructor = parserClass.getConstructor(RuntimeServices.class); + } + catch (NoSuchMethodException nsme) + { + throw new VelocityException("parser class must provide a constructor taking a RuntimeServices argument", nsme); + } + + /* * Which parser pool? */ String pp = getString(RuntimeConstants.PARSER_POOL_CLASS); @@ -1190,6 +1243,17 @@ public class RuntimeInstance implements parserPool = (ParserPool) o; parserPool.initialize(this); + + /* + * test parser creation and use generated parser to fill up customized characters + */ + Parser parser = parserPool.get(); + parserConfiguration = new ParserConfiguration(); + parserConfiguration.setDollarChar(parser.dollar()); + parserConfiguration.setHashChar(parser.hash()); + parserConfiguration.setAtChar(parser.at()); + parserConfiguration.setAsteriskChar(parser.asterisk()); + parserPool.put(parser); } else { @@ -1215,8 +1279,14 @@ public class RuntimeInstance implements public Parser createNewParser() { requireInitialization(); - - return new Parser(this); + try + { + return (Parser)parserConstructor.newInstance((RuntimeServices)this); + } + catch (IllegalAccessException | InstantiationException | InvocationTargetException e) + { + throw new VelocityException("could not build new parser class", e); + } } /** @@ -1264,7 +1334,7 @@ public class RuntimeInstance implements if (keepParser) { /* drop the parser Template reference to allow garbage collection */ - parser.currentTemplate = null; + parser.resetCurrentTemplate(); parserPool.put(parser); } @@ -1530,7 +1600,7 @@ public class RuntimeInstance implements } /* now just create the VM call, and use evaluate */ - StringBuilder template = new StringBuilder("#"); + StringBuilder template = new StringBuilder(String.valueOf(parserConfiguration.getHashChar())); template.append(vmName); template.append("("); for (String param : params) @@ -1904,4 +1974,10 @@ public class RuntimeInstance implements { return enabledScopeControls.contains(scopeName); } + + @Override + public ParserConfiguration getParserConfiguration() + { + return parserConfiguration; + } } Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java Thu Aug 22 14:22:58 2019 @@ -489,4 +489,11 @@ public interface RuntimeServices * @since 2.1 */ boolean isScopeControlEnabled(String scopeName); + + /** + * Get the replacement characters configured for this runtime service's parser + * @return configured replacement characters + * @since 2.2 + */ + ParserConfiguration getParserConfiguration(); } Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java Thu Aug 22 14:22:58 2019 @@ -21,8 +21,10 @@ package org.apache.velocity.runtime.dire import org.apache.velocity.context.InternalContextAdapter; import org.apache.velocity.exception.TemplateInitException; +import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.RuntimeServices; import org.apache.velocity.runtime.parser.ParseException; +import org.apache.velocity.runtime.parser.Parser; import org.apache.velocity.runtime.parser.Token; import org.apache.velocity.runtime.parser.node.Node; import org.apache.velocity.runtime.parser.node.ParserTreeConstants; @@ -218,9 +220,9 @@ public class Macro extends Directive // trim off the leading $ for the args after the macro name. // saves everyone else from having to do it - if (i > 0 && macroArg.name.startsWith("$")) + if (i > 0 && macroArg.name.startsWith(String.valueOf(rsvc.getParserConfiguration().getDollarChar()))) { - macroArg.name = macroArg.name.substring(1, macroArg.name.length()); + macroArg.name = macroArg.name.substring(1); } macroArgs.add(macroArg); @@ -230,7 +232,7 @@ public class Macro extends Directive { StringBuilder msg = new StringBuilder("Macro.getArgArray(): nbrArgs="); msg.append(numArgs).append(": "); - macroToString(msg, macroArgs); + macroToString(msg, macroArgs, rsvc); rsvc.getLog("macro").debug(msg.toString()); } @@ -267,15 +269,14 @@ public class Macro extends Directive * has passed in as buf, this method returns it. * @since 1.5 */ - public static StringBuilder macroToString(final StringBuilder buf, - List macroArgs) + public static StringBuilder macroToString(final StringBuilder buf, List macroArgs, RuntimeServices rsvc) { StringBuilder ret = (buf == null) ? new StringBuilder() : buf; - ret.append('#').append(macroArgs.get(0).name).append("( "); + ret.append(rsvc.getParserConfiguration().getHashChar()).append(macroArgs.get(0).name).append("( "); for (MacroArg marg : macroArgs) { - ret.append("$").append(marg.name); + ret.append(rsvc.getParserConfiguration().getDollarChar()).append(marg.name); if (marg.defaultVal != null) { ret.append("=").append(marg.defaultVal); Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java Thu Aug 22 14:22:58 2019 @@ -30,6 +30,7 @@ import org.apache.velocity.runtime.Rende import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.RuntimeConstants.SpaceGobbling; import org.apache.velocity.runtime.RuntimeServices; +import org.apache.velocity.runtime.parser.Parser; import org.apache.velocity.runtime.parser.Token; import org.apache.velocity.runtime.parser.node.ASTDirective; import org.apache.velocity.runtime.parser.node.Node; @@ -140,7 +141,7 @@ public class RuntimeMacro extends Direct */ // Tokens can be used here since we are in init() and Tokens have not been dropped yet Token t = node.getLastToken(); - if (t.image.startsWith(")") || t.image.startsWith("#end")) + if (t.image.startsWith(")") || t.image.startsWith(rsvc.getParserConfiguration().getHashChar() + "end")) { strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false); } @@ -194,7 +195,7 @@ public class RuntimeMacro extends Direct int pos = -1; while (t != null && t != node.getLastToken()) { - if (pos == -1) pos = t.image.lastIndexOf('#'); + if (pos == -1) pos = t.image.lastIndexOf(rsvc.getParserConfiguration().getHashChar()); if (pos != -1) { buffer.append(t.image.substring(pos)); @@ -209,7 +210,7 @@ public class RuntimeMacro extends Direct if (t != null) { - if (pos == -1) pos = t.image.lastIndexOf('#'); + if (pos == -1) pos = t.image.lastIndexOf(rsvc.getParserConfiguration().getHashChar()); if (pos != -1) { buffer.append(t.image.substring(pos)); Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java Thu Aug 22 14:22:58 2019 @@ -20,6 +20,7 @@ package org.apache.velocity.runtime.dire */ import org.apache.velocity.Template; +import org.apache.velocity.runtime.parser.Parser; import java.util.AbstractMap; import java.util.HashMap; @@ -326,7 +327,7 @@ public class Scope extends AbstractMap StringBuilder sb = new StringBuilder(); if (directive != null) { - sb.append('#'); + sb.append('#'); // parser characters substitution is not handled here } sb.append(getName()); sb.append("[type:").append(getType()); Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java Thu Aug 22 14:22:58 2019 @@ -76,8 +76,8 @@ public class ASTComment extends SimpleNo { Token t = getFirstToken(); - int loc1 = t.image.indexOf("##"); - int loc2 = t.image.indexOf("#*"); + int loc1 = t.image.indexOf(parser.lineComment()); + int loc2 = t.image.indexOf(parser.blockComment()); if (loc1 == -1 && loc2 == -1) { Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java Thu Aug 22 14:22:58 2019 @@ -29,10 +29,9 @@ import org.apache.velocity.runtime.Runti import org.apache.velocity.runtime.directive.BlockMacro; import org.apache.velocity.runtime.directive.Directive; import org.apache.velocity.runtime.directive.RuntimeMacro; -import org.apache.velocity.runtime.parser.LogContext; import org.apache.velocity.runtime.parser.ParseException; import org.apache.velocity.runtime.parser.Parser; -import org.apache.velocity.runtime.parser.ParserConstants; +import org.apache.velocity.runtime.parser.StandardParserConstants; import org.apache.velocity.runtime.parser.Token; import org.apache.velocity.util.introspection.Info; @@ -113,7 +112,7 @@ public class ASTDirective extends Simple */ t = getFirstToken(); int pos = -1; - while (t != null && (pos = t.image.lastIndexOf('#')) == -1) + while (t != null && (pos = t.image.lastIndexOf(rsvc.getParserConfiguration().getHashChar())) == -1) { t = t.next; } @@ -144,11 +143,11 @@ public class ASTDirective extends Simple } t = getFirstToken(); - if (t.kind == ParserConstants.WHITESPACE) t = t.next; + if (t.kind == StandardParserConstants.WHITESPACE) t = t.next; directive.setLocation(t.beginLine, t.beginColumn, getTemplate()); directive.init(rsvc, context, this); } - else if( directiveName.startsWith("@") ) + else if( directiveName.startsWith(String.valueOf(rsvc.getParserConfiguration().getAtChar())) ) { if( this.jjtGetNumChildren() > 0 ) { @@ -313,7 +312,7 @@ public class ASTDirective extends Simple { writer.write(prefix); writer.write(morePrefix); - writer.write( "#"); + writer.write(rsvc.getParserConfiguration().getHashChar()); writer.write(directiveName); writer.write(postfix); } Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java Thu Aug 22 14:22:58 2019 @@ -93,7 +93,7 @@ public class ASTIfStatement extends Simp */ Token t = getFirstToken(); int pos = -1; - while (t != null && (pos = t.image.lastIndexOf('#')) == -1) + while (t != null && (pos = t.image.lastIndexOf(rsvc.getParserConfiguration().getHashChar())) == -1) { t = t.next; } Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java Thu Aug 22 14:22:58 2019 @@ -322,7 +322,7 @@ public class ASTReference extends Simple (!onlyTestingReference || warnInvalidTestedReferences))) { result = EventHandlerUtil.invalidGetMethod(rsvc, context, - "$" + rootString, null, null, uberInfo); + rsvc.getParserConfiguration().getDollarChar() + rootString, null, null, uberInfo); } return result; @@ -388,7 +388,7 @@ public class ASTReference extends Simple (!onlyTestingReference || warnInvalidTestedReferences || numChildren > 0)) { result = EventHandlerUtil.invalidGetMethod(rsvc, context, - "$" + rootString, previousResult, null, uberInfo); + rsvc.getParserConfiguration().getDollarChar() + rootString, previousResult, null, uberInfo); } } else @@ -402,7 +402,7 @@ public class ASTReference extends Simple (referenceType != QUIET_REFERENCE || warnInvalidQuietReferences) && (!onlyTestingReference || warnInvalidTestedReferences || failedChild < numChildren - 1)) { - StringBuilder name = new StringBuilder("$").append(rootString); + StringBuilder name = new StringBuilder(String.valueOf(rsvc.getParserConfiguration().getDollarChar())).append(rootString); for (int i = 0; i <= failedChild; i++) { Node node = jjtGetChild(i); @@ -953,7 +953,7 @@ public class ASTReference extends Simple int i = 0; int len = t.image.length(); - i = t.image.indexOf('$'); + i = t.image.indexOf(rsvc.getParserConfiguration().getDollarChar()); if (i == -1) { @@ -1037,7 +1037,7 @@ public class ASTReference extends Simple * last $ */ - int loc1 = t.image.lastIndexOf('$'); + int loc1 = t.image.lastIndexOf(rsvc.getParserConfiguration().getDollarChar()); /* * if we have extra stuff, loc > 0 Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java Thu Aug 22 14:22:58 2019 @@ -115,7 +115,7 @@ public class ASTSetDirective extends Sim */ Token t = getFirstToken(); int pos = -1; - while (t != null && (pos = t.image.lastIndexOf('#')) == -1) + while (t != null && (pos = t.image.lastIndexOf(rsvc.getParserConfiguration().getHashChar())) == -1) { t = t.next; } Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java Thu Aug 22 14:22:58 2019 @@ -96,8 +96,8 @@ public class ASTStringLiteral extends Si interpolate = rsvc.getBoolean( RuntimeConstants.INTERPOLATE_STRINGLITERALS, true) && getFirstToken().image.startsWith("\"") - && ((getFirstToken().image.indexOf('$') != -1) || (getFirstToken().image - .indexOf('#') != -1)); + && ((getFirstToken().image.indexOf(rsvc.getParserConfiguration().getDollarChar()) != -1) || (getFirstToken().image + .indexOf(rsvc.getParserConfiguration().getHashChar()) != -1)); /* * get the contents of the string, minus the '/" at each end Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java Thu Aug 22 14:22:58 2019 @@ -96,9 +96,9 @@ public class ASTText extends SimpleNode Token t = getFirstToken(); for (; t != getLastToken(); t = t.next) { - builder.append(NodeUtils.tokenLiteral(t)); + builder.append(NodeUtils.tokenLiteral(parser, t)); } - builder.append(NodeUtils.tokenLiteral(t)); + builder.append(NodeUtils.tokenLiteral(parser, t)); ctext = builder.toString(); cleanupParserAndTokens(); Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java Thu Aug 22 14:22:58 2019 @@ -35,25 +35,19 @@ import java.io.Writer; */ public class ASTTextblock extends SimpleNode { - public static final String START = "#[["; - public static final String END = "]]#"; + public final String START; + public final String END; private char[] ctext; /** - * @param id - */ - public ASTTextblock(int id) - { - super(id); - } - - /** * @param p * @param id */ public ASTTextblock(Parser p, int id) { super(p, id); + START = parser.hash() + "[["; + END = "]]" + parser.hash(); } /** Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java Thu Aug 22 14:22:58 2019 @@ -26,6 +26,7 @@ import org.apache.velocity.exception.Par import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.exception.TemplateInitException; import org.apache.velocity.runtime.Renderable; +import org.apache.velocity.runtime.parser.Parser; import org.apache.velocity.runtime.parser.Token; import java.io.IOException; @@ -221,4 +222,10 @@ public interface Node extends Renderable * @return the template this node belongs to */ Template getTemplate(); + + /** + * @return the parser which generated this node + * @since 2.2 + */ + Parser getParser(); } Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/NodeUtils.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/NodeUtils.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/NodeUtils.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/NodeUtils.java Thu Aug 22 14:22:58 2019 @@ -19,7 +19,8 @@ package org.apache.velocity.runtime.pars * under the License. */ -import org.apache.velocity.runtime.parser.ParserConstants; +import org.apache.velocity.runtime.parser.Parser; +import org.apache.velocity.runtime.parser.StandardParserConstants; import org.apache.velocity.runtime.parser.Token; /** @@ -43,7 +44,7 @@ public class NodeUtils * @return StrBuilder with the special tokens. * @since 2.0.0 */ - public static StringBuilder getSpecialText(Token t) + public static StringBuilder getSpecialText(Parser parser, Token t) { StringBuilder sb = new StringBuilder(); @@ -62,7 +63,7 @@ public class NodeUtils { char c = st.charAt(i); - if ( c == '#' || c == '$' ) + if ( c == parser.hash() || c == parser.dollar() ) { sb.append( c ); } @@ -90,7 +91,7 @@ public class NodeUtils */ continue; } - else if( cc == '$' ) + else if( cc == parser.dollar() ) { /* * a $ ends it correctly @@ -126,20 +127,20 @@ public class NodeUtils * @param t * @return A node literal. */ - public static String tokenLiteral( Token t ) + public static String tokenLiteral( Parser parser, Token t ) { - // Look at kind of token and return "" when it's a multiline comment - if (t.kind == ParserConstants.MULTI_LINE_COMMENT) + // Look at kind of token and return "" when it's a block comment + if (t.kind == StandardParserConstants.MULTI_LINE_COMMENT) { return ""; } - else if (t.specialToken == null || t.specialToken.image.startsWith("##")) + else if (t.specialToken == null || t.specialToken.image.startsWith(parser.lineComment())) { return t.image; } else { - StringBuilder special = getSpecialText(t); + StringBuilder special = getSpecialText(parser, t); if (special.length() > 0) { return special.append(t.image).toString(); Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java Thu Aug 22 14:22:58 2019 @@ -128,7 +128,7 @@ public class SimpleNode implements Node { this(i); parser = p; - template = parser.currentTemplate; + template = parser.getCurrentTemplate(); } /** @@ -352,16 +352,16 @@ public class SimpleNode implements Node // buffer allocation. VELOCITY-606 if (first == last) { - literal = NodeUtils.tokenLiteral(first); + literal = NodeUtils.tokenLiteral(parser, first); return literal; } Token t = first; - StringBuilder sb = new StringBuilder(NodeUtils.tokenLiteral(t)); + StringBuilder sb = new StringBuilder(NodeUtils.tokenLiteral(parser, t)); while (t != last) { t = t.next; - sb.append(NodeUtils.tokenLiteral(t)); + sb.append(NodeUtils.tokenLiteral(parser, t)); } literal = sb.toString(); return literal; @@ -570,4 +570,13 @@ public class SimpleNode implements Node } public Template getTemplate() { return template; } + + /** + * @return the parser which created this node + * @since 2.2 + */ + public Parser getParser() + { + return parser; + } } Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java Thu Aug 22 14:22:58 2019 @@ -19,6 +19,7 @@ package org.apache.velocity.runtime.visi * under the License. */ +import org.apache.velocity.runtime.parser.Parser; import org.apache.velocity.runtime.parser.Token; import org.apache.velocity.runtime.parser.node.*; @@ -66,7 +67,7 @@ public class NodeViewMode extends BaseVi // TODO: Token reference t = node.getFirstToken(); - if (t.specialToken != null && ! t.specialToken.image.startsWith("##")) + if (t.specialToken != null && ! t.specialToken.image.startsWith(node.getParser().lineComment())) special = t.specialToken.image; tokens = " -> " + special + t.image; Propchange: velocity/engine/trunk/velocity-engine-core/src/test/java/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Aug 22 14:22:58 2019 @@ -3,5 +3,6 @@ /velocity/engine/branches/VELOCITY-892/velocity-engine-core/src/test/java:1844076-1854372 /velocity/engine/branches/VELOCITY-898/velocity-engine-core/src/test/java:1843220-1843786 /velocity/engine/branches/VELOCITY-909/velocity-engine-core/src/test/java:1854851-1855185 +/velocity/engine/branches/parser_experiments/velocity-engine-core/src/test/java:1860001-1865676 /velocity/engine/trunk/src/test:1032134 /velocity/engine/trunk/velocity-engine-core/src/test/java:992133,1032159 Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/TextblockTestCase.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/TextblockTestCase.java?rev=1865687&r1=1865686&r2=1865687&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/TextblockTestCase.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/TextblockTestCase.java Thu Aug 22 14:22:58 2019 @@ -19,8 +19,12 @@ package org.apache.velocity.test; * under the License. */ +import org.apache.velocity.runtime.RuntimeInstance; +import org.apache.velocity.runtime.parser.Parser; import org.apache.velocity.runtime.parser.node.ASTTextblock; +import java.lang.reflect.Field; + /** * This class tests the Textblock directive. */ @@ -28,12 +32,12 @@ public class TextblockTestCase extends B { // these are all here so that the test case adapts instantly // to changes in the textblock start/end sequences - private static final String START = ASTTextblock.START; - private static final String END = ASTTextblock.END; - private static final String PARTIAL_START = START.substring(0, START.length() - 1); - private static final String PARTIAL_END = END.substring(1, END.length()); - private static final String END_OF_START = START.substring(START.length() - 1, START.length()); - private static final String START_OF_END = END.substring(0, 1); + private String START = null; + private String END = null; + private String PARTIAL_START = null; + private String PARTIAL_END = null; + private String END_OF_START = null; + private String START_OF_END = null; public TextblockTestCase(String name) { @@ -41,6 +45,25 @@ public class TextblockTestCase extends B //DEBUG = true; } + @Override + protected void setUp() throws Exception + { + super.setUp(); + + // get a valid parser instance to initialize string constants + Field riField = engine.getClass().getDeclaredField("ri"); + riField.setAccessible(true); + RuntimeInstance ri = (RuntimeInstance)riField.get(engine); + Parser parser = ri.createNewParser(); + ASTTextblock astTextblock = new ASTTextblock(parser, 0); + START = astTextblock.START; + END = astTextblock.END; + PARTIAL_START = START.substring(0, START.length() - 1); + PARTIAL_END = END.substring(1); + END_OF_START = START.substring(START.length() - 1); + START_OF_END = END.substring(0, 1); + } + public String textblock(String s) { return START + s + END;