This class is responsible for handling the pluggable directives in VTL. ex. #foreach() Please look at the Parser.jjt file which is what controls the generation of this class.
Inheritance: NVelocity.Runtime.Parser.Node.SimpleNode
Beispiel #1
0
		public virtual Object Visit(ASTDirective node, Object data)
		{
			data = node.ChildrenAccept(this, data);
			return data;
		}
Beispiel #2
0
		public override Object Visit(ASTDirective node, Object data)
		{
			return ShowNode(node, data);
		}
	public virtual System.Object visit(ASTDirective node, System.Object data) {
	    data = node.childrenAccept(this, data);
	    return data;
	}
Beispiel #4
0
	/// <summary>   Supports the Pluggable Directives
	/// #foo( arg+ )
	/// </summary>
	public SimpleNode Directive() {
	    /*@bgen(jjtree) Directive */
	    ASTDirective jjtn000 = new ASTDirective(this, ParserTreeConstants.JJTDIRECTIVE);
	    bool jjtc000 = true;
	    jjtree.openNodeScope(jjtn000);
	    Token t = null;
	    Directive.Directive d;
	    int directiveType;
	    bool doItNow = false;
	    //UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to ' ' which has different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1100"'
	    try {
		/*
		* note that if we were escaped, that is now handled by 
		* EscapedDirective()
		*/
		t = jj_consume_token(ParserConstants.WORD);
		System.String directiveName = t.image.Substring(1);

		d = (Directive.Directive) directives[directiveName];

		/*
		*  Velocimacro support : if the directive is macro directive
		*   then set the flag so after the block parsing, we add the VM
		*   right then. (So available if used w/in the current template )
		*/

		if (directiveName.Equals("macro")) {
		    doItNow = true;
		}

		/*
		* set the directive name from here.  No reason for the thing to know 
		* about parser tokens
		*/

		jjtn000.DirectiveName = directiveName;

		if (d == null) {
		    /*
		    *  if null, then not a real directive, but maybe a Velocimacro
		    */

		    //d  =  (Directive) rsvc.getVelocimacro( directiveName, currentTemplateName );

		    // TODO: adding a null check since RuntimeServices is not finished
		    // since the parser can be created without RuntimeServices - this may actually be needed here and in the orgiginal source as well.
		    if (rsvc != null) {
			if (!rsvc.isVelocimacro(directiveName, currentTemplateName)) {
			    token_source.stateStackPop();
			    token_source.inDirective = false;
			    if (true)
				return jjtn000;
			}
		    }

		    /*
		    *  Currently, all VMs are LINE directives
		    */
		    directiveType = NVelocity.Runtime.Directive.DirectiveConstants_Fields.LINE;
		} else {
		    directiveType = d.Type;
		}

		/*
				*  now, switch us out of PRE_DIRECTIVE
				*/

		token_source.SwitchTo(ParserConstants.DIRECTIVE);
		switch ((jj_ntk_Renamed_Field == - 1)?jj_ntk():jj_ntk_Renamed_Field) {
		    case ParserConstants.WHITESPACE:
			jj_consume_token(ParserConstants.WHITESPACE);
			break;

		    default:
			jj_la1[6] = jj_gen;
			;
			break;

		}
		jj_consume_token(ParserConstants.LPAREN);
		while (true) {
		    switch ((jj_ntk_Renamed_Field == - 1)?jj_ntk():jj_ntk_Renamed_Field) {
case ParserConstants.LBRACKET: case ParserConstants.WHITESPACE: case ParserConstants.STRING_LITERAL: case ParserConstants.TRUE: case ParserConstants.FALSE: case ParserConstants.NUMBER_LITERAL: case ParserConstants.WORD: case ParserConstants.IDENTIFIER: case ParserConstants.LCURLY:
			    ;
			    break;

			default:
			    jj_la1[7] = jj_gen;
			    //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1012"'
			    goto label_3_brk;

		    }
		    DirectiveArg();
		}
		//UPGRADE_NOTE: Label 'label_3_brk' was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1011"'
label_3_brk:
		;

		jj_consume_token(ParserConstants.RPAREN);
		if (directiveType == NVelocity.Runtime.Directive.DirectiveConstants_Fields.LINE) {
		    if (true)
			return jjtn000;
		}
		ASTBlock jjtn001 = new ASTBlock(this, ParserTreeConstants.JJTBLOCK);
		bool jjtc001 = true;
		jjtree.openNodeScope(jjtn001);
		//UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to ' ' which has different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1100"'
		try {
		    while (true) {
			Statement();
			switch ((jj_ntk_Renamed_Field == - 1)?jj_ntk():jj_ntk_Renamed_Field) {
case ParserConstants.LPAREN: case ParserConstants.RPAREN: case ParserConstants.ESCAPE_DIRECTIVE: case ParserConstants.SET_DIRECTIVE: case ParserConstants.DOUBLE_ESCAPE: case ParserConstants.ESCAPE: case ParserConstants.TEXT: case ParserConstants.SINGLE_LINE_COMMENT: case ParserConstants.FORMAL_COMMENT: case ParserConstants.MULTI_LINE_COMMENT: case ParserConstants.STRING_LITERAL: case ParserConstants.IF_DIRECTIVE: case ParserConstants.STOP_DIRECTIVE: case ParserConstants.NUMBER_LITERAL: case ParserConstants.WORD: case ParserConstants.IDENTIFIER: case ParserConstants.DOT: case ParserConstants.LCURLY: case ParserConstants.RCURLY:
				;
				break;

			    default:
				jj_la1[8] = jj_gen;
				//UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1012"'
				goto label_4_brk;

			}
		    }
		    //UPGRADE_NOTE: Label 'label_4_brk' was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1011"'
label_4_brk:
		    ;

		} catch (System.Exception jjte001) {
		    if (jjtc001) {
			jjtree.clearNodeScope(jjtn001);
			jjtc001 = false;
		    } else {
			jjtree.popNode();
		    }
		    if (jjte001 is System.SystemException) { {
			    if (true)
				throw (System.SystemException) jjte001;
			}
		    }
		    if (jjte001 is ParseException) { {
			    if (true)
				throw (ParseException) jjte001;
			}
		    } {
			if (true)
			    throw (System.ApplicationException) jjte001;
		    }
		} finally {
		    if (jjtc001) {
			jjtree.closeNodeScope(jjtn001, true);
		    }
		}
		jj_consume_token(ParserConstants.END);
		jjtree.closeNodeScope(jjtn000, true);
		jjtc000 = false;
		/*
		*  VM : if we are processing a #macro directive, we need to 
		*     process the block.  In truth, I can just register the name
		*     and do the work later when init-ing.  That would work
		*     as long as things were always defined before use.  This way
		*     we don't have to worry about forward references and such...
		*/

		if (doItNow) {
		    Macro.processAndRegister(rsvc, jjtn000, currentTemplateName);
		} {

		    /*
		    *  VM : end
		    */

		    if (true)
			return jjtn000;
		}
	    } catch (System.Exception jjte000) {
		if (jjtc000) {
		    jjtree.clearNodeScope(jjtn000);
		    jjtc000 = false;
		} else {
		    jjtree.popNode();
		}
		if (jjte000 is System.SystemException) { {
			if (true)
			    throw (System.SystemException) jjte000;
		    }
		}
		if (jjte000 is ParseException) { {
			if (true)
			    throw (ParseException) jjte000;
		    }
		} {
		    if (true)
			throw (System.ApplicationException) jjte000;
		}
	    } finally {
		if (jjtc000) {
		    jjtree.closeNodeScope(jjtn000, true);
		}
	    }
	    throw new System.ApplicationException("Missing return statement in function");
	}
Beispiel #5
0
 public override System.Object visit(ASTDirective node, System.Object data)
 {
     return showNode(node, data);
 }