[engine][VELOCITY-925] Fix BC whitespace gobbling for macro call without parentheses

git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1873088 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/velocity-engine-core/src/main/parser/Parser.jjt b/velocity-engine-core/src/main/parser/Parser.jjt
index 4051786..df5748d 100644
--- a/velocity-engine-core/src/main/parser/Parser.jjt
+++ b/velocity-engine-core/src/main/parser/Parser.jjt
@@ -1781,6 +1781,7 @@
     ArrayList argtypes = new ArrayList(4);
     String blockPrefix = "";
     ASTBlock block = null, elseBlock = null;
+    boolean hasParentheses = false;
     boolean newlineAtStart = afterNewline;
 }
 {
@@ -1908,6 +1909,7 @@
             <SINGLE_LINE_COMMENT_START> [<SINGLE_LINE_COMMENT>]
           )
         )* (<WHITESPACE> | <NEWLINE>)* <RPAREN>
+        { hasParentheses = true; }
       )
       |
       {
@@ -1918,10 +1920,10 @@
     [
       // Conditions where whitespace and newline postfix is eaten by space gobbling at this point:
       // - block directive
-      // - new line before directive
-      // - backward compatibility mode
+      // - new line before directive without backward compatibility mode
+      // - backward compatibility mode *with parentheses*
       // - #include() or #parse()
-      LOOKAHEAD(2, { directiveType != Directive.LINE || newlineAtStart || rsvc.getSpaceGobbling() == SpaceGobbling.BC || d != null && (d instanceof Include || d instanceof Parse) })
+      LOOKAHEAD(2, { directiveType != Directive.LINE || newlineAtStart && rsvc.getSpaceGobbling() != SpaceGobbling.BC || rsvc.getSpaceGobbling() == SpaceGobbling.BC && hasParentheses || d != null && (d instanceof Include || d instanceof Parse) })
         ( [ ( t = <WHITESPACE> ) ] ( u = <NEWLINE> ) )
       {
           afterNewline = true;
diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.BC b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.BC
new file mode 100644
index 0000000..b9dd4b8
--- /dev/null
+++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.BC
@@ -0,0 +1,6 @@
+-----
+value
+-----
+
+-----
+value-----
diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.LINES b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.LINES
new file mode 100644
index 0000000..856047a
--- /dev/null
+++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.LINES
@@ -0,0 +1,5 @@
+-----
+value-----
+
+-----
+value-----
diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.NONE b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.NONE
new file mode 100644
index 0000000..e66cde7
--- /dev/null
+++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.NONE
@@ -0,0 +1,8 @@
+
+-----
+value
+-----
+
+-----
+value
+-----
diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.STRUCTURED b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.STRUCTURED
new file mode 100644
index 0000000..856047a
--- /dev/null
+++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.STRUCTURED
@@ -0,0 +1,5 @@
+-----
+value-----
+
+-----
+value-----
diff --git a/velocity-engine-core/src/test/resources/gobbling/macro2.vtl b/velocity-engine-core/src/test/resources/gobbling/macro2.vtl
new file mode 100644
index 0000000..3d9f7da
--- /dev/null
+++ b/velocity-engine-core/src/test/resources/gobbling/macro2.vtl
@@ -0,0 +1,8 @@
+#macro(test)value#end
+-----
+#test
+-----
+
+-----
+#test()
+-----