jvanzyl     00/11/30 00:15:53

  Modified:    src/java/org/apache/velocity/runtime/parser Parser.java
                        Parser.jj ParserTokenManager.java
  Log:
  - the rest of the parser goodies.
  
  Revision  Changes    Path
  1.36      +237 -242  
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- Parser.java       2000/11/26 18:11:38     1.35
  +++ Parser.java       2000/11/30 08:15:50     1.36
  @@ -21,7 +21,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: Parser.java,v 1.35 2000/11/26 18:11:38 geirm Exp $ 
  + * @version $Id: Parser.java,v 1.36 2000/11/30 08:15:50 jvanzyl Exp $ 
   */
   public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants, ParserConstants 
{/*@bgen(jjtree)*/
     protected JJTParserState jjtree = new JJTParserState();/**
  @@ -29,33 +29,26 @@
        */
       private Hashtable directives = new Hashtable(0);
   
  -    /** This was added to allow the parser to be associated
  -     * with a particular syntax. JavaCC doesn't generate
  -     * a constructor without parameters. The normal constructor
  -     * takes a single argument which an InputStream. But in
  -     * order to make the parser dynamically loadable this
  -     * constructor had to be added. This also allows us to
  -     * create a single instance of a parser and reuse
  -     * it over and over.
  +    /** 
  +     * This constructor was added to allow the re-use of parsers.
  +     * The normal constructor takes a single argument which 
  +     * an InputStream. This simply creates a re-usable parser
  +     * object, we satisfy the requirement of an InputStream
  +     * by using a newline character as an input stream.
        */
       public Parser()
       {
           this(new ByteArrayInputStream("\n".getBytes()));
       }
   
  -    /** This was also added to allow parsers to be dynamically
  -     * loadable.
  -     * 
  -     * Taken from the generated constructor in Parser.java.
  -     * Just be watchful when you change the grammar because
  -     * the generated method changes when the grammar changes
  -     * WRT to adding new token types. So you have to
  -     * occasionally do some cutting and pasting :-)
  -     *
  -     * It would be A LOT better it you could subclass grammars
  -     * and override particular methods but that's not
  -     * possible with JavaCC. I believe that you can do
  -     * this with ANTLR though.
  +    /** 
  +     * This was also added to allow parsers to be
  +     * re-usable. Normal JavaCC use entails passing an
  +     * input stream to the constructor and the parsing
  +     * process is carried out once. We want to be able
  +     * to re-use parsers: we do this by adding this
  +     * method and re-initializing the lexer with
  +     * the new stream that we want parsed.
        */
       public SimpleNode parse(InputStream stream) throws ParseException
       {
  @@ -108,7 +101,8 @@
   
   
       /**
  -     *  Produces a processed output for an escaped control or pluggable directive
  +     * Produces a processed output for an escaped control or 
  +     * pluggable directive
        */
       private String escapedDirective( String strImage )
       {
  @@ -306,7 +300,7 @@
   
   /**
    *  Used to catch and process escape sequences in grammatical constructs
  - *  as escapes outside of VTL are just characters.  Right now we hav both
  + *  as escapes outside of VTL are just characters.  Right now we have both
    *  this and the EscapeDirective() construction because in the EscapeDirective()
    *  case, we want to suck in the #<directive> and here we don't.  We just want
    *  the escapes to render correctly
  @@ -507,9 +501,9 @@
       boolean bDoItNow = false;
       try {
         /*
  -           *  note that if we were escaped, that is now handled by 
EscapedDirective()
  +           * note that if we were escaped, that is now handled by 
  +           * EscapedDirective()
              */
  -      
             t = jj_consume_token(WORD);
           String strDirectiveName = t.image.substring(1);
   
  @@ -527,7 +521,8 @@
           }
   
           /*
  -         *  set the directive name from here.  No reason for the thing to know 
about parser tokens
  +         * set the directive name from here.  No reason for the thing to know 
  +         * about parser tokens
            */
   
           jjtn000.setDirectiveName( strDirectiveName );
  @@ -2014,6 +2009,215 @@
       return retval;
     }
   
  +  final private boolean jj_3R_18() {
  +    if (jj_3R_21()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_68() {
  +    if (jj_3R_74()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    Token xsp;
  +    while (true) {
  +      xsp = jj_scanpos;
  +      if (jj_3R_75()) { jj_scanpos = xsp; break; }
  +      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    }
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_77() {
  +    if (jj_scan_token(MINUS)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_68()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_76() {
  +    if (jj_scan_token(PLUS)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_68()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_69() {
  +    Token xsp;
  +    xsp = jj_scanpos;
  +    if (jj_3R_76()) {
  +    jj_scanpos = xsp;
  +    if (jj_3R_77()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_64() {
  +    if (jj_3R_68()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    Token xsp;
  +    while (true) {
  +      xsp = jj_scanpos;
  +      if (jj_3R_69()) { jj_scanpos = xsp; break; }
  +      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    }
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_73() {
  +    if (jj_scan_token(LOGICAL_GE)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_64()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_72() {
  +    if (jj_scan_token(LOGICAL_LE)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_64()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_71() {
  +    if (jj_scan_token(LOGICAL_GT)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_64()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_70() {
  +    if (jj_scan_token(LOGICAL_LT)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_64()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_65() {
  +    Token xsp;
  +    xsp = jj_scanpos;
  +    if (jj_3R_70()) {
  +    jj_scanpos = xsp;
  +    if (jj_3R_71()) {
  +    jj_scanpos = xsp;
  +    if (jj_3R_72()) {
  +    jj_scanpos = xsp;
  +    if (jj_3R_73()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_61() {
  +    if (jj_scan_token(COMMA)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_32()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_21() {
  +    if (jj_scan_token(IDENTIFIER)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_62() {
  +    if (jj_3R_64()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    Token xsp;
  +    while (true) {
  +      xsp = jj_scanpos;
  +      if (jj_3R_65()) { jj_scanpos = xsp; break; }
  +      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    }
  +    return false;
  +  }
  +
  +  final private boolean jj_3_3() {
  +    if (jj_3R_19()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_67() {
  +    if (jj_scan_token(LOGICAL_NOT_EQUALS)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_62()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_66() {
  +    if (jj_scan_token(LOGICAL_EQUALS)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_62()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_63() {
  +    Token xsp;
  +    xsp = jj_scanpos;
  +    if (jj_3R_66()) {
  +    jj_scanpos = xsp;
  +    if (jj_3R_67()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_59() {
  +    if (jj_3R_62()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    Token xsp;
  +    while (true) {
  +      xsp = jj_scanpos;
  +      if (jj_3R_63()) { jj_scanpos = xsp; break; }
  +      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    }
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_22() {
  +    if (jj_3R_32()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    Token xsp;
  +    while (true) {
  +      xsp = jj_scanpos;
  +      if (jj_3R_61()) { jj_scanpos = xsp; break; }
  +      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    }
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_38() {
  +    if (jj_scan_token(FALSE)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_60() {
  +    if (jj_scan_token(LOGICAL_AND)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    if (jj_3R_59()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_33() {
  +    if (jj_scan_token(STRING_LITERAL)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
     final private boolean jj_3R_57() {
       if (jj_3R_59()) return true;
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  @@ -2326,12 +2530,6 @@
       return false;
     }
   
  -  final private boolean jj_3_1() {
  -    if (jj_scan_token(DOUBLE_ESCAPE)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
     final private boolean jj_3R_23() {
       if (jj_scan_token(WHITESPACE)) return true;
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  @@ -2346,6 +2544,12 @@
       return false;
     }
   
  +  final private boolean jj_3_1() {
  +    if (jj_scan_token(DOUBLE_ESCAPE)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
     final private boolean jj_3R_20() {
       Token xsp;
       xsp = jj_scanpos;
  @@ -2430,215 +2634,6 @@
       if (jj_3R_79()) return true;
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
       } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_18() {
  -    if (jj_3R_21()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_68() {
  -    if (jj_3R_74()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    Token xsp;
  -    while (true) {
  -      xsp = jj_scanpos;
  -      if (jj_3R_75()) { jj_scanpos = xsp; break; }
  -      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    }
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_77() {
  -    if (jj_scan_token(MINUS)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_68()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_76() {
  -    if (jj_scan_token(PLUS)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_68()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_69() {
  -    Token xsp;
  -    xsp = jj_scanpos;
  -    if (jj_3R_76()) {
  -    jj_scanpos = xsp;
  -    if (jj_3R_77()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_64() {
  -    if (jj_3R_68()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    Token xsp;
  -    while (true) {
  -      xsp = jj_scanpos;
  -      if (jj_3R_69()) { jj_scanpos = xsp; break; }
  -      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    }
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_73() {
  -    if (jj_scan_token(LOGICAL_GE)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_64()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_72() {
  -    if (jj_scan_token(LOGICAL_LE)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_64()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_71() {
  -    if (jj_scan_token(LOGICAL_GT)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_64()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_70() {
  -    if (jj_scan_token(LOGICAL_LT)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_64()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_65() {
  -    Token xsp;
  -    xsp = jj_scanpos;
  -    if (jj_3R_70()) {
  -    jj_scanpos = xsp;
  -    if (jj_3R_71()) {
  -    jj_scanpos = xsp;
  -    if (jj_3R_72()) {
  -    jj_scanpos = xsp;
  -    if (jj_3R_73()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_61() {
  -    if (jj_scan_token(COMMA)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_32()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_21() {
  -    if (jj_scan_token(IDENTIFIER)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_62() {
  -    if (jj_3R_64()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    Token xsp;
  -    while (true) {
  -      xsp = jj_scanpos;
  -      if (jj_3R_65()) { jj_scanpos = xsp; break; }
  -      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    }
  -    return false;
  -  }
  -
  -  final private boolean jj_3_3() {
  -    if (jj_3R_19()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_67() {
  -    if (jj_scan_token(LOGICAL_NOT_EQUALS)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_62()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_66() {
  -    if (jj_scan_token(LOGICAL_EQUALS)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_62()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_63() {
  -    Token xsp;
  -    xsp = jj_scanpos;
  -    if (jj_3R_66()) {
  -    jj_scanpos = xsp;
  -    if (jj_3R_67()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_59() {
  -    if (jj_3R_62()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    Token xsp;
  -    while (true) {
  -      xsp = jj_scanpos;
  -      if (jj_3R_63()) { jj_scanpos = xsp; break; }
  -      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    }
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_22() {
  -    if (jj_3R_32()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    Token xsp;
  -    while (true) {
  -      xsp = jj_scanpos;
  -      if (jj_3R_61()) { jj_scanpos = xsp; break; }
  -      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    }
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_38() {
  -    if (jj_scan_token(FALSE)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_33() {
  -    if (jj_scan_token(STRING_LITERAL)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_60() {
  -    if (jj_scan_token(LOGICAL_AND)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    if (jj_3R_59()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
       return false;
     }
   
  
  
  
  1.34      +100 -123  
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.jj
  
  Index: Parser.jj
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.jj,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- Parser.jj 2000/11/26 18:11:39     1.33
  +++ Parser.jj 2000/11/30 08:15:50     1.34
  @@ -68,16 +68,6 @@
        */
       STATIC=false;                                                                   
                                                                                       
                                                                                       
                                                                 
       
  -    /**
  -     * This option is used as one of the steps
  -     * required to allow the use of an "#include"
  -     * type behaviour. In this case the directive
  -     * is "#parse". See the TOKEN_MGR_DECLS section
  -     * below for details on how the TokenManager is
  -     * modified to allow this behaviour.
  -     */
  -    COMMON_TOKEN_ACTION=true;
  -    
       DEBUG_PARSER=false;
       DEBUG_TOKEN_MANAGER=false;
   }    
  @@ -106,7 +96,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: Parser.jj,v 1.33 2000/11/26 18:11:39 geirm Exp $ 
  + * @version $Id: Parser.jj,v 1.34 2000/11/30 08:15:50 jvanzyl Exp $ 
   */
   public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants/*@egen*/
   {/*@bgen(jjtree)*/
  @@ -118,33 +108,26 @@
        */
       private Hashtable directives = new Hashtable(0);
     
  -    /** This was added to allow the parser to be associated
  -     * with a particular syntax. JavaCC doesn't generate
  -     * a constructor without parameters. The normal constructor
  -     * takes a single argument which an InputStream. But in
  -     * order to make the parser dynamically loadable this
  -     * constructor had to be added. This also allows us to
  -     * create a single instance of a parser and reuse
  -     * it over and over.
  +    /** 
  +     * This constructor was added to allow the re-use of parsers.
  +     * The normal constructor takes a single argument which 
  +     * an InputStream. This simply creates a re-usable parser
  +     * object, we satisfy the requirement of an InputStream
  +     * by using a newline character as an input stream.
        */
       public Parser()
       {
           this(new ByteArrayInputStream("\n".getBytes()));
       }
   
  -    /** This was also added to allow parsers to be dynamically
  -     * loadable.
  -     * 
  -     * Taken from the generated constructor in Parser.java.
  -     * Just be watchful when you change the grammar because
  -     * the generated method changes when the grammar changes
  -     * WRT to adding new token types. So you have to
  -     * occasionally do some cutting and pasting :-)
  -     *
  -     * It would be A LOT better it you could subclass grammars
  -     * and override particular methods but that's not
  -     * possible with JavaCC. I believe that you can do
  -     * this with ANTLR though.
  +    /** 
  +     * This was also added to allow parsers to be
  +     * re-usable. Normal JavaCC use entails passing an
  +     * input stream to the constructor and the parsing
  +     * process is carried out once. We want to be able
  +     * to re-use parsers: we do this by adding this
  +     * method and re-initializing the lexer with
  +     * the new stream that we want parsed.
        */
       public SimpleNode parse(InputStream stream) throws ParseException
       {
  @@ -197,7 +180,8 @@
   
      
       /**
  -     *  Produces a processed output for an escaped control or pluggable directive
  +     * Produces a processed output for an escaped control or 
  +     * pluggable directive
        */
       private String escapedDirective( String strImage )
       {
  @@ -280,45 +264,6 @@
       private boolean inComment;
       private boolean inSet;
   
  -    Stack streams = new Stack();
  -    Stack states = new Stack();
  -   
  -    /**
  -     * Retrieve the oldStream and oldState and
  -     * continue processing the input.
  -     */
  -    void popFile()
  -    {
  -        ReInit((ASCII_CharStream) streams.pop(), ((Integer) 
states.pop()).intValue());
  -        fileDepth--;
  -    }    
  -    
  -    private boolean AtParent()
  -    {
  -        if (fileDepth == 0)
  -            return true;
  -        else
  -            return false;
  -    }
  -    
  -    void CommonTokenAction(Token t)
  -    {
  -        if (t.kind == EOF && ! AtParent())
  -        {
  -            Token new_t;
  -            popFile();
  -            new_t = getNextToken();
  -            t.kind = new_t.kind;
  -            t.beginLine = new_t.beginLine;
  -            t.beginColumn = new_t.beginColumn;
  -            t.endLine = new_t.endLine;
  -            t.endColumn = new_t.endColumn;
  -            t.image = new_t.image;
  -            t.next = new_t.next;
  -            t.specialToken = new_t.specialToken;
  -        }
  -    } 
  -
       /**
        *  pushes the current state onto the 'state stack',
        *  and maintains the parens counts
  @@ -344,8 +289,11 @@
           }
   
           if( bDebugPrint_ )
  -            System.out.println(" stack pop (" + stateStack.size() + ") : lparen=" + 
( (Integer) hStack.get("lparen")).intValue() 
  -                + " newstate=" +  ( (Integer)  hStack.get("lexstate")).intValue() );
  +            System.out.println(
  +                " stack pop (" + stateStack.size() + ") : lparen=" + 
  +                    ( (Integer) hStack.get("lparen")).intValue() + 
  +                        " newstate=" + ( (Integer) hStack
  +                            .get("lexstate")).intValue() );
          
           lparen = ( (Integer) hStack.get("lparen")).intValue();
           rparen = ( (Integer) hStack.get("rparen")).intValue();
  @@ -362,7 +310,8 @@
       public boolean stateStackPush()
       {
           if( bDebugPrint_ )
  -            System.out.println(" (" + stateStack.size() + ") pushing cur state : " 
+ curLexState );
  +            System.out.println(" (" + stateStack.size() + ") pushing cur state : " 
+ 
  +                curLexState );
               
           Hashtable hStack = new Hashtable();
           hStack.put("lexstate", new Integer( curLexState ) );
  @@ -402,8 +351,9 @@
       private void RPARENHandler()
       {
           /*
  -         *  Ultimately, we want to drop down to the state below the one that has an 
open (
  -         *  if we hit bottom (DEFAULT), that's fine. It's just text schmoo.
  +         * Ultimately, we want to drop down to the state below 
  +         * the one that has an open (if we hit bottom (DEFAULT), 
  +         * that's fine. It's just text schmoo.
            *
            */
      
  @@ -415,15 +365,16 @@
           while( !bClosed) 
           {
               /*
  -             * look at current state.  If we haven't seen a lparen in this state
  -             * then we drop a state, because this lparen clearly closes our state
  +             * look at current state.  If we haven't seen a lparen 
  +             * in this state then we drop a state, because this 
  +             * lparen clearly closes our state
                */
   
               if( lparen > 0)
               {
                   /*
  -                 *  if rparen + 1 == lparen, then this state is closed. Otherwise, 
increment
  -                 *  and keep parsing
  +                 *  if rparen + 1 == lparen, then this state is closed. 
  +                 * Otherwise, increment and keep parsing
                    */
   
                    if( lparen == rparen + 1)
  @@ -483,7 +434,8 @@
               lparen++;
   
           /*
  -         *  if in REFERENCE and we have seen the dot, then move to REFMOD2 -> 
Modifier()
  +         * If in REFERENCE and we have seen the dot, then move 
  +         * to REFMOD2 -> Modifier()
            */
   
           if (curLexState == REFMODIFIER )
  @@ -492,7 +444,8 @@
   }
   
   /* 
  - *  we never will see a ')' in anything but DIRECTIVE and REFMOD2.  Each have their 
own
  + * we never will see a ')' in anything but DIRECTIVE and REFMOD2.  
  + * Each have their own
    */
   <DIRECTIVE>
   TOKEN:
  @@ -511,13 +464,15 @@
   TOKEN:
   {
       /*
  -     *  in REFMOD2, we don't want to bind the whitespace and \n like we do when 
closing a directive.
  +     * in REFMOD2, we don't want to bind the whitespace and \n like we 
  +     * do when closing a directive.
        */
       <REFMOD2_RPAREN: ")">
       {
           /*
  -         *  need to simply switch back to REFERENCE, not drop down the stack
  -         *  because we can (infinitely) chain, ala 
$foo.bar().blargh().woogie().doogie()
  +         * need to simply switch back to REFERENCE, not drop down the stack
  +         * because we can (infinitely) chain, ala 
  +         * $foo.bar().blargh().woogie().doogie()
            */
   
           SwitchTo( REFERENCE );
  @@ -548,9 +503,10 @@
   
   
   /*
  - *  needed because #set is so wacky in it's desired behavior.  We want set to eat 
any preceeding whitespace
  - *  so it is invisible in formatting. (As it should be.)  If this works well, I am 
going to chuck the whole MORE:
  - *  token abomination. 
  + * needed because #set is so wacky in it's desired behavior.  We want set 
  + * to eat any preceeding whitespace so it is invisible in formatting. 
  + * (As it should be.)  If this works well, I am going to chuck the whole MORE:
  + * token abomination. 
    */
   TOKEN:
   {
  @@ -635,9 +591,10 @@
           if (! inComment)
           {
               /*
  -             *  We can have the situation where #if($foo)$foo#end.  We need to 
transition out of 
  -             *  REFERENCE before going to DIRECTIVE.  I don't really like this, but 
I can't think of
  -             *  a legal way you are going into DIRECTIVE while in REFERENCE.  -gmj
  +             * We can have the situation where #if($foo)$foo#end.  
  +             * We need to transition out of REFERENCE before going to DIRECTIVE. 
  +             * I don't really like this, but I can't think of a legal way 
  +             * you are going into DIRECTIVE while in REFERENCE.  -gmj
                */
   
               if (curLexState == REFERENCE)
  @@ -866,13 +823,15 @@
   |   <DOT: "." <ALPHA_CHAR>> 
       { 
           /*
  -         * push the alpha char back into the stream so the following identifier is 
complete
  +         * push the alpha char back into the stream so the following identifier 
  +         * is complete
            */
   
           input_stream.backup(1); 
   
           /*
  -         *  and munge the <DOT> so we just get a . when we have normal text that 
looks like a ref.ident
  +         * and munge the <DOT> so we just get a . when we have normal text that 
  +         * looks like a ref.ident
            */
   
           matchedToken.image = ".";
  @@ -1027,7 +986,7 @@
   
   /**
    *  Used to catch and process escape sequences in grammatical constructs
  - *  as escapes outside of VTL are just characters.  Right now we hav both
  + *  as escapes outside of VTL are just characters.  Right now we have both
    *  this and the EscapeDirective() construction because in the EscapeDirective()
    *  case, we want to suck in the #<directive> and here we don't.  We just want
    *  the escapes to render correctly
  @@ -1225,9 +1184,9 @@
       try {
   /*@egen*/
       /*
  -     *  note that if we were escaped, that is now handled by EscapedDirective()
  +     * note that if we were escaped, that is now handled by 
  +     * EscapedDirective()
        */
  -  
       t = <WORD> 
       {
           String strDirectiveName = t.image.substring(1);
  @@ -1246,7 +1205,8 @@
           }
   
           /*
  -         *  set the directive name from here.  No reason for the thing to know 
about parser tokens
  +         * set the directive name from here.  No reason for the thing to know 
  +         * about parser tokens
            */
   
           jjtn000.setDirectiveName( strDirectiveName );
  @@ -2307,36 +2267,48 @@
      Notes
      -----
    
  -    template == the input stream for this parser, contains 'VTL' mixed in with 
'schmoo'
  +    template == the input stream for this parser, contains 'VTL' 
  +    mixed in with 'schmoo'
  +    
       VTL == Velocity Template Language : the references, directives, etc
  +    
       shmoo == the non-VTL component of a template
  +    
       reference == VTL entity that represents data within the context. ex. $foo
  +    
       directive == VTL entity that denotes 'action' (#set, #foreach, #if )
  -    defined directive (DD) == VTL directive entity that is expressed explicitly 
w/in this grammar
  -    pluggable directive (PD) == VTL directive entity that is defined outside of the 
grammar.  PD's
  -            allow VTL to be easily expandable w/o parser modification.
  +    
  +    defined directive (DD) == VTL directive entity that is expressed 
  +    explicitly w/in this grammar
  +    
  +    pluggable directive (PD) == VTL directive entity that is defined outside of the 
  +    grammar.  PD's allow VTL to be easily expandable w/o parser modification.
    
  -    The problem with parsing VTL is that an input stream consists generally of 
little
  -    bits of VTL mixed in with 'other stuff, referred to as 'schmoo'.  Unlike
  -    other languages, like C or Java, where the parser can punt whenever it 
encounters 
  -    input that doesn't conform to the grammar, the VTL parser can't do that.  It 
must simply 
  -    output the schmoo and keep going.  
  +    The problem with parsing VTL is that an input stream consists generally of 
  +    little bits of VTL mixed in with 'other stuff, referred to as 'schmoo'. 
  +    Unlike other languages, like C or Java, where the parser can punt whenever 
  +    it encounters input that doesn't conform to the grammar, the VTL parser can't 
do 
  +    that. It must simply output the schmoo and keep going.  
    
       There are a few things that we do here :
        - define a set of parser states (DEFAULT, DIRECTIVE, REFERENCE, etc)
        - define for each parser state a set of tokens for each state
  -     - define the VTL grammar, expressed (mostly) in the productions such as 
Text(), SetStatement(), etc.
  +     - define the VTL grammar, expressed (mostly) in the productions such as 
Text(), 
  +     SetStatement(), etc.
      
  -    It is clear that this expression of the VTL grammer (the contents of this .jjt 
file) is maturing and
  -    evolving as we learn more about how to parse VTL ( and as I learn about 
parsing...), so in the event 
  -    this documentation is in disagreement w/ the source, the source takes 
precedence. :)
  +    It is clear that this expression of the VTL grammar (the contents 
  +    of this .jjt file) is maturing and evolving as we learn more about 
  +    how to parse VTL ( and as I learn about parsing...), so in the event 
  +    this documentation is in disagreement w/ the source, the source 
  +    takes precedence. :)
    
       Parser States
       -------------
  -    DEFAULT :  This is the base or starting state, and strangely enough, the 
default state.
  +    DEFAULT :  This is the base or starting state, and strangely enough, the 
  +    default state.
    
  -    PRE_DIRECTIVE : State immediately following '#' before we figure out which 
defined or pluggable
  -        directive (or neither) we are working with.
  +    PRE_DIRECTIVE : State immediately following '#' before we figure out which 
  +    defined or pluggable directive (or neither) we are working with.
        
       DIRECTIVE : This state is triggered by the a match of a DD or a PD.
   
  @@ -2350,7 +2322,8 @@
   
       Escape Sequences
       ----------------
  -    The escape processing in VTL is very simple.  The '\' character acts only as an 
escape when :
  +    The escape processing in VTL is very simple.  The '\' character acts 
  +    only as an escape when :
       
           1) On or more touch a VTL element.
   
  @@ -2358,11 +2331,12 @@
   
           1) It preceeds a reference that is in the context.
   
  -        2) It preceeds a defined directive (#set, #if, #end, etc) or a valid 
pluggable directive, 
  -            such as #foreach
  +        2) It preceeds a defined directive (#set, #if, #end, etc) or a valid 
  +        pluggable directive, such as #foreach
   
  -    In all other cases the '\' is just another piece of text.  The purpose of this 
is to allow the non-VTL
  -    parts of a template (the 'schmoo') to not have to be altered for processing by 
Velocity.
  +    In all other cases the '\' is just another piece of text.  The purpose of this 
  +    is to allow the non-VTL parts of a template (the 'schmoo') to not have to be 
  +    altered for processing by Velocity.
   
       So if in the context $foo and $bar were defined and $woogie was not 
           
  @@ -2372,7 +2346,8 @@
   
           $foo  $bar  \$woogie
   
  -    Further, you can stack them and they affect left to right, just like convention 
escape characters in other languages.
  +    Further, you can stack them and they affect left to right, just like convention 
  +    escape characters in other languages.
   
           \$foo = $foo
           \\$foo = \<foo>
  @@ -2381,9 +2356,11 @@
       
       What You Expect
       ---------------
  -    The recent versions of the parser are trying to support precise output to 
support general template use.
  -    The directives do not render trailing whitespace and newlines if followed by a 
newline.  They will render preceeding whitespace.
  -    The only exception is #set, which also eats preceeding whitespace.
  +    The recent versions of the parser are trying to support precise output to 
  +    support general template use. The directives do not render trailing 
  +    whitespace and newlines if followed by a newline.  They will render 
  +    preceeding whitespace. The only exception is #set, which also eats 
  +    preceeding whitespace.
    
       So, with a template :
   
  
  
  
  1.31      +28 -58    
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java
  
  Index: ParserTokenManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- ParserTokenManager.java   2000/11/26 18:11:39     1.30
  +++ ParserTokenManager.java   2000/11/30 08:15:51     1.31
  @@ -23,45 +23,6 @@
       private boolean inComment;
       private boolean inSet;
   
  -    Stack streams = new Stack();
  -    Stack states = new Stack();
  -
  -    /**
  -     * Retrieve the oldStream and oldState and
  -     * continue processing the input.
  -     */
  -    void popFile()
  -    {
  -        ReInit((ASCII_CharStream) streams.pop(), ((Integer) 
states.pop()).intValue());
  -        fileDepth--;
  -    }
  -
  -    private boolean AtParent()
  -    {
  -        if (fileDepth == 0)
  -            return true;
  -        else
  -            return false;
  -    }
  -
  -    void CommonTokenAction(Token t)
  -    {
  -        if (t.kind == EOF && ! AtParent())
  -        {
  -            Token new_t;
  -            popFile();
  -            new_t = getNextToken();
  -            t.kind = new_t.kind;
  -            t.beginLine = new_t.beginLine;
  -            t.beginColumn = new_t.beginColumn;
  -            t.endLine = new_t.endLine;
  -            t.endColumn = new_t.endColumn;
  -            t.image = new_t.image;
  -            t.next = new_t.next;
  -            t.specialToken = new_t.specialToken;
  -        }
  -    }
  -
       /**
        *  pushes the current state onto the 'state stack',
        *  and maintains the parens counts
  @@ -87,8 +48,11 @@
           }
   
           if( bDebugPrint_ )
  -            System.out.println(" stack pop (" + stateStack.size() + ") : lparen=" + 
( (Integer) hStack.get("lparen")).intValue()
  -                + " newstate=" +  ( (Integer)  hStack.get("lexstate")).intValue() );
  +            System.out.println(
  +                " stack pop (" + stateStack.size() + ") : lparen=" +
  +                    ( (Integer) hStack.get("lparen")).intValue() +
  +                        " newstate=" + ( (Integer) hStack
  +                            .get("lexstate")).intValue() );
   
           lparen = ( (Integer) hStack.get("lparen")).intValue();
           rparen = ( (Integer) hStack.get("rparen")).intValue();
  @@ -105,7 +69,8 @@
       public boolean stateStackPush()
       {
           if( bDebugPrint_ )
  -            System.out.println(" (" + stateStack.size() + ") pushing cur state : " 
+ curLexState );
  +            System.out.println(" (" + stateStack.size() + ") pushing cur state : " +
  +                curLexState );
   
           Hashtable hStack = new Hashtable();
           hStack.put("lexstate", new Integer( curLexState ) );
  @@ -145,8 +110,9 @@
       private void RPARENHandler()
       {
           /*
  -         *  Ultimately, we want to drop down to the state below the one that has an 
open (
  -         *  if we hit bottom (DEFAULT), that's fine. It's just text schmoo.
  +         * Ultimately, we want to drop down to the state below 
  +         * the one that has an open (if we hit bottom (DEFAULT), 
  +         * that's fine. It's just text schmoo.
            *
            */
   
  @@ -158,15 +124,16 @@
           while( !bClosed)
           {
               /*
  -             * look at current state.  If we haven't seen a lparen in this state
  -             * then we drop a state, because this lparen clearly closes our state
  +             * look at current state.  If we haven't seen a lparen 
  +             * in this state then we drop a state, because this 
  +             * lparen clearly closes our state
                */
   
               if( lparen > 0)
               {
                   /*
  -                 *  if rparen + 1 == lparen, then this state is closed. Otherwise, 
increment
  -                 *  and keep parsing
  +                 *  if rparen + 1 == lparen, then this state is closed. 
  +                 * Otherwise, increment and keep parsing
                    */
   
                    if( lparen == rparen + 1)
  @@ -3014,7 +2981,6 @@
         jjmatchedKind = 0;
         matchedToken = jjFillToken();
         matchedToken.specialToken = specialToken;
  -      CommonTokenAction(matchedToken);
         return matchedToken;
      }
      image = null;
  @@ -3109,7 +3075,6 @@
              TokenLexicalActions(matchedToken);
          if (jjnewLexState[jjmatchedKind] != -1)
            curLexState = jjnewLexState[jjmatchedKind];
  -           CommonTokenAction(matchedToken);
              return matchedToken;
           }
           else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 
0L)
  @@ -3287,9 +3252,10 @@
           if (! inComment)
           {
               /*
  -             *  We can have the situation where #if($foo)$foo#end.  We need to 
transition out of 
  -             *  REFERENCE before going to DIRECTIVE.  I don't really like this, but 
I can't think of
  -             *  a legal way you are going into DIRECTIVE while in REFERENCE.  -gmj
  +             * We can have the situation where #if($foo)$foo#end.  
  +             * We need to transition out of REFERENCE before going to DIRECTIVE. 
  +             * I don't really like this, but I can't think of a legal way 
  +             * you are going into DIRECTIVE while in REFERENCE.  -gmj
                */
   
               if (curLexState == REFERENCE)
  @@ -3324,7 +3290,8 @@
               lparen++;
   
           /*
  -         *  if in REFERENCE and we have seen the dot, then move to REFMOD2 -> 
Modifier()
  +         * If in REFERENCE and we have seen the dot, then move 
  +         * to REFMOD2 -> Modifier()
            */
   
           if (curLexState == REFMODIFIER )
  @@ -3343,8 +3310,9 @@
            else
               image.append(new String(input_stream.GetSuffix(jjimageLen + 
(lengthOfMatch = jjmatchedPos + 1))));
           /*
  -         *  need to simply switch back to REFERENCE, not drop down the stack
  -         *  because we can (infinitely) chain, ala 
$foo.bar().blargh().woogie().doogie()
  +         * need to simply switch back to REFERENCE, not drop down the stack
  +         * because we can (infinitely) chain, ala 
  +         * $foo.bar().blargh().woogie().doogie()
            */
   
           SwitchTo( REFERENCE );
  @@ -3481,13 +3449,15 @@
            else
               image.append(new String(input_stream.GetSuffix(jjimageLen + 
(lengthOfMatch = jjmatchedPos + 1))));
           /*
  -         * push the alpha char back into the stream so the following identifier is 
complete
  +         * push the alpha char back into the stream so the following identifier 
  +         * is complete
            */
   
           input_stream.backup(1);
   
           /*
  -         *  and munge the <DOT> so we just get a . when we have normal text that 
looks like a ref.ident
  +         * and munge the <DOT> so we just get a . when we have normal text that 
  +         * looks like a ref.ident
            */
   
           matchedToken.image = ".";
  
  
  

Reply via email to