Author: byron
Date: Sun Feb 15 12:19:21 2009
New Revision: 744662
URL: http://svn.apache.org/viewvc?rev=744662&view=rev
Log:
Improve directive parse error reporting and make it more verbose. Also make
directive parse errors more IDE friendly
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Break.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Directive.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Macro.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java
velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt
velocity/engine/branches/2.0_Exp/test/macroforwarddefine/macros.vm
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Break.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Break.java?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Break.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Break.java
Sun Feb 15 12:19:21 2009
@@ -21,24 +21,18 @@
import java.io.IOException;
import java.io.Writer;
-import java.util.Iterator;
-import java.util.List;
+import java.util.ArrayList;
-import org.apache.velocity.app.event.EventCartridge;
-import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.TemplateInitException;
-import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
-import org.apache.velocity.runtime.parser.node.ASTReference;
+import org.apache.velocity.runtime.parser.ParseException;
+import org.apache.velocity.runtime.parser.ParserTreeConstants;
+import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
-import org.apache.velocity.runtime.parser.node.SimpleNode;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.util.introspection.Info;
-import org.apache.velocity.util.introspection.IntrospectionCacheData;
/**
* Break directive used for interrupting foreach loops.
@@ -116,4 +110,18 @@
super("Break");
}
}
+
+ /**
+ * Called by the parser to validate the argument types
+ */
+ public void checkArgs(ArrayList<Integer> argtypes, Token t, String
templateName)
+ throws ParseException
+ {
+ if (argtypes.size() != 0)
+ {
+ throw new MacroParseException("The #break directive does not take
any arguments",
+ templateName, t);
+ }
+ }
+
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java
Sun Feb 15 12:19:21 2009
@@ -20,10 +20,15 @@
*/
import java.io.Writer;
+import java.util.ArrayList;
+
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.ParserTreeConstants;
+import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
/**
@@ -80,4 +85,22 @@
return true;
}
+ /**
+ * Called by the parser to validate the argument types
+ */
+ public void checkArgs(ArrayList<Integer> argtypes, Token t, String
templateName)
+ throws ParseException
+ {
+ if (argtypes.size() != 1)
+ {
+ throw new MacroParseException("The #define directive requires one
argument",
+ templateName, t);
+ }
+
+ if (argtypes.get(0) == ParserTreeConstants.JJTWORD)
+ {
+ throw new MacroParseException("The argument to #define is of the
wrong type",
+ templateName, t);
+ }
+ }
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Directive.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Directive.java?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Directive.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Directive.java
Sun Feb 15 12:19:21 2009
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.Writer;
+import java.util.ArrayList;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
@@ -29,7 +30,6 @@
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.ParseException;
-import org.apache.velocity.runtime.parser.ParserTreeConstants;
import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
@@ -134,21 +134,17 @@
/**
* The Parser calls this method during template parsing to check the
arguments
* types. Be aware that this method is called pre init, so not all data
- * is available in this method. The default implemenation is to throw a
- * parse exception if there is a word argument in any of the argument
positions.
- * @param argType type, for example ParserTreeConstants.JJTWORD.
- * @param argPos argument position, starting with 0
+ * is available in this method. The default implementation does not
peform any
+ * checking. We do this so that Custom directives do not trigger any
parse
+ * errors in IDEs.
+ * @param argtypes type, Array of argument types of each argument to the
directive
+ * for example ParserTreeConstants.JJTWORD
* @param t, token of directive
* @param templateName, the name of the template this directive is
referenced in.
*/
- public void checkArg(int argType, int argPos, Token t, String templateName)
- throws ParseException
+ public void checkArgs(ArrayList<Integer> argtypes, Token t, String
templateName)
+ throws ParseException
{
- if (argType == ParserTreeConstants.JJTWORD)
- {
- throw new MacroParseException("Invalid arg #"
- + argPos + " in directive " + t.image, templateName, t);
- }
}
/**
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java
Sun Feb 15 12:19:21 2009
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.Writer;
+import java.util.ArrayList;
import java.util.Iterator;
import org.apache.velocity.context.InternalContextAdapter;
@@ -330,13 +331,29 @@
* We do not allow a word token in any other arg position except for the
2nd since
* we are looking for the pattern #foreach($foo in $bar).
*/
- public void checkArg(int argType, int argPos, Token t, String templateName)
+ public void checkArgs(ArrayList<Integer> argtypes, Token t, String
templateName)
throws ParseException
{
- if (argType == ParserTreeConstants.JJTWORD && argPos != 1)
+ if (argtypes.size() < 3)
{
- throw new MacroParseException("Invalid arg #"
- + argPos + " in directive " + t.image, templateName, t);
+ throw new MacroParseException("Too few arguments to the #foreach
directive",
+ templateName, t);
+ }
+ else if (argtypes.get(0) == ParserTreeConstants.JJTWORD)
+ {
+ throw new MacroParseException("Argument 1 of #foreach is of the
wrong type",
+ templateName, t);
+ }
+
+ else if (argtypes.get(1) != ParserTreeConstants.JJTWORD)
+ {
+ throw new MacroParseException("Expected word 'in' at argument
position 2 in #foreach",
+ templateName, t);
+ }
+ else if (argtypes.get(2) == ParserTreeConstants.JJTWORD)
+ {
+ throw new MacroParseException("Argument 3 of #foreach is of the
wrong type",
+ templateName, t);
}
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Macro.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Macro.java?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Macro.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Macro.java
Sun Feb 15 12:19:21 2009
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.Writer;
+import java.util.ArrayList;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
@@ -107,48 +108,36 @@
}
/**
- * Used by Parser.java to do further parameter checking for macro
arguments.
+ * Check the argument types of a macro call, called by the parser to do
validation
*/
- public static void checkArgs(RuntimeServices rs, Token t, Node node,
- String sourceTemplate)
- throws IOException, ParseException
- {
- /*
- * There must be at least one arg to #macro,
- * the name of the VM. Note that 0 following
- * args is ok for naming blocks of HTML
- */
- int numArgs = node.jjtGetNumChildren();
-
- /*
- * this number is the # of args + 1. The + 1
- * is for the block tree
- */
- if (numArgs < 2)
+ public void checkArgs(ArrayList<Integer> argtypes, Token t, String
templateName)
+ throws ParseException
+ {
+ if (argtypes.size() < 1)
{
-
- /*
- * error - they didn't name the macro or
- * define a block
- */
- rs.getLog().error("#macro error : Velocimacro must have name as
1st " +
- "argument to #macro(). #args = " + numArgs);
-
- throw new MacroParseException("First argument to #macro() must be
" +
- " macro name", sourceTemplate, t);
+ throw new MacroParseException("A macro definition requires at
least a macro name"
+ , templateName, t);
}
/*
* lets make sure that the first arg is an ASTWord
*/
- int firstType = node.jjtGetChild(0).getType();
- if(firstType != ParserTreeConstants.JJTWORD)
+ if(argtypes.get(0) != ParserTreeConstants.JJTWORD)
{
- throw new MacroParseException("First argument to #macro() must be
a"
- + " token without surrounding \' or \", which specifies"
- + " the macro name. Currently it is a "
- + ParserTreeConstants.jjtNodeName[firstType],
sourceTemplate, t);
- }
+ throw new MacroParseException("Macro argument 1"
+ + " must be a token without surrounding \' or \""
+ , templateName, t);
+ }
+
+ // All arguments other then the first must be a reference
+ for (int argPos = 1; argPos < argtypes.size(); argPos++)
+ {
+ if (argtypes.get(argPos) != ParserTreeConstants.JJTREFERENCE)
+ {
+ throw new MacroParseException("Macro argument " + (argPos + 1)
+ + " must be a reference", templateName, t);
+ }
+ }
}
/**
@@ -235,21 +224,6 @@
}
ret.append(" )");
return ret;
- }
-
- /**
- * We expect the pattern #macro(foo $bar1 ...) so words are not allowed
- * in the other argument positions.
- */
- public void checkArg(int argType, int argPos, Token t, String templateName)
- throws ParseException
- {
- if (argType == ParserTreeConstants.JJTWORD && argPos > 0)
- {
- throw new MacroParseException("Invalid first arg"
- + " in #macro() directive - must be a"
- + " word token (no \' or \" surrounding)", templateName, t);
- }
- }
+ }
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
Sun Feb 15 12:19:21 2009
@@ -21,8 +21,8 @@
import java.io.IOException;
import java.io.Writer;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
import org.apache.velocity.Template;
import org.apache.velocity.app.event.EventHandlerUtil;
@@ -31,11 +31,14 @@
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.exception.TemplateInitException;
+import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.log.Log;
+import org.apache.velocity.runtime.parser.ParseException;
+import org.apache.velocity.runtime.parser.ParserTreeConstants;
+import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.node.SimpleNode;
@@ -133,15 +136,6 @@
MethodInvocationException
{
/*
- * did we get an argument?
- */
- if ( node.jjtGetChild(0) == null)
- {
- rsvc.getLog().error("#parse() null argument");
- return false;
- }
-
- /*
* does it have a value? If you have a null reference, then no.
*/
Object value = node.jjtGetChild(0).value( context );
@@ -311,6 +305,24 @@
return true;
}
-
+
+ /**
+ * Called by the parser to validate the argument types
+ */
+ public void checkArgs(ArrayList<Integer> argtypes, Token t, String
templateName)
+ throws ParseException
+ {
+ if (argtypes.size() != 1)
+ {
+ throw new MacroParseException("The #parse directive requires one
argument",
+ templateName, t);
+ }
+
+ if (argtypes.get(0) == ParserTreeConstants.JJTWORD)
+ {
+ throw new MacroParseException("The argument to #parse is of the
wrong type",
+ templateName, t);
+ }
+ }
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java
Sun Feb 15 12:19:21 2009
@@ -724,6 +724,7 @@
int directiveType;
boolean isVM = false;
boolean isMacro = false;
+ ArrayList argtypes = new ArrayList(4);
try {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case WORD:
@@ -779,12 +780,8 @@
/*
* if null, then not a real directive, but maybe a Velocimacro
*/
-
isVM = rsvc.isVelocimacro(directiveName, currentTemplateName);
- /*
- * Currently, all VMs are LINE directives
- */
directiveType = Directive.LINE;
}
}
@@ -842,18 +839,13 @@
;
}
argType = DirectiveArg();
- if (d != null)
- {
- // If a directive then call the directive check args method
- d.checkArg(argType, argPos, t, currentTemplateName);
-
- }
- else if (argType == ParserTreeConstants.JJTWORD)
+ argtypes.add(argType);
+ if (d == null && argType == ParserTreeConstants.JJTWORD)
{
if (isVM)
{
- {if (true) throw new MacroParseException("Invalid arg
#"
- + argPos + " in VM " + t.image, currentTemplateName,
t);}
+ {if (true) throw new MacroParseException("Invalid
argument "
+ + (argPos+1) + " in macro call " + t.image,
currentTemplateName, t);}
}
}
@@ -868,28 +860,19 @@
;
}
jj_consume_token(RPAREN);
- if (directiveType == Directive.LINE)
- {
- {if (true) return jjtn000;}
- }
} else {
- if (isMacro) // isMacro is true if the directive is "macro"
- {
- // VELOCITY-667 We get here if we have a "#macro" construct
- // without parenthesis which is a parse error
- {if (true) throw new MacroParseException("A macro declaration
requires at least a name argument"
- , currentTemplateName, t);}
- }
-
token_source.stateStackPop();
token_source.inDirective = false;
+ }
+ if (d != null)
+ {
+ d.checkArgs(argtypes, t, currentTemplateName);
+ }
- if (directiveType != Directive.BLOCK)
+ if (directiveType == Directive.LINE)
{
- // not a directive
{if (true) return jjtn000;}
}
- }
ASTBlock jjtn001 = new ASTBlock(this, JJTBLOCK);
boolean jjtc001 = true;
jjtree.openNodeScope(jjtn001);
@@ -962,15 +945,17 @@
if (isMacro)
{
- // Further checking of macro arguments
- Macro.checkArgs(rsvc, t, jjtn000, currentTemplateName);
-
// Add the macro name so that we can peform escape processing
// on defined macros
String macroName = jjtn000.jjtGetChild(0).getFirstToken().image;
macroNames.put(macroName, macroName);
}
+ if (d != null)
+ {
+ d.checkArgs(argtypes, t, currentTemplateName);
+ }
+
/*
* VM : end
*/
@@ -2911,6 +2896,74 @@
finally { jj_save(11, xla); }
}
+ final private boolean jj_3R_29() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_scan_token(33)) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_51()) {
+ jj_scanpos = xsp;
+ if (jj_3R_52()) {
+ jj_scanpos = xsp;
+ if (jj_3R_53()) {
+ jj_scanpos = xsp;
+ if (jj_3R_54()) {
+ jj_scanpos = xsp;
+ if (jj_3R_55()) {
+ jj_scanpos = xsp;
+ if (jj_3R_56()) {
+ jj_scanpos = xsp;
+ if (jj_3R_57()) {
+ jj_scanpos = xsp;
+ if (jj_3R_58()) {
+ jj_scanpos = xsp;
+ if (jj_3R_59()) return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ xsp = jj_scanpos;
+ if (jj_scan_token(33)) jj_scanpos = xsp;
+ return false;
+ }
+
+ final private boolean jj_3R_100() {
+ if (jj_scan_token(COMMA)) return true;
+ if (jj_3R_29()) return true;
+ if (jj_scan_token(COLON)) return true;
+ if (jj_3R_29()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_96() {
+ if (jj_3R_24()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_26() {
+ if (jj_3R_40()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_95() {
+ if (jj_3R_71()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_94() {
+ if (jj_3R_70()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_93() {
+ if (jj_3R_40()) return true;
+ return false;
+ }
+
final private boolean jj_3R_92() {
if (jj_3R_65()) return true;
return false;
@@ -2955,8 +3008,8 @@
return false;
}
- final private boolean jj_3R_26() {
- if (jj_3R_40()) return true;
+ final private boolean jj_3R_25() {
+ if (jj_3R_24()) return true;
return false;
}
@@ -2980,6 +3033,11 @@
return false;
}
+ final private boolean jj_3_1() {
+ if (jj_3R_24()) return true;
+ return false;
+ }
+
final private boolean jj_3R_66() {
if (jj_scan_token(LBRACKET)) return true;
Token xsp;
@@ -3006,8 +3064,8 @@
return false;
}
- final private boolean jj_3R_25() {
- if (jj_3R_24()) return true;
+ final private boolean jj_3R_50() {
+ if (jj_3R_71()) return true;
return false;
}
@@ -3020,8 +3078,29 @@
return false;
}
- final private boolean jj_3_1() {
- if (jj_3R_24()) return true;
+ final private boolean jj_3R_49() {
+ if (jj_3R_70()) return true;
+ return false;
+ }
+
+ final private boolean jj_3_3() {
+ if (jj_scan_token(LBRACKET)) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_scan_token(33)) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_25()) {
+ jj_scanpos = xsp;
+ if (jj_3R_26()) return true;
+ }
+ xsp = jj_scanpos;
+ if (jj_scan_token(33)) jj_scanpos = xsp;
+ if (jj_scan_token(DOUBLEDOT)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_48() {
+ if (jj_3R_69()) return true;
return false;
}
@@ -3044,6 +3123,11 @@
return false;
}
+ final private boolean jj_3R_47() {
+ if (jj_3R_68()) return true;
+ return false;
+ }
+
final private boolean jj_3R_37() {
if (jj_3R_40()) return true;
return false;
@@ -3065,47 +3149,6 @@
return false;
}
- final private boolean jj_3R_50() {
- if (jj_3R_71()) return true;
- return false;
- }
-
- final private boolean jj_3R_49() {
- if (jj_3R_70()) return true;
- return false;
- }
-
- final private boolean jj_3_3() {
- if (jj_scan_token(LBRACKET)) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_scan_token(33)) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_25()) {
- jj_scanpos = xsp;
- if (jj_3R_26()) return true;
- }
- xsp = jj_scanpos;
- if (jj_scan_token(33)) jj_scanpos = xsp;
- if (jj_scan_token(DOUBLEDOT)) return true;
- return false;
- }
-
- final private boolean jj_3R_48() {
- if (jj_3R_69()) return true;
- return false;
- }
-
- final private boolean jj_3R_36() {
- if (jj_3R_24()) return true;
- return false;
- }
-
- final private boolean jj_3R_47() {
- if (jj_3R_68()) return true;
- return false;
- }
-
final private boolean jj_3R_46() {
if (jj_3R_67()) return true;
return false;
@@ -3116,18 +3159,13 @@
return false;
}
- final private boolean jj_3R_90() {
- if (jj_3R_73()) return true;
- return false;
- }
-
final private boolean jj_3R_44() {
if (jj_3R_40()) return true;
return false;
}
- final private boolean jj_3R_89() {
- if (jj_3R_73()) return true;
+ final private boolean jj_3R_36() {
+ if (jj_3R_24()) return true;
return false;
}
@@ -3149,8 +3187,8 @@
return false;
}
- final private boolean jj_3R_34() {
- if (jj_3R_60()) return true;
+ final private boolean jj_3R_90() {
+ if (jj_3R_73()) return true;
return false;
}
@@ -3193,6 +3231,26 @@
return false;
}
+ final private boolean jj_3R_89() {
+ if (jj_3R_73()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_64() {
+ if (jj_scan_token(WORD)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_60() {
+ if (jj_scan_token(IDENTIFIER)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_34() {
+ if (jj_3R_60()) return true;
+ return false;
+ }
+
final private boolean jj_3_12() {
if (jj_scan_token(LBRACKET)) return true;
Token xsp;
@@ -3219,8 +3277,13 @@
return false;
}
- final private boolean jj_3R_64() {
- if (jj_scan_token(WORD)) return true;
+ final private boolean jj_3_4() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_scan_token(33)) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_27()) jj_scanpos = xsp;
+ if (jj_3R_28()) return true;
return false;
}
@@ -3249,8 +3312,8 @@
return false;
}
- final private boolean jj_3R_60() {
- if (jj_scan_token(IDENTIFIER)) return true;
+ final private boolean jj_3R_65() {
+ if (jj_scan_token(STRING_LITERAL)) return true;
return false;
}
@@ -3269,18 +3332,13 @@
return false;
}
- final private boolean jj_3R_79() {
- if (jj_3R_65()) return true;
+ final private boolean jj_3R_40() {
+ if (jj_scan_token(INTEGER_LITERAL)) return true;
return false;
}
- final private boolean jj_3_4() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_scan_token(33)) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_27()) jj_scanpos = xsp;
- if (jj_3R_28()) return true;
+ final private boolean jj_3R_79() {
+ if (jj_3R_65()) return true;
return false;
}
@@ -3320,6 +3378,11 @@
return false;
}
+ final private boolean jj_3R_67() {
+ if (jj_scan_token(FLOATING_POINT_LITERAL)) return true;
+ return false;
+ }
+
final private boolean jj_3_10() {
if (jj_3R_33()) return true;
return false;
@@ -3354,11 +3417,6 @@
return false;
}
- final private boolean jj_3R_65() {
- if (jj_scan_token(STRING_LITERAL)) return true;
- return false;
- }
-
final private boolean jj_3_8() {
if (jj_3R_33()) return true;
return false;
@@ -3369,11 +3427,6 @@
return false;
}
- final private boolean jj_3R_40() {
- if (jj_scan_token(INTEGER_LITERAL)) return true;
- return false;
- }
-
final private boolean jj_3R_97() {
if (jj_scan_token(COMMA)) return true;
if (jj_3R_29()) return true;
@@ -3385,11 +3438,6 @@
return false;
}
- final private boolean jj_3R_67() {
- if (jj_scan_token(FLOATING_POINT_LITERAL)) return true;
- return false;
- }
-
final private boolean jj_3R_63() {
if (jj_3R_73()) return true;
return false;
@@ -3518,6 +3566,11 @@
return false;
}
+ final private boolean jj_3_2() {
+ if (jj_scan_token(DOUBLE_ESCAPE)) return true;
+ return false;
+ }
+
final private boolean jj_3R_59() {
if (jj_3R_67()) return true;
return false;
@@ -3563,74 +3616,6 @@
return false;
}
- final private boolean jj_3_2() {
- if (jj_scan_token(DOUBLE_ESCAPE)) return true;
- return false;
- }
-
- final private boolean jj_3R_29() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_scan_token(33)) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_51()) {
- jj_scanpos = xsp;
- if (jj_3R_52()) {
- jj_scanpos = xsp;
- if (jj_3R_53()) {
- jj_scanpos = xsp;
- if (jj_3R_54()) {
- jj_scanpos = xsp;
- if (jj_3R_55()) {
- jj_scanpos = xsp;
- if (jj_3R_56()) {
- jj_scanpos = xsp;
- if (jj_3R_57()) {
- jj_scanpos = xsp;
- if (jj_3R_58()) {
- jj_scanpos = xsp;
- if (jj_3R_59()) return true;
- }
- }
- }
- }
- }
- }
- }
- }
- xsp = jj_scanpos;
- if (jj_scan_token(33)) jj_scanpos = xsp;
- return false;
- }
-
- final private boolean jj_3R_100() {
- if (jj_scan_token(COMMA)) return true;
- if (jj_3R_29()) return true;
- if (jj_scan_token(COLON)) return true;
- if (jj_3R_29()) return true;
- return false;
- }
-
- final private boolean jj_3R_96() {
- if (jj_3R_24()) return true;
- return false;
- }
-
- final private boolean jj_3R_95() {
- if (jj_3R_71()) return true;
- return false;
- }
-
- final private boolean jj_3R_94() {
- if (jj_3R_70()) return true;
- return false;
- }
-
- final private boolean jj_3R_93() {
- if (jj_3R_40()) return true;
- return false;
- }
-
public ParserTokenManager token_source;
public Token token, jj_nt;
private int jj_ntk;
Modified: velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt (original)
+++ velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt Sun Feb 15 12:19:21
2009
@@ -1517,6 +1517,7 @@
int directiveType;
boolean isVM = false;
boolean isMacro = false;
+ ArrayList argtypes = new ArrayList(4);
}
{
@@ -1599,18 +1600,13 @@
argType = DirectiveArg()
{
- if (d != null)
- {
- // If a directive then call the directive check args method
- d.checkArg(argType, argPos, t, currentTemplateName);
-
- }
- else if (argType == ParserTreeConstants.JJTWORD)
+ argtypes.add(argType);
+ if (d == null && argType == ParserTreeConstants.JJTWORD)
{
if (isVM)
{
- throw new MacroParseException("Invalid arg #"
- + argPos + " in VM " + t.image, currentTemplateName,
t);
+ throw new MacroParseException("Invalid argument "
+ + (argPos+1) + " in macro call " + t.image,
currentTemplateName, t);
}
}
@@ -1618,33 +1614,23 @@
}
)* [<WHITESPACE>] <RPAREN>)
+ |
{
-
- if (directiveType == Directive.LINE)
- {
- return jjtThis;
- }
+ token_source.stateStackPop();
+ token_source.inDirective = false;
}
- |
+ )
{
- if (isMacro) // isMacro is true if the directive is "macro"
+ if (d != null)
{
- // VELOCITY-667 We get here if we have a "#macro" construct
- // without parenthesis which is a parse error
- throw new MacroParseException("A macro declaration requires at
least a name argument"
- , currentTemplateName, t);
+ d.checkArgs(argtypes, t, currentTemplateName);
}
-
- token_source.stateStackPop();
- token_source.inDirective = false;
-
- if (directiveType != Directive.BLOCK)
+
+ if (directiveType == Directive.LINE)
{
- // not a directive
return jjtThis;
}
}
- )
/*
* and the following block if the PD needs it
*/
@@ -1662,15 +1648,17 @@
if (isMacro)
{
- // Further checking of macro arguments
- Macro.checkArgs(rsvc, t, jjtThis, currentTemplateName);
-
// Add the macro name so that we can peform escape processing
// on defined macros
String macroName = jjtThis.jjtGetChild(0).getFirstToken().image;
macroNames.put(macroName, macroName);
}
+ if (d != null)
+ {
+ d.checkArgs(argtypes, t, currentTemplateName);
+ }
+
/*
* VM : end
*/
Modified: velocity/engine/branches/2.0_Exp/test/macroforwarddefine/macros.vm
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/test/macroforwarddefine/macros.vm?rev=744662&r1=744661&r2=744662&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/test/macroforwarddefine/macros.vm
(original)
+++ velocity/engine/branches/2.0_Exp/test/macroforwarddefine/macros.vm Sun Feb
15 12:19:21 2009
@@ -3,7 +3,7 @@
#end
#macro(test1b $p)
- #foreach($i $foo)
+ #foreach($i in $foo)
#test2($p)
#end
#end