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

com.sirolf2009.husk.dsl.CLI Maven / Gradle / Ivy

/* Generated By:JJTree&JavaCC: Do not edit this line. CLI.java */
package com.sirolf2009.husk.dsl;

public class CLI/*@bgen(jjtree)*/implements CLITreeConstants, CLIConstants {/*@bgen(jjtree)*/
  protected JJTCLIState jjtree = new JJTCLIState();
  public static void main(String args []) throws ParseException {
      parse("getFromDatabase 1 | parse report | print").dump(" >");
      parse("print").dump(" >");
  }

  public static SimpleNode parse(String command) throws ParseException {
    SimpleNode node = new CLI(new java.io.StringReader(command)).cliCommand();
    return node;
  }

  final public SimpleNode cliCommand() throws ParseException {
 /*@bgen(jjtree) cliCommand */
  SimpleNode jjtn000 = new SimpleNode(JJTCLICOMMAND);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case WORD:
        command();
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case PIPELINE:
          label_1:
          while (true) {
            jj_consume_token(PIPELINE);
            command();
            switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
            case PIPELINE:
              ;
              break;
            default:
              jj_la1[0] = jj_gen;
              break label_1;
            }
          }
          break;
        default:
          jj_la1[1] = jj_gen;
          ;
        }
        break;
      default:
        jj_la1[2] = jj_gen;
        ;
      }
      jj_consume_token(0);
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
        {if (true) return ((SimpleNode)jjtree.rootNode());}
    } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      {if (true) throw (RuntimeException)jjte000;}
    }
    if (jjte000 instanceof ParseException) {
      {if (true) throw (ParseException)jjte000;}
    }
    {if (true) throw (Error)jjte000;}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
    throw new Error("Missing return statement in function");
  }

  final public void pipelinedCommand() throws ParseException {
 /*@bgen(jjtree) pipelinedCommand */
  SimpleNode jjtn000 = new SimpleNode(JJTPIPELINEDCOMMAND);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      command();
      label_2:
      while (true) {
        jj_consume_token(PIPELINE);
        command();
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case PIPELINE:
          ;
          break;
        default:
          jj_la1[3] = jj_gen;
          break label_2;
        }
      }
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  final public void command() throws ParseException {
 /*@bgen(jjtree) command */
  SimpleNode jjtn000 = new SimpleNode(JJTCOMMAND);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      word();
      label_3:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case INTEGER_LITERAL:
        case LONG_LITERAL:
        case DOUBLE_POINT_LITERAL:
        case FLOATING_POINT_LITERAL:
        case WORD:
          ;
          break;
        default:
          jj_la1[4] = jj_gen;
          break label_3;
        }
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case INTEGER_LITERAL:
        case LONG_LITERAL:
        case DOUBLE_POINT_LITERAL:
        case FLOATING_POINT_LITERAL:
          number();
          break;
        case WORD:
          word();
          break;
        default:
          jj_la1[5] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
      }
    } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      {if (true) throw (RuntimeException)jjte000;}
    }
    if (jjte000 instanceof ParseException) {
      {if (true) throw (ParseException)jjte000;}
    }
    {if (true) throw (Error)jjte000;}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
  }

  final public Number number() throws ParseException {
 /*@bgen(jjtree) number */
  SimpleNode jjtn000 = new SimpleNode(JJTNUMBER);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);Number n;
    try {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case INTEGER_LITERAL:
        n = Integer();
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = n.intValue();
    {if (true) return n;}
        break;
      case LONG_LITERAL:
        n = Long();
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = n.longValue();
    {if (true) return n;}
        break;
      case FLOATING_POINT_LITERAL:
        n = Float();
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = n.floatValue();
    {if (true) return n;}
        break;
      case DOUBLE_POINT_LITERAL:
        n = Double();
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = n.doubleValue();
    {if (true) return n;}
        break;
      default:
        jj_la1[6] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      {if (true) throw (RuntimeException)jjte000;}
    }
    if (jjte000 instanceof ParseException) {
      {if (true) throw (ParseException)jjte000;}
    }
    {if (true) throw (Error)jjte000;}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
    throw new Error("Missing return statement in function");
  }

  final public double Double() throws ParseException {
 /*@bgen(jjtree) Double */
  SimpleNode jjtn000 = new SimpleNode(JJTDOUBLE);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);Token t;
    try {
      t = jj_consume_token(DOUBLE_POINT_LITERAL);
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = Double.parseDouble(t.image);
    {if (true) return Double.parseDouble(t.image);}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
    throw new Error("Missing return statement in function");
  }

  final public float Float() throws ParseException {
 /*@bgen(jjtree) Float */
  SimpleNode jjtn000 = new SimpleNode(JJTFLOAT);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);Token t;
    try {
      t = jj_consume_token(FLOATING_POINT_LITERAL);
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = Float.parseFloat(t.image);
    {if (true) return Float.parseFloat(t.image);}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
    throw new Error("Missing return statement in function");
  }

  final public int Integer() throws ParseException {
 /*@bgen(jjtree) Integer */
  SimpleNode jjtn000 = new SimpleNode(JJTINTEGER);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);Token t;
    try {
      t = jj_consume_token(INTEGER_LITERAL);
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = Integer.parseInt(t.image);
    {if (true) return Integer.parseInt(t.image);}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
    throw new Error("Missing return statement in function");
  }

  final public long Long() throws ParseException {
 /*@bgen(jjtree) Long */
  SimpleNode jjtn000 = new SimpleNode(JJTLONG);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);Token t;
    try {
      t = jj_consume_token(LONG_LITERAL);
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = Long.parseLong(t.image.replace("l", "").replace("L", ""));
    {if (true) return (long) jjtn000.value;}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
    throw new Error("Missing return statement in function");
  }

  final public String word() throws ParseException {
 /*@bgen(jjtree) word */
  SimpleNode jjtn000 = new SimpleNode(JJTWORD);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);String n;
  Token t;
    try {
      t = jj_consume_token(WORD);
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.value = t.image;
    {if (true) return t.image;}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
    throw new Error("Missing return statement in function");
  }

  /** Generated Token Manager. */
  public CLITokenManager 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[] {0x100000,0x100000,0x200000,0x100000,0x200c60,0x200c60,0xc60,};
   }

  /** Constructor with InputStream. */
  public CLI(java.io.InputStream stream) {
     this(stream, null);
  }
  /** Constructor with InputStream and supplied encoding */
  public CLI(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 CLITokenManager(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;
    jjtree.reset();
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  /** Constructor. */
  public CLI(java.io.Reader stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new CLITokenManager(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;
    jjtree.reset();
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  /** Constructor with generated Token Manager. */
  public CLI(CLITokenManager 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(CLITokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jjtree.reset();
    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[23];
    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