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

net.optionfactory.csv.parser.javacc.TabCsvParser Maven / Gradle / Ivy

The newest version!
/* Generated By:JavaCC: Do not edit this line. TabCsvParser.java */
package net.optionfactory.csv.parser.javacc;

import net.optionfactory.csv.parser.CsvParser.Trimming;
import net.optionfactory.csv.parser.CsvParserSpi;
import net.optionfactory.csv.parser.CsvParserSpi.Record;

public class TabCsvParser implements CsvParserSpi, TabCsvParserConstants {

  public Token skipToNextRecord() throws ParseException {
    Token t;
    do { t = getNextToken(); } while (t.kind != EOL && t.kind != EOF);
    return t;
  }

  final public Record record(Trimming trimming) throws ParseException {
    Record out = Record.empty(this.token.beginLine, this.token.beginColumn);
    String current = null;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case START_QUOTE:
    case TEXTDATA:
      current = field(trimming);
      break;
    default:
      jj_la1[0] = jj_gen;
      ;
    }
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case FIELD_DELIMITER:
        ;
        break;
      default:
        jj_la1[1] = jj_gen;
        break label_1;
      }
      jj_consume_token(FIELD_DELIMITER);
                            add(out, current == null ? "" : current); current = "";
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case START_QUOTE:
      case TEXTDATA:
        current = field(trimming);
        break;
      default:
        jj_la1[2] = jj_gen;
        ;
      }
    }
      add(out, current);
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case EOL:
      jj_consume_token(EOL);
                  out.source.endLine = this.token.endLine; out.source.endColumn = this.token.endColumn; {if (true) return out;}
      break;
    case 0:
      jj_consume_token(0);
                  out.source.endLine = this.token.endLine; out.source.endColumn = this.token.endColumn; {if (true) return out.values.isEmpty() ? null : out;}
      break;
    default:
      jj_la1[3] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    throw new Error("Missing return statement in function");
  }

  final public String field(Trimming trimming) throws ParseException {
    final StringBuilder sb = new StringBuilder();
    final String out;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case START_QUOTE:
      jj_consume_token(START_QUOTE);
      label_2:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case QUOTED_QUOTE:
        case QUOTED_TEXTDATA:
          ;
          break;
        default:
          jj_la1[4] = jj_gen;
          break label_2;
        }
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case QUOTED_QUOTE:
          jj_consume_token(QUOTED_QUOTE);
                                     sb.append('"');
          break;
        case QUOTED_TEXTDATA:
          jj_consume_token(QUOTED_TEXTDATA);
                                     sb.append(this.token.image);
          break;
        default:
          jj_la1[5] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
      }
      jj_consume_token(END_QUOTE);
             out = trimming == Trimming.Always ? sb.toString().trim() : sb.toString();
      break;
    case TEXTDATA:
      jj_consume_token(TEXTDATA);
                       out = trimming == Trimming.Never ? this.token.image: this.token.image.trim();
      break;
    default:
      jj_la1[6] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
      {if (true) return out;}
    throw new Error("Missing return statement in function");
  }

  /** Generated Token Manager. */
  public TabCsvParserTokenManager token_source;
  SimpleCharStream jj_input_stream;
  /** Current token. */
  public Token token;
  /** Next token. */
  public Token jj_nt;
  private int jj_ntk;
  private int jj_gen;
  final private int[] jj_la1 = new int[7];
  static private int[] jj_la1_0;
  static {
      jj_la1_init_0();
   }
   private static void jj_la1_init_0() {
      jj_la1_0 = new int[] {0x18,0x2,0x18,0x5,0x140,0x140,0x18,};
   }

  /** Constructor with InputStream. */
  public TabCsvParser(java.io.InputStream stream) {
     this(stream, null);
  }
  /** Constructor with InputStream and supplied encoding */
  public TabCsvParser(java.io.InputStream stream, String encoding) {
    try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
    token_source = new TabCsvParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  public void ReInit(java.io.InputStream stream) {
     ReInit(stream, null);
  }
  /** Reinitialise. */
  public void ReInit(java.io.InputStream stream, String encoding) {
    try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
    token_source.ReInit(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  /** Constructor. */
  public TabCsvParser(java.io.Reader stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new TabCsvParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  public void ReInit(java.io.Reader stream) {
    jj_input_stream.ReInit(stream, 1, 1);
    token_source.ReInit(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  /** Constructor with generated Token Manager. */
  public TabCsvParser(TabCsvParserTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  public void ReInit(TabCsvParserTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  private Token jj_consume_token(int kind) throws ParseException {
    Token oldToken;
    if ((oldToken = token).next != null) token = token.next;
    else token = token.next = token_source.getNextToken();
    jj_ntk = -1;
    if (token.kind == kind) {
      jj_gen++;
      return token;
    }
    token = oldToken;
    jj_kind = kind;
    throw generateParseException();
  }


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

/** Get the specific Token. */
  final public Token getToken(int index) {
    Token t = token;
    for (int i = 0; i < index; i++) {
      if (t.next != null) t = t.next;
      else t = t.next = token_source.getNextToken();
    }
    return t;
  }

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

  private java.util.List jj_expentries = new java.util.ArrayList();
  private int[] jj_expentry;
  private int jj_kind = -1;

  /** Generate ParseException. */
  public ParseException generateParseException() {
    jj_expentries.clear();
    boolean[] la1tokens = new boolean[9];
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 7; i++) {
      if (jj_la1[i] == jj_gen) {
        for (int j = 0; j < 32; j++) {
          if ((jj_la1_0[i] & (1<




© 2015 - 2025 Weber Informatics LLC | Privacy Policy