/// <summary> Supports the Pluggable Directives /// #foo( arg+ ) /// </summary> public SimpleNode Directive() { ASTDirective directiveNode = new ASTDirective(this, ParserTreeConstants.DIRECTIVE); bool isNodeScopeOpen = true; nodeTree.OpenNodeScope(directiveNode); Token token; Directive.Directive directive; bool doItNow = false; try { /* * note that if we were escaped, that is now handled by * EscapedDirective() */ token = ConsumeToken(ParserConstants.WORD); String directiveName = token.Image.Substring(1); directive = directives.Create(directiveName, directiveStack); Debug.Assert(directiveNode != null); directiveNode.Directive = directive; /* * 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 */ directiveNode.DirectiveName = directiveName; DirectiveType directiveType; if (directive == null) { // if null, then not a real directive, but maybe a Velocimacro //d = (Directive) runtimeServices.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 (runtimeServices != null) { if (!runtimeServices.IsVelocimacro(directiveName, currentTemplateName)) { token_source.StateStackPop(); token_source.inDirective = false; if (true) return directiveNode; } } /* * Currently, all VMs are LINE directives */ directiveType = DirectiveType.LINE; } else { directiveType = directive.Type; } /* * now, switch us out of PRE_DIRECTIVE */ token_source.SwitchTo(ParserConstants.DIRECTIVE); ConsumeWhiteSpaces(); if (directive != null && !directive.AcceptParams) { int curToken = GetCurrentTokenKind(); if (curToken == ParserConstants.NEWLINE) { ConsumeToken(ParserConstants.NEWLINE); } else { throw new ParseException( "Foreach directives must be the only items on the line (comments or contents are not allowed)"); } } if (directive == null || directive.AcceptParams) { ConsumeToken(ParserConstants.LPAREN); while(true) { switch(GetCurrentTokenKind()) { 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: ; ConsumeToken(ParserConstants.RPAREN); } if (directiveType == DirectiveType.LINE) { return directiveNode; } directiveStack.Push(directive); ASTBlock jjtn001 = new ASTBlock(this, ParserTreeConstants.BLOCK); bool jjtc001 = true; nodeTree.OpenNodeScope(jjtn001); try { while(true) { Statement(); int kind = GetCurrentTokenKind(); switch(kind) { 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) { nodeTree.ClearNodeScope(jjtn001); jjtc001 = false; if (jjte001 is SystemException) { throw; } if (jjte001 is ParseException) { throw; } throw (ApplicationException) jjte001; } finally { if (jjtc001) { nodeTree.CloseNodeScope(jjtn001, true); } directiveStack.Pop(); } ConsumeToken(ParserConstants.END); nodeTree.CloseNodeScope(directiveNode, true); isNodeScopeOpen = 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(runtimeServices, directiveNode, currentTemplateName); } return directiveNode; } catch(System.Exception jjte000) { if (isNodeScopeOpen) { nodeTree.ClearNodeScope(directiveNode); isNodeScopeOpen = false; } else { nodeTree.PopNode(); } if (jjte000 is SystemException) { throw; } if (jjte000 is ParseException) { throw; } throw (ApplicationException) jjte000; } finally { if (isNodeScopeOpen) { nodeTree.CloseNodeScope(directiveNode, true); } } }
public virtual Object Visit(ASTBlock node, Object data) { data = node.ChildrenAccept(this, data); return data; }
public void ElseIfStatement() { /*@bgen(jjtree) ElseIfStatement */ ASTElseIfStatement jjtn000 = new ASTElseIfStatement(this, ParserTreeConstants.ELSE_IF_STATEMENT); bool jjtc000 = true; nodeTree.OpenNodeScope(jjtn000); //UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to ' ' which has different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1100"' try { ConsumeToken(ParserConstants.ELSEIF_DIRECTIVE); switch(GetCurrentTokenKind()) { case ParserConstants.WHITESPACE: ConsumeToken(ParserConstants.WHITESPACE); break; default: jj_la1[33] = jj_gen; break; } ConsumeToken(ParserConstants.LPAREN); Expression(); ConsumeToken(ParserConstants.RPAREN); ASTBlock jjtn001 = new ASTBlock(this, ParserTreeConstants.BLOCK); bool jjtc001 = true; nodeTree.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(GetCurrentTokenKind()) { 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[34] = 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_12_brk; } } //UPGRADE_NOTE: Label 'label_12_brk' was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1011"' label_12_brk: ; } catch(System.Exception exception) { nodeTree.ClearNodeScope(jjtn001); jjtc001 = false; if (exception is SystemException) { throw; } if (exception is ParseException) { throw; } throw (ApplicationException) exception; } finally { if (jjtc001) { nodeTree.CloseNodeScope(jjtn001, true); } } } catch(System.Exception exception) { nodeTree.ClearNodeScope(jjtn000); jjtc000 = false; if (exception is SystemException) { throw; } if (exception is ParseException) { throw; } throw (ApplicationException) exception; } finally { if (jjtc000) { nodeTree.CloseNodeScope(jjtn000, true); } } }
/// <summary>Display an ASTBlock node /// </summary> public override Object Visit(ASTBlock node, Object data) { return ShowNode(node, data); }