Logo Search packages:      
Sourcecode: velocity version File versions  Download package

final SimpleNode org::apache::velocity::runtime::parser::Parser::Directive (  )  throws ParseException [inline]

Supports the Pluggable Directives foo( arg+ )

Definition at line 583 of file Parser.java.

References org::apache::velocity::runtime::parser::Token::beginColumn, org::apache::velocity::runtime::parser::Token::beginLine, currentTemplateName, DirectiveArg(), directives, org::apache::velocity::runtime::directive::Directive::getType(), org::apache::velocity::runtime::parser::Token::image, org::apache::velocity::runtime::RuntimeServices::isVelocimacro(), org::apache::velocity::runtime::parser::node::ASTDirective::setDirectiveName(), and Statement().

Referenced by Statement().

                                                            {
 /*@bgen(jjtree) Directive */
    ASTDirective jjtn000 = new ASTDirective(this, JJTDIRECTIVE);
    boolean jjtc000 = true;
    jjtree.openNodeScope(jjtn000);Token t = null;
    int argType;
    int argPos = 0;
    Directive d;
    int directiveType;
    boolean isVM = false;
    boolean doItNow = false;
    try {
      /*
           * note that if we were escaped, that is now handled by
           * EscapedDirective()
           */
          t = jj_consume_token(WORD);
        String directiveName = t.image.substring(1);

        d = (Directive) directives.get(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.setDirectiveName(directiveName);

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

            isVM = rsvc.isVelocimacro(directiveName, currentTemplateName);

            if (!isVM)
            {
                token_source.stateStackPop();
                token_source.inDirective = false;
                {if (true) return jjtn000;}
            }


            /*
             *  Currently, all VMs are LINE directives
             */

            directiveType = Directive.LINE;
        }
        else
        {
            directiveType = d.getType();
        }

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

        token_source.SwitchTo(DIRECTIVE);

        argPos = 0;
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case WHITESPACE:
        jj_consume_token(WHITESPACE);
        break;
      default:
        jj_la1[6] = jj_gen;
        ;
      }
      jj_consume_token(LPAREN);
      label_3:
      while (true) {
        if (jj_2_4(2)) {
          ;
        } else {
          break label_3;
        }
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case WHITESPACE:
          jj_consume_token(WHITESPACE);
          break;
        default:
          jj_la1[7] = jj_gen;
          ;
        }
        argType = DirectiveArg();
                if (argType == ParserTreeConstants.JJTWORD)
                {
                    if (doItNow && argPos == 0)
                    {
                        /* if a VM and it's the 0th arg... ok */
                        ;
                    }
                    else if( t.image.equals("#foreach") && argPos == 1)
                    {
                        /* if a foreach and it's the 2nd arg ok */
                        ;
                    }
                    else
                    {
                        {if (true) throw new MacroParseException("Invalid arg #"
                            + argPos + " in "
                            + (isVM ? "VM " : "directive " )
                            + t.image
                            + " at line " + t.beginLine + ", column "
                            + t.beginColumn
                            + " in template " + currentTemplateName);}
                    }
                }
                else
                {
                    if (doItNow && argPos == 0)
                    {
                        /* if a VM and it's the 0th arg, not ok */

                        {if (true) throw new MacroParseException("Invalid first arg "
                            + " in #macro() directive - must be a"
                            + " word token (no \' or \" surrounding)"
                            + " at line " + t.beginLine + ", column "
                            + t.beginColumn
                            + " in template " + currentTemplateName);}
                    }
                }

                argPos++;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case WHITESPACE:
        jj_consume_token(WHITESPACE);
        break;
      default:
        jj_la1[8] = jj_gen;
        ;
      }
      jj_consume_token(RPAREN);
        if (directiveType  == Directive.LINE)
        {
            {if (true) return jjtn000;}
        }
      ASTBlock jjtn001 = new ASTBlock(this, JJTBLOCK);
      boolean jjtc001 = true;
      jjtree.openNodeScope(jjtn001);
      try {
        label_4:
        while (true) {
          Statement();
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case LPAREN:
          case RPAREN:
          case ESCAPE_DIRECTIVE:
          case SET_DIRECTIVE:
          case DOUBLE_ESCAPE:
          case ESCAPE:
          case TEXT:
          case SINGLE_LINE_COMMENT:
          case FORMAL_COMMENT:
          case MULTI_LINE_COMMENT:
          case STRING_LITERAL:
          case IF_DIRECTIVE:
          case STOP_DIRECTIVE:
          case NUMBER_LITERAL:
          case WORD:
          case IDENTIFIER:
          case DOT:
          case LCURLY:
          case RCURLY:
            ;
            break;
          default:
            jj_la1[9] = jj_gen;
            break label_4;
          }
        }
      } catch (Throwable jjte001) {
      if (jjtc001) {
        jjtree.clearNodeScope(jjtn001);
        jjtc001 = false;
      } else {
        jjtree.popNode();
      }
      if (jjte001 instanceof RuntimeException) {
        {if (true) throw (RuntimeException)jjte001;}
      }
      if (jjte001 instanceof ParseException) {
        {if (true) throw (ParseException)jjte001;}
      }
      {if (true) throw (Error)jjte001;}
      } finally {
      if (jjtc001) {
        jjtree.closeNodeScope(jjtn001, true);
      }
      }
      jj_consume_token(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 (Throwable jjte000) {
      if (jjtc000) {
        jjtree.clearNodeScope(jjtn000);
        jjtc000 = false;
      } else {
        jjtree.popNode();
      }
      if (jjte000 instanceof RuntimeException) {
        {if (true) throw (RuntimeException)jjte000;}
      }
      if (jjte000 instanceof ParseException) {
        {if (true) throw (ParseException)jjte000;}
      }
      {if (true) throw (Error)jjte000;}
    } finally {
      if (jjtc000) {
        jjtree.closeNodeScope(jjtn000, true);
      }
    }
    throw new Error("Missing return statement in function");
  }


Generated by  Doxygen 1.6.0   Back to index