Save This Page
Home » lucene-3.0.1-src » org.apache.lucene.queryParser.standard.parser » [javadoc | source]
    1   /* Generated By:JavaCC: Do not edit this line. StandardSyntaxParser.java */
    2   package org.apache.lucene.queryParser.standard.parser;
    3   
    4   /**
    5    * Licensed to the Apache Software Foundation (ASF) under one or more
    6    * contributor license agreements.  See the NOTICE file distributed with
    7    * this work for additional information regarding copyright ownership.
    8    * The ASF licenses this file to You under the Apache License, Version 2.0
    9    * (the "License"); you may not use this file except in compliance with
   10    * the License.  You may obtain a copy of the License at
   11    *
   12    *     http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing, software
   15    * distributed under the License is distributed on an "AS IS" BASIS,
   16    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   17    * See the License for the specific language governing permissions and
   18    * limitations under the License.
   19    */
   20   
   21   import java.io.StringReader;
   22   import java.util.Vector;
   23   
   24   import org.apache.lucene.messages.Message;
   25   import org.apache.lucene.messages.MessageImpl;
   26   import org.apache.lucene.queryParser.core.QueryNodeParseException;
   27   import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
   28   import org.apache.lucene.queryParser.core.nodes.AndQueryNode;
   29   import org.apache.lucene.queryParser.core.nodes.BooleanQueryNode;
   30   import org.apache.lucene.queryParser.core.nodes.BoostQueryNode;
   31   import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
   32   import org.apache.lucene.queryParser.core.nodes.FuzzyQueryNode;
   33   import org.apache.lucene.queryParser.core.nodes.GroupQueryNode;
   34   import org.apache.lucene.queryParser.core.nodes.ModifierQueryNode;
   35   import org.apache.lucene.queryParser.core.nodes.OrQueryNode;
   36   import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode;
   37   import org.apache.lucene.queryParser.core.nodes.ParametricRangeQueryNode;
   38   import org.apache.lucene.queryParser.core.nodes.QueryNode;
   39   import org.apache.lucene.queryParser.core.nodes.QuotedFieldQueryNode;
   40   import org.apache.lucene.queryParser.core.nodes.SlopQueryNode;
   41   import org.apache.lucene.queryParser.core.parser.SyntaxParser;
   42   
   43   @SuppressWarnings("all")
   44   public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserConstants {
   45   
   46           private static final int CONJ_NONE =0;
   47           private static final int CONJ_AND =2;
   48           private static final int CONJ_OR =2;
   49   
   50   
   51      // syntax parser constructor
   52      public StandardSyntaxParser() {
   53           this(new StringReader(""));
   54     }
   55        /** Parses a query string, returning a {@link org.apache.lucene.queryParser.core.nodes.QueryNode}.
   56        *  @param query  the query string to be parsed.
   57        *  @throws ParseException if the parsing fails
   58        */
   59       public QueryNode parse(CharSequence query, CharSequence field) throws QueryNodeParseException {
   60         ReInit(new StringReader(query.toString()));
   61         try {
   62           // TopLevelQuery is a Query followed by the end-of-input (EOF)
   63           QueryNode querynode = TopLevelQuery(field);
   64           return querynode;
   65         }
   66         catch (ParseException tme) {
   67               tme.setQuery(query);
   68               throw tme;
   69         }
   70         catch (Error tme) {
   71             Message message = new MessageImpl(QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, query, tme.getMessage());
   72             QueryNodeParseException e = new QueryNodeParseException(tme);
   73               e.setQuery(query);
   74               e.setNonLocalizedMessage(message);
   75               throw e;
   76         }
   77       }
   78   
   79   // *   Query  ::= ( Clause )*
   80   // *   Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
   81     final public int Conjunction() throws ParseException {
   82     int ret = CONJ_NONE;
   83       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
   84       case AND:
   85       case OR:
   86         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
   87         case AND:
   88           jj_consume_token(AND);
   89               ret = CONJ_AND;
   90           break;
   91         case OR:
   92           jj_consume_token(OR);
   93                 ret = CONJ_OR;
   94           break;
   95         default:
   96           jj_la1[0] = jj_gen;
   97           jj_consume_token(-1);
   98           throw new ParseException();
   99         }
  100         break;
  101       default:
  102         jj_la1[1] = jj_gen;
  103         ;
  104       }
  105       {if (true) return ret;}
  106       throw new Error("Missing return statement in function");
  107     }
  108   
  109     final public ModifierQueryNode.Modifier Modifiers() throws ParseException {
  110     ModifierQueryNode.Modifier ret = ModifierQueryNode.Modifier.MOD_NONE;
  111       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  112       case NOT:
  113       case PLUS:
  114       case MINUS:
  115         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  116         case PLUS:
  117           jj_consume_token(PLUS);
  118                 ret = ModifierQueryNode.Modifier.MOD_REQ;
  119           break;
  120         case MINUS:
  121           jj_consume_token(MINUS);
  122                    ret = ModifierQueryNode.Modifier.MOD_NOT;
  123           break;
  124         case NOT:
  125           jj_consume_token(NOT);
  126                  ret = ModifierQueryNode.Modifier.MOD_NOT;
  127           break;
  128         default:
  129           jj_la1[2] = jj_gen;
  130           jj_consume_token(-1);
  131           throw new ParseException();
  132         }
  133         break;
  134       default:
  135         jj_la1[3] = jj_gen;
  136         ;
  137       }
  138       {if (true) return ret;}
  139       throw new Error("Missing return statement in function");
  140     }
  141   
  142   // This makes sure that there is no garbage after the query string
  143     final public QueryNode TopLevelQuery(CharSequence field) throws ParseException {
  144           QueryNode q;
  145       q = Query(field);
  146       jj_consume_token(0);
  147                   {if (true) return q;}
  148       throw new Error("Missing return statement in function");
  149     }
  150   
  151   // These changes were made to introduce operator precedence:
  152   // - Clause() now returns a QueryNode. 
  153   // - The modifiers are consumed by Clause() and returned as part of the QueryNode Object
  154   // - Query does not consume conjunctions (AND, OR) anymore. 
  155   // - This is now done by two new non-terminals: ConjClause and DisjClause
  156   // The parse tree looks similar to this:
  157   //       Query ::= DisjQuery ( DisjQuery )*
  158   //   DisjQuery ::= ConjQuery ( OR ConjQuery )* 
  159   //   ConjQuery ::= Clause ( AND Clause )*
  160   //      Clause ::= [ Modifier ] ... 
  161     final public QueryNode Query(CharSequence field) throws ParseException {
  162     Vector clauses = null;
  163     QueryNode c, first=null;
  164       first = DisjQuery(field);
  165       label_1:
  166       while (true) {
  167         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  168         case NOT:
  169         case PLUS:
  170         case MINUS:
  171         case LPAREN:
  172         case QUOTED:
  173         case TERM:
  174         case RANGEIN_START:
  175         case RANGEEX_START:
  176         case NUMBER:
  177           ;
  178           break;
  179         default:
  180           jj_la1[4] = jj_gen;
  181           break label_1;
  182         }
  183         c = DisjQuery(field);
  184                if (clauses == null) {
  185                    clauses = new Vector();
  186                    clauses.addElement(first);
  187                }
  188            clauses.addElement(c);
  189       }
  190           if (clauses != null) {
  191                   {if (true) return new BooleanQueryNode(clauses);}
  192           } else {
  193                   {if (true) return first;}
  194           }
  195       throw new Error("Missing return statement in function");
  196     }
  197   
  198     final public QueryNode DisjQuery(CharSequence field) throws ParseException {
  199           QueryNode first, c;
  200           Vector clauses = null;
  201       first = ConjQuery(field);
  202       label_2:
  203       while (true) {
  204         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  205         case OR:
  206           ;
  207           break;
  208         default:
  209           jj_la1[5] = jj_gen;
  210           break label_2;
  211         }
  212         jj_consume_token(OR);
  213         c = ConjQuery(field);
  214        if (clauses == null) {
  215            clauses = new Vector();
  216            clauses.addElement(first);
  217        }
  218        clauses.addElement(c);
  219       }
  220       if (clauses != null) {
  221               {if (true) return new OrQueryNode(clauses);}
  222       } else {
  223           {if (true) return first;}
  224       }
  225       throw new Error("Missing return statement in function");
  226     }
  227   
  228     final public QueryNode ConjQuery(CharSequence field) throws ParseException {
  229           QueryNode first, c;
  230           Vector clauses = null;
  231       first = ModClause(field);
  232       label_3:
  233       while (true) {
  234         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  235         case AND:
  236           ;
  237           break;
  238         default:
  239           jj_la1[6] = jj_gen;
  240           break label_3;
  241         }
  242         jj_consume_token(AND);
  243         c = ModClause(field);
  244        if (clauses == null) {
  245            clauses = new Vector();
  246            clauses.addElement(first);
  247        }
  248        clauses.addElement(c);
  249       }
  250       if (clauses != null) {
  251               {if (true) return new AndQueryNode(clauses);}
  252       } else {
  253           {if (true) return first;}
  254       }
  255       throw new Error("Missing return statement in function");
  256     }
  257   
  258   // QueryNode Query(CharSequence field) :
  259   // {
  260   // List clauses = new ArrayList();
  261   //   List modifiers = new ArrayList();
  262   //   QueryNode q, firstQuery=null;
  263   //   ModifierQueryNode.Modifier mods;
  264   //   int conj;
  265   // }
  266   // {
  267   //   mods=Modifiers() q=Clause(field)
  268   //   {
  269   //     if (mods == ModifierQueryNode.Modifier.MOD_NONE) firstQuery=q;
  270   //     
  271   //     // do not create modifier nodes with MOD_NONE
  272   //    	if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
  273   //    		q = new ModifierQueryNode(q, mods);
  274   //    	}
  275   //    	clauses.add(q);
  276   //   }
  277   //   (
  278   //     conj=Conjunction() mods=Modifiers() q=Clause(field)
  279   //     { 
  280   // 	    // do not create modifier nodes with MOD_NONE
  281   // 	   	if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
  282   // 	   		q = new ModifierQueryNode(q, mods);
  283   // 	   	}
  284   // 	   	clauses.add(q);
  285   // 	   	//TODO: figure out what to do with AND and ORs
  286   //   }
  287   //   )*
  288   //     {
  289   //      if (clauses.size() == 1 && firstQuery != null)
  290   //         return firstQuery;
  291   //       else {
  292   //   		return new BooleanQueryNode(clauses);
  293   //       }
  294   //     }
  295   // }
  296     final public QueryNode ModClause(CharSequence field) throws ParseException {
  297     QueryNode q;
  298     ModifierQueryNode.Modifier mods;
  299       mods = Modifiers();
  300       q = Clause(field);
  301                   if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
  302                           q = new ModifierQueryNode(q, mods);
  303                   }
  304                   {if (true) return q;}
  305       throw new Error("Missing return statement in function");
  306     }
  307   
  308     final public QueryNode Clause(CharSequence field) throws ParseException {
  309     QueryNode q;
  310     Token fieldToken=null, boost=null;
  311     boolean group = false;
  312       if (jj_2_1(2)) {
  313         fieldToken = jj_consume_token(TERM);
  314         jj_consume_token(COLON);
  315                                  field=EscapeQuerySyntaxImpl.discardEscapeChar(fieldToken.image);
  316       } else {
  317         ;
  318       }
  319       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  320       case QUOTED:
  321       case TERM:
  322       case RANGEIN_START:
  323       case RANGEEX_START:
  324       case NUMBER:
  325         q = Term(field);
  326         break;
  327       case LPAREN:
  328         jj_consume_token(LPAREN);
  329         q = Query(field);
  330         jj_consume_token(RPAREN);
  331         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  332         case CARAT:
  333           jj_consume_token(CARAT);
  334           boost = jj_consume_token(NUMBER);
  335           break;
  336         default:
  337           jj_la1[7] = jj_gen;
  338           ;
  339         }
  340                                                                    group=true;
  341         break;
  342       default:
  343         jj_la1[8] = jj_gen;
  344         jj_consume_token(-1);
  345         throw new ParseException();
  346       }
  347         if (boost != null) {
  348                     float f = (float)1.0;
  349                     try {
  350                       f = Float.valueOf(boost.image).floatValue();
  351                       // avoid boosting null queries, such as those caused by stop words
  352                   if (q != null) {
  353                           q = new BoostQueryNode(q, f);
  354                   }
  355                     } catch (Exception ignored) {
  356                           /* Should this be handled somehow? (defaults to "no boost", if
  357                * boost number is invalid)
  358                */
  359                     }
  360         }
  361         if (group) { q = new GroupQueryNode(q);}
  362         {if (true) return q;}
  363       throw new Error("Missing return statement in function");
  364     }
  365   
  366     final public QueryNode Term(CharSequence field) throws ParseException {
  367     Token term, boost=null, fuzzySlop=null, goop1, goop2;
  368     boolean fuzzy = false;
  369     QueryNode q =null;
  370     ParametricQueryNode qLower, qUpper;
  371     float defaultMinSimilarity = 0.5f;
  372       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  373       case TERM:
  374       case NUMBER:
  375         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  376         case TERM:
  377           term = jj_consume_token(TERM);
  378                            q = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn);
  379           break;
  380         case NUMBER:
  381           term = jj_consume_token(NUMBER);
  382           break;
  383         default:
  384           jj_la1[9] = jj_gen;
  385           jj_consume_token(-1);
  386           throw new ParseException();
  387         }
  388         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  389         case FUZZY_SLOP:
  390           fuzzySlop = jj_consume_token(FUZZY_SLOP);
  391                                   fuzzy=true;
  392           break;
  393         default:
  394           jj_la1[10] = jj_gen;
  395           ;
  396         }
  397         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  398         case CARAT:
  399           jj_consume_token(CARAT);
  400           boost = jj_consume_token(NUMBER);
  401           switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  402           case FUZZY_SLOP:
  403             fuzzySlop = jj_consume_token(FUZZY_SLOP);
  404                                                            fuzzy=true;
  405             break;
  406           default:
  407             jj_la1[11] = jj_gen;
  408             ;
  409           }
  410           break;
  411         default:
  412           jj_la1[12] = jj_gen;
  413           ;
  414         }
  415          if (fuzzy) {
  416             float fms = defaultMinSimilarity;
  417             try {
  418               fms = Float.valueOf(fuzzySlop.image.substring(1)).floatValue();
  419             } catch (Exception ignored) { }
  420            if(fms < 0.0f || fms > 1.0f){
  421              {if (true) throw new ParseException(new MessageImpl(QueryParserMessages.INVALID_SYNTAX_FUZZY_LIMITS));}
  422            }
  423            q = new FuzzyQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), fms, term.beginColumn, term.endColumn);
  424          }
  425         break;
  426       case RANGEIN_START:
  427         jj_consume_token(RANGEIN_START);
  428         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  429         case RANGEIN_GOOP:
  430           goop1 = jj_consume_token(RANGEIN_GOOP);
  431           break;
  432         case RANGEIN_QUOTED:
  433           goop1 = jj_consume_token(RANGEIN_QUOTED);
  434           break;
  435         default:
  436           jj_la1[13] = jj_gen;
  437           jj_consume_token(-1);
  438           throw new ParseException();
  439         }
  440         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  441         case RANGEIN_TO:
  442           jj_consume_token(RANGEIN_TO);
  443           break;
  444         default:
  445           jj_la1[14] = jj_gen;
  446           ;
  447         }
  448         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  449         case RANGEIN_GOOP:
  450           goop2 = jj_consume_token(RANGEIN_GOOP);
  451           break;
  452         case RANGEIN_QUOTED:
  453           goop2 = jj_consume_token(RANGEIN_QUOTED);
  454           break;
  455         default:
  456           jj_la1[15] = jj_gen;
  457           jj_consume_token(-1);
  458           throw new ParseException();
  459         }
  460         jj_consume_token(RANGEIN_END);
  461         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  462         case CARAT:
  463           jj_consume_token(CARAT);
  464           boost = jj_consume_token(NUMBER);
  465           break;
  466         default:
  467           jj_la1[16] = jj_gen;
  468           ;
  469         }
  470             if (goop1.kind == RANGEIN_QUOTED) {
  471               goop1.image = goop1.image.substring(1, goop1.image.length()-1);
  472             }
  473             if (goop2.kind == RANGEIN_QUOTED) {
  474               goop2.image = goop2.image.substring(1, goop2.image.length()-1);
  475             }
  476   
  477             qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GE,
  478                                                  EscapeQuerySyntaxImpl.discardEscapeChar(goop1.image), goop1.beginColumn, goop1.endColumn);
  479                     qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LE,
  480                                                  EscapeQuerySyntaxImpl.discardEscapeChar(goop2.image), goop2.beginColumn, goop2.endColumn);
  481             q = new ParametricRangeQueryNode(qLower, qUpper);
  482         break;
  483       case RANGEEX_START:
  484         jj_consume_token(RANGEEX_START);
  485         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  486         case RANGEEX_GOOP:
  487           goop1 = jj_consume_token(RANGEEX_GOOP);
  488           break;
  489         case RANGEEX_QUOTED:
  490           goop1 = jj_consume_token(RANGEEX_QUOTED);
  491           break;
  492         default:
  493           jj_la1[17] = jj_gen;
  494           jj_consume_token(-1);
  495           throw new ParseException();
  496         }
  497         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  498         case RANGEEX_TO:
  499           jj_consume_token(RANGEEX_TO);
  500           break;
  501         default:
  502           jj_la1[18] = jj_gen;
  503           ;
  504         }
  505         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  506         case RANGEEX_GOOP:
  507           goop2 = jj_consume_token(RANGEEX_GOOP);
  508           break;
  509         case RANGEEX_QUOTED:
  510           goop2 = jj_consume_token(RANGEEX_QUOTED);
  511           break;
  512         default:
  513           jj_la1[19] = jj_gen;
  514           jj_consume_token(-1);
  515           throw new ParseException();
  516         }
  517         jj_consume_token(RANGEEX_END);
  518         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  519         case CARAT:
  520           jj_consume_token(CARAT);
  521           boost = jj_consume_token(NUMBER);
  522           break;
  523         default:
  524           jj_la1[20] = jj_gen;
  525           ;
  526         }
  527             if (goop1.kind == RANGEEX_QUOTED) {
  528               goop1.image = goop1.image.substring(1, goop1.image.length()-1);
  529             }
  530             if (goop2.kind == RANGEEX_QUOTED) {
  531               goop2.image = goop2.image.substring(1, goop2.image.length()-1);
  532             }
  533             qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GT,
  534                                                  EscapeQuerySyntaxImpl.discardEscapeChar(goop1.image), goop1.beginColumn, goop1.endColumn);
  535                     qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LT,
  536                                                  EscapeQuerySyntaxImpl.discardEscapeChar(goop2.image), goop2.beginColumn, goop2.endColumn);
  537             q = new ParametricRangeQueryNode(qLower, qUpper);
  538         break;
  539       case QUOTED:
  540         term = jj_consume_token(QUOTED);
  541                         q = new QuotedFieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image.substring(1, term.image.length()-1)), term.beginColumn + 1, term.endColumn - 1);
  542         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  543         case FUZZY_SLOP:
  544           fuzzySlop = jj_consume_token(FUZZY_SLOP);
  545           break;
  546         default:
  547           jj_la1[21] = jj_gen;
  548           ;
  549         }
  550         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  551         case CARAT:
  552           jj_consume_token(CARAT);
  553           boost = jj_consume_token(NUMBER);
  554           break;
  555         default:
  556           jj_la1[22] = jj_gen;
  557           ;
  558         }
  559            int phraseSlop = 0;
  560   
  561            if (fuzzySlop != null) {
  562              try {
  563                phraseSlop = Float.valueOf(fuzzySlop.image.substring(1)).intValue();
  564                q = new SlopQueryNode(q, phraseSlop);
  565              }
  566              catch (Exception ignored) {
  567               /* Should this be handled somehow? (defaults to "no PhraseSlop", if
  568   	         * slop number is invalid)
  569   	         */
  570              }
  571            }
  572         break;
  573       default:
  574         jj_la1[23] = jj_gen;
  575         jj_consume_token(-1);
  576         throw new ParseException();
  577       }
  578             if (boost != null) {
  579                     float f = (float)1.0;
  580                     try {
  581                       f = Float.valueOf(boost.image).floatValue();
  582                       // avoid boosting null queries, such as those caused by stop words
  583                   if (q != null) {
  584                           q = new BoostQueryNode(q, f);
  585                   }
  586                     } catch (Exception ignored) {
  587                           /* Should this be handled somehow? (defaults to "no boost", if
  588   	         * boost number is invalid)
  589   	         */
  590                     }
  591             }
  592         {if (true) return q;}
  593       throw new Error("Missing return statement in function");
  594     }
  595   
  596     private boolean jj_2_1(int xla) {
  597       jj_la = xla; jj_lastpos = jj_scanpos = token;
  598       try { return !jj_3_1(); }
  599       catch(LookaheadSuccess ls) { return true; }
  600       finally { jj_save(0, xla); }
  601     }
  602   
  603     private boolean jj_3_1() {
  604       if (jj_scan_token(TERM)) return true;
  605       if (jj_scan_token(COLON)) return true;
  606       return false;
  607     }
  608   
  609     /** Generated Token Manager. */
  610     public StandardSyntaxParserTokenManager token_source;
  611     JavaCharStream jj_input_stream;
  612     /** Current token. */
  613     public Token token;
  614     /** Next token. */
  615     public Token jj_nt;
  616     private int jj_ntk;
  617     private Token jj_scanpos, jj_lastpos;
  618     private int jj_la;
  619     private int jj_gen;
  620     final private int[] jj_la1 = new int[24];
  621     static private int[] jj_la1_0;
  622     static {
  623         jj_la1_init_0();
  624      }
  625      private static void jj_la1_init_0() {
  626         jj_la1_0 = new int[] {0x300,0x300,0x1c00,0x1c00,0x763c00,0x200,0x100,0x10000,0x762000,0x440000,0x80000,0x80000,0x10000,0x6000000,0x800000,0x6000000,0x10000,0x60000000,0x8000000,0x60000000,0x10000,0x80000,0x10000,0x760000,};
  627      }
  628     final private JJCalls[] jj_2_rtns = new JJCalls[1];
  629     private boolean jj_rescan = false;
  630     private int jj_gc = 0;
  631   
  632     /** Constructor with InputStream. */
  633     public StandardSyntaxParser(java.io.InputStream stream) {
  634        this(stream, null);
  635     }
  636     /** Constructor with InputStream and supplied encoding */
  637     public StandardSyntaxParser(java.io.InputStream stream, String encoding) {
  638       try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
  639       token_source = new StandardSyntaxParserTokenManager(jj_input_stream);
  640       token = new Token();
  641       jj_ntk = -1;
  642       jj_gen = 0;
  643       for (int i = 0; i < 24; i++) jj_la1[i] = -1;
  644       for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  645     }
  646   
  647     /** Reinitialise. */
  648     public void ReInit(java.io.InputStream stream) {
  649        ReInit(stream, null);
  650     }
  651     /** Reinitialise. */
  652     public void ReInit(java.io.InputStream stream, String encoding) {
  653       try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
  654       token_source.ReInit(jj_input_stream);
  655       token = new Token();
  656       jj_ntk = -1;
  657       jj_gen = 0;
  658       for (int i = 0; i < 24; i++) jj_la1[i] = -1;
  659       for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  660     }
  661   
  662     /** Constructor. */
  663     public StandardSyntaxParser(java.io.Reader stream) {
  664       jj_input_stream = new JavaCharStream(stream, 1, 1);
  665       token_source = new StandardSyntaxParserTokenManager(jj_input_stream);
  666       token = new Token();
  667       jj_ntk = -1;
  668       jj_gen = 0;
  669       for (int i = 0; i < 24; i++) jj_la1[i] = -1;
  670       for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  671     }
  672   
  673     /** Reinitialise. */
  674     public void ReInit(java.io.Reader stream) {
  675       jj_input_stream.ReInit(stream, 1, 1);
  676       token_source.ReInit(jj_input_stream);
  677       token = new Token();
  678       jj_ntk = -1;
  679       jj_gen = 0;
  680       for (int i = 0; i < 24; i++) jj_la1[i] = -1;
  681       for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  682     }
  683   
  684     /** Constructor with generated Token Manager. */
  685     public StandardSyntaxParser(StandardSyntaxParserTokenManager tm) {
  686       token_source = tm;
  687       token = new Token();
  688       jj_ntk = -1;
  689       jj_gen = 0;
  690       for (int i = 0; i < 24; i++) jj_la1[i] = -1;
  691       for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  692     }
  693   
  694     /** Reinitialise. */
  695     public void ReInit(StandardSyntaxParserTokenManager tm) {
  696       token_source = tm;
  697       token = new Token();
  698       jj_ntk = -1;
  699       jj_gen = 0;
  700       for (int i = 0; i < 24; i++) jj_la1[i] = -1;
  701       for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  702     }
  703   
  704     private Token jj_consume_token(int kind) throws ParseException {
  705       Token oldToken;
  706       if ((oldToken = token).next != null) token = token.next;
  707       else token = token.next = token_source.getNextToken();
  708       jj_ntk = -1;
  709       if (token.kind == kind) {
  710         jj_gen++;
  711         if (++jj_gc > 100) {
  712           jj_gc = 0;
  713           for (int i = 0; i < jj_2_rtns.length; i++) {
  714             JJCalls c = jj_2_rtns[i];
  715             while (c != null) {
  716               if (c.gen < jj_gen) c.first = null;
  717               c = c.next;
  718             }
  719           }
  720         }
  721         return token;
  722       }
  723       token = oldToken;
  724       jj_kind = kind;
  725       throw generateParseException();
  726     }
  727   
  728     static private final class LookaheadSuccess extends java.lang.Error { }
  729     final private LookaheadSuccess jj_ls = new LookaheadSuccess();
  730     private boolean jj_scan_token(int kind) {
  731       if (jj_scanpos == jj_lastpos) {
  732         jj_la--;
  733         if (jj_scanpos.next == null) {
  734           jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
  735         } else {
  736           jj_lastpos = jj_scanpos = jj_scanpos.next;
  737         }
  738       } else {
  739         jj_scanpos = jj_scanpos.next;
  740       }
  741       if (jj_rescan) {
  742         int i = 0; Token tok = token;
  743         while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
  744         if (tok != null) jj_add_error_token(kind, i);
  745       }
  746       if (jj_scanpos.kind != kind) return true;
  747       if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
  748       return false;
  749     }
  750   
  751   
  752   /** Get the next Token. */
  753     final public Token getNextToken() {
  754       if (token.next != null) token = token.next;
  755       else token = token.next = token_source.getNextToken();
  756       jj_ntk = -1;
  757       jj_gen++;
  758       return token;
  759     }
  760   
  761   /** Get the specific Token. */
  762     final public Token getToken(int index) {
  763       Token t = token;
  764       for (int i = 0; i < index; i++) {
  765         if (t.next != null) t = t.next;
  766         else t = t.next = token_source.getNextToken();
  767       }
  768       return t;
  769     }
  770   
  771     private int jj_ntk() {
  772       if ((jj_nt=token.next) == null)
  773         return (jj_ntk = (token.next=token_source.getNextToken()).kind);
  774       else
  775         return (jj_ntk = jj_nt.kind);
  776     }
  777   
  778     private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
  779     private int[] jj_expentry;
  780     private int jj_kind = -1;
  781     private int[] jj_lasttokens = new int[100];
  782     private int jj_endpos;
  783   
  784     private void jj_add_error_token(int kind, int pos) {
  785       if (pos >= 100) return;
  786       if (pos == jj_endpos + 1) {
  787         jj_lasttokens[jj_endpos++] = kind;
  788       } else if (jj_endpos != 0) {
  789         jj_expentry = new int[jj_endpos];
  790         for (int i = 0; i < jj_endpos; i++) {
  791           jj_expentry[i] = jj_lasttokens[i];
  792         }
  793         jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) {
  794           int[] oldentry = (int[])(it.next());
  795           if (oldentry.length == jj_expentry.length) {
  796             for (int i = 0; i < jj_expentry.length; i++) {
  797               if (oldentry[i] != jj_expentry[i]) {
  798                 continue jj_entries_loop;
  799               }
  800             }
  801             jj_expentries.add(jj_expentry);
  802             break jj_entries_loop;
  803           }
  804         }
  805         if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
  806       }
  807     }
  808   
  809     /** Generate ParseException. */
  810     public ParseException generateParseException() {
  811       jj_expentries.clear();
  812       boolean[] la1tokens = new boolean[31];
  813       if (jj_kind >= 0) {
  814         la1tokens[jj_kind] = true;
  815         jj_kind = -1;
  816       }
  817       for (int i = 0; i < 24; i++) {
  818         if (jj_la1[i] == jj_gen) {
  819           for (int j = 0; j < 32; j++) {
  820             if ((jj_la1_0[i] & (1<<j)) != 0) {
  821               la1tokens[j] = true;
  822             }
  823           }
  824         }
  825       }
  826       for (int i = 0; i < 31; i++) {
  827         if (la1tokens[i]) {
  828           jj_expentry = new int[1];
  829           jj_expentry[0] = i;
  830           jj_expentries.add(jj_expentry);
  831         }
  832       }
  833       jj_endpos = 0;
  834       jj_rescan_token();
  835       jj_add_error_token(0, 0);
  836       int[][] exptokseq = new int[jj_expentries.size()][];
  837       for (int i = 0; i < jj_expentries.size(); i++) {
  838         exptokseq[i] = jj_expentries.get(i);
  839       }
  840       return new ParseException(token, exptokseq, tokenImage);
  841     }
  842   
  843     /** Enable tracing. */
  844     final public void enable_tracing() {
  845     }
  846   
  847     /** Disable tracing. */
  848     final public void disable_tracing() {
  849     }
  850   
  851     private void jj_rescan_token() {
  852       jj_rescan = true;
  853       for (int i = 0; i < 1; i++) {
  854       try {
  855         JJCalls p = jj_2_rtns[i];
  856         do {
  857           if (p.gen > jj_gen) {
  858             jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
  859             switch (i) {
  860               case 0: jj_3_1(); break;
  861             }
  862           }
  863           p = p.next;
  864         } while (p != null);
  865         } catch(LookaheadSuccess ls) { }
  866       }
  867       jj_rescan = false;
  868     }
  869   
  870     private void jj_save(int index, int xla) {
  871       JJCalls p = jj_2_rtns[index];
  872       while (p.gen > jj_gen) {
  873         if (p.next == null) { p = p.next = new JJCalls(); break; }
  874         p = p.next;
  875       }
  876       p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
  877     }
  878   
  879     static final class JJCalls {
  880       int gen;
  881       Token first;
  882       int arg;
  883       JJCalls next;
  884     }
  885   
  886   }

Save This Page
Home » lucene-3.0.1-src » org.apache.lucene.queryParser.standard.parser » [javadoc | source]