All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rbmhtechnology.vind.parser.queryparser.QueryParser Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
/* QueryParser.java */
/* Generated by: ParserGeneratorCC: Do not edit this line. QueryParser.java */
package com.rbmhtechnology.vind.parser.queryparser;

import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;

public class QueryParser implements QueryParserConstants {
    public Query run() throws ParseException {
        return query();
    }

  final public Query query() throws ParseException {Query q = new Query();Clause c;Token value;
    label_1:
    while (true) {
      if (jj_2_1(10)) {
      } else {
        break label_1;
      }
      c = expresion();
q.add(c);
    }
    label_2:
    while (true) {
      if (jj_2_2(10)) {
      } else {
        break label_2;
      }
      if (jj_2_3(10)) {
        value = jj_consume_token(TERM);
q.addText(value.image);
      } else if (jj_2_4(10)) {
        value = jj_consume_token(QUOTED_STRING);
q.addText(value.image);
      } else if (jj_2_5(10)) {
        value = jj_consume_token(AND);
q.addText(value.image);
      } else if (jj_2_6(10)) {
        value = jj_consume_token(OR);
q.addText(value.image);
      } else if (jj_2_7(10)) {
        value = jj_consume_token(NOT);
q.addText(value.image);
      } else if (jj_2_8(10)) {
        value = jj_consume_token(NUMBER_TERM);
q.addText(value.image);
      } else if (jj_2_9(10)) {
        jj_consume_token(MINUS);
      } else if (jj_2_10(10)) {
        jj_consume_token(PLUS);
      } else if (jj_2_11(10)) {
        jj_consume_token(WILDCARD);
      } else if (jj_2_12(10)) {
        jj_consume_token(LPAREN);
      } else if (jj_2_13(10)) {
        jj_consume_token(RPAREN);
      } else if (jj_2_14(10)) {
        jj_consume_token(LBRACKET);
      } else if (jj_2_15(10)) {
        jj_consume_token(RBRACKET);
      } else if (jj_2_16(10)) {
        jj_consume_token(LCBRACKET);
      } else if (jj_2_17(10)) {
        jj_consume_token(RCBRACKET);
      } else if (jj_2_18(10)) {
        jj_consume_token(SINGLE_QUOTE);
      } else if (jj_2_19(10)) {
        jj_consume_token(QUOTE);
      } else {
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
{if ("" != null) return q;}
    throw new IllegalStateException ("Missing return statement in function");
}

/********************** Literals **************************************************/
  final public 
Literal literal() throws ParseException {Literal literal;ArrayList literals = new ArrayList(); Token op=null;MultiBooleanLiteral boolLiteral;
    literal = literalClause();
literals.add(literal);
    label_3:
    while (true) {
      if (jj_2_20(10)) {
      } else {
        break label_3;
      }
      op = jj_consume_token(OR);
      literal = literalClause();
literals.add(literal);
    }
if( literals.size()==1) {
            {if ("" != null) return literal;}
        } else {
            boolLiteral = new MultiBooleanLiteral(op.image,literals.get(0),literals.get(1));
            for (int i = 2; i literals = new ArrayList(); Token op=null;MultiBooleanLiteral boolLiteral;
    literal = baseLiteral();
literals.add(literal);
    label_4:
    while (true) {
      if (jj_2_21(10)) {
      } else {
        break label_4;
      }
      op = jj_consume_token(AND);
      literal = baseLiteral();
literals.add(literal);
    }
if( literals.size()==1) {
            {if ("" != null) return literal;}
        } else {
            boolLiteral = new MultiBooleanLiteral(op.image,literals.get(0),literals.get(1));
            for (int i = 2; i clauses=new ArrayList();MultiBooleanClause boolClause;Token op=null;
    clause = clause();
clauses.add(clause);
    label_6:
    while (true) {
      if (jj_2_47(10)) {
      } else {
        break label_6;
      }
      op = jj_consume_token(OR);
      clause = clause();
clauses.add(clause);
    }
if( clauses.size()==1) {
            {if ("" != null) return clause;}
        } else {
            boolClause = new MultiBooleanClause(op.image,clauses.get(0),clauses.get(1));
            for (int i = 2; i clauses=new ArrayList();MultiBooleanClause boolClause;Token op=null;
    clause = baseClause();
clauses.add(clause);
    label_7:
    while (true) {
      if (jj_2_48(10)) {
      } else {
        break label_7;
      }
      op = jj_consume_token(AND);
      clause = baseClause();
clauses.add(clause);
    }
if( clauses.size()==1) {
            {if ("" != null) return clause;}
        } else {
            boolClause = new MultiBooleanClause(op.image,clauses.get(0),clauses.get(1));
            for (int i = 2; i 100) {
        jj_gc = 0;
        for (int i = 0; i < jj_2_rtns.length; i++) {
          JJCalls c = jj_2_rtns[i];
          while (c != null) {
            if (c.gen < jj_gen)
              c.first = null;
            c = c.next;
          }
        }
      }
      return token;
    }
    token = oldToken;
    jj_kind = kind;
    throw generateParseException();
  }

  private static final class LookaheadSuccess extends IllegalStateException {}
  private final LookaheadSuccess jj_ls = new LookaheadSuccess();
  private boolean jj_scan_token(int kind) {
	 if (jj_scanpos == jj_lastpos) {
	   jj_la--;
	   if (jj_scanpos.next == null) {
		   jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
	   } else {
		   jj_lastpos = jj_scanpos = jj_scanpos.next;
	   }
	 } else {
	   jj_scanpos = jj_scanpos.next;
	 }
	 if (jj_rescan) {
	   int i = 0; Token tok = token;
	   while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
	   if (tok != null) jj_add_error_token(kind, i);
	 }
	 if (jj_scanpos.kind != kind) return true;
	 if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
	 return false;
  }


  /**
   * @return the next Token.
   */
  public final Token getNextToken() {
   if (token.next != null)
     token = token.next;
   else
     token = token.next = token_source.getNextToken();
	 jj_ntk = -1;
	 jj_gen++;
	 return token;
  }

  /**
   * @param index index to be retrieved
   * @return the specific Token.
   */
  public final Token getToken(final int index) {
    Token t = token;
    for (int i = 0; i < index; i++) {
      if (t.next == null)
        t.next = token_source.getNextToken();
      t = t.next;
    }
    return t;
  }

  private int jj_ntk_f() {
    jj_nt = token.next;
    if (jj_nt == null) {
      token.next = token_source.getNextToken();
      jj_ntk = token.next.kind;
      return jj_ntk;
    }
    jj_ntk = jj_nt.kind;
    return jj_ntk;
  }

  private java.util.List jj_expentries = new java.util.ArrayList<>();
  private int[] jj_expentry;
  private int jj_kind = -1;
  private int[] jj_lasttokens = new int[100];
  private int jj_endpos;

  private void jj_add_error_token(int kind, int pos) {
  if (pos >= 100) {
    return;
  }

  if (pos == jj_endpos + 1) {
    jj_lasttokens[jj_endpos++] = kind;
  } else if (jj_endpos != 0) {
    jj_expentry = new int[jj_endpos];

    for (int i = 0; i < jj_endpos; i++) {
      jj_expentry[i] = jj_lasttokens[i];
    }

    for (final int[] oldentry : jj_expentries) {
      if (oldentry.length == jj_expentry.length) {
        boolean isMatched = true;
        for (int i = 0; i < jj_expentry.length; i++) {
          if (oldentry[i] != jj_expentry[i]) {
            isMatched = false;
            break;
          }
        }
        if (isMatched) {
          jj_expentries.add(jj_expentry);
          break;
        }
      }
    }

    if (pos != 0) {
      jj_endpos = pos;
      jj_lasttokens[jj_endpos - 1] = kind;
    }
  }
}

  /**
   * Generate ParseException.
   * @return new Exception object. Never null
   */
  public ParseException generateParseException() {
    jj_expentries.clear();
    boolean[] la1tokens = new boolean[23];
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 0; i++) {
      if (jj_la1[i] == jj_gen) {
        for (int j = 0; j < 32; j++) {
          if ((jj_la1_0[i] & (1<false.
   */
  public final boolean trace_enabled() {
    return false;
  }

  /** Enable tracing. */
  public final void enable_tracing() {}

  /** Disable tracing. */
  public final void disable_tracing() {}

  private void jj_rescan_token() {
    jj_rescan = true;
    for (int i = 0; i < 54; i++) {
      try {
        JJCalls p = jj_2_rtns[i];
        do {
          if (p.gen > jj_gen) {
            jj_la = p.arg;
            jj_scanpos = p.first;
            jj_lastpos = p.first;
            switch (i) {
              case 0: jj_3_1(); break;
              case 1: jj_3_2(); break;
              case 2: jj_3_3(); break;
              case 3: jj_3_4(); break;
              case 4: jj_3_5(); break;
              case 5: jj_3_6(); break;
              case 6: jj_3_7(); break;
              case 7: jj_3_8(); break;
              case 8: jj_3_9(); break;
              case 9: jj_3_10(); break;
              case 10: jj_3_11(); break;
              case 11: jj_3_12(); break;
              case 12: jj_3_13(); break;
              case 13: jj_3_14(); break;
              case 14: jj_3_15(); break;
              case 15: jj_3_16(); break;
              case 16: jj_3_17(); break;
              case 17: jj_3_18(); break;
              case 18: jj_3_19(); break;
              case 19: jj_3_20(); break;
              case 20: jj_3_21(); break;
              case 21: jj_3_22(); break;
              case 22: jj_3_23(); break;
              case 23: jj_3_24(); break;
              case 24: jj_3_25(); break;
              case 25: jj_3_26(); break;
              case 26: jj_3_27(); break;
              case 27: jj_3_28(); break;
              case 28: jj_3_29(); break;
              case 29: jj_3_30(); break;
              case 30: jj_3_31(); break;
              case 31: jj_3_32(); break;
              case 32: jj_3_33(); break;
              case 33: jj_3_34(); break;
              case 34: jj_3_35(); break;
              case 35: jj_3_36(); break;
              case 36: jj_3_37(); break;
              case 37: jj_3_38(); break;
              case 38: jj_3_39(); break;
              case 39: jj_3_40(); break;
              case 40: jj_3_41(); break;
              case 41: jj_3_42(); break;
              case 42: jj_3_43(); break;
              case 43: jj_3_44(); break;
              case 44: jj_3_45(); break;
              case 45: jj_3_46(); break;
              case 46: jj_3_47(); break;
              case 47: jj_3_48(); break;
              case 48: jj_3_49(); break;
              case 49: jj_3_50(); break;
              case 50: jj_3_51(); break;
              case 51: jj_3_52(); break;
              case 52: jj_3_53(); break;
              case 53: jj_3_54(); break;
            }
          }
          p = p.next;
        } while (p != null);
      } catch(LookaheadSuccess ls) { /* ignore */ }
    }
    jj_rescan = false;
  }

  private void jj_save(int index, int xla) {
    JJCalls p = jj_2_rtns[index];
    while (p.gen > jj_gen) {
      if (p.next == null) {
        p.next = new JJCalls();
        p = p.next;
        break;
      }
      p = p.next;
    }
    p.gen = jj_gen + xla - jj_la; 
    p.first = token;
    p.arg = xla;
  }

  static final class JJCalls {
	 int gen;
	 Token first;
	 int arg;
	 JJCalls next;
  }

};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy