/* Generated By: FragmentGrammar.jj,v 1.8 2010/11/02 08&JavaCC: Do not edit this line. FragmentParser.java */
import java.io.StringReader;
import java.io.IOException;

public class FragmentParser implements FragmentParserConstants {

    FragmentParser() {
    }

    public static void main(String args[]) {
        if (args.length < 1) {
            System.err.println("Not enought parameters");
            System.exit(1);
        }
        for (int i=0; i< args.length; i++) {
            String param = args[i];
            System.out.println("Checking: "+param);
            if (param.indexOf("#") >= 0) {
                param = param.substring(param.indexOf("#")+1);
            } else if (param.indexOf("?") >= 0) {
                param = param.substring(param.indexOf("?")+1);
            }
            StringReader sr = new StringReader(param);
            try {
                new FragmentParser(sr).parserUnit();
                System.out.println("OK");
            } catch (Exception ex) {
                System.out.println("failed");
            }
        }
    }

////////////////////////////////////////////////////////////////////
//                     End of Lexical Scanner                     // 
////////////////////////////////////////////////////////////////////
  final public void pdigit() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case DIGIT:
      jj_consume_token(DIGIT);
      break;
    case PDIGIT:
      jj_consume_token(PDIGIT);
      break;
    default:
      jj_la1[0] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void utf8string() throws ParseException {
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case UNRESERVED:
        jj_consume_token(UNRESERVED);
        break;
      case PCT_ENCODED:
        jj_consume_token(PCT_ENCODED);
        break;
      case TIMEPREFIX:
        jj_consume_token(TIMEPREFIX);
        break;
      case TIMEUNIT:
        jj_consume_token(TIMEUNIT);
        break;
      case DEFTIMEFORMAT:
        jj_consume_token(DEFTIMEFORMAT);
        break;
      case XYWHPREFIX:
        jj_consume_token(XYWHPREFIX);
        break;
      case XYWHUNIT:
        jj_consume_token(XYWHUNIT);
        break;
      case TRACKPREFIX:
        jj_consume_token(TRACKPREFIX);
        break;
      case NAMEPREFIX:
        jj_consume_token(NAMEPREFIX);
        break;
      case DIGIT:
        jj_consume_token(DIGIT);
        break;
      case PDIGIT:
        jj_consume_token(PDIGIT);
        break;
      default:
        jj_la1[1] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case TIMEPREFIX:
      case TIMEUNIT:
      case DEFTIMEFORMAT:
      case XYWHPREFIX:
      case XYWHUNIT:
      case TRACKPREFIX:
      case NAMEPREFIX:
      case DIGIT:
      case PDIGIT:
      case UNRESERVED:
      case PCT_ENCODED:
        ;
        break;
      default:
        jj_la1[2] = jj_gen;
        break label_1;
      }
    }
  }

  final public void parserUnit() throws ParseException {
    mediasegment();
    jj_consume_token(0);
  }

  final public void mediasegment() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case NAMEPREFIX:
      namesegment();
      break;
    case TIMEPREFIX:
    case XYWHPREFIX:
    case TRACKPREFIX:
      axissegment();
      break;
    default:
      jj_la1[3] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void namesegment() throws ParseException {
    jj_consume_token(NAMEPREFIX);
    jj_consume_token(EQ);
    nameparam();
  }

  final public void nameparam() throws ParseException {
    utf8string();
  }

  final public void axissegment() throws ParseException {
    boolean gottime  = false;
    boolean gotspace = false;
    boolean gottrack = false;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case TIMEPREFIX:
      timesegment();
                      gottime = true;
      break;
    case XYWHPREFIX:
      spacesegment();
                         gotspace = true;
      break;
    case TRACKPREFIX:
      tracksegment();
                         gottrack = true;
      break;
    default:
      jj_la1[4] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case AMP:
        ;
        break;
      default:
        jj_la1[5] = jj_gen;
        break label_2;
      }
      jj_consume_token(AMP);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case TIMEPREFIX:
        timesegment();
                                  if (gottime) {if (true) throw new ParseException();} gottime = true;
        break;
      case XYWHPREFIX:
        spacesegment();
                                     if (gotspace) {if (true) throw new ParseException();} gotspace = true;
        break;
      case TRACKPREFIX:
        tracksegment();
                                     if (gottrack) {if (true) throw new ParseException();} gottrack = true;
        break;
      default:
        jj_la1[6] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
  }

  final public void timesegment() throws ParseException {
    jj_consume_token(TIMEPREFIX);
    jj_consume_token(EQ);
    timeparam();
  }

  final public void timeparam() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case DEFTIMEFORMAT:
    case COMMA:
    case DIGIT:
    case PDIGIT:
      npttimedef();
      break;
    case TIMEFORMAT:
      othertimedef();
      break;
    default:
      jj_la1[7] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void npttimedef() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case DEFTIMEFORMAT:
      jj_consume_token(DEFTIMEFORMAT);
      jj_consume_token(COLON);
      break;
    default:
      jj_la1[8] = jj_gen;
      ;
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case DIGIT:
    case PDIGIT:
      clocktime();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case COMMA:
        jj_consume_token(COMMA);
        clocktime();
        break;
      default:
        jj_la1[9] = jj_gen;
        ;
      }
      break;
    case COMMA:
      jj_consume_token(COMMA);
      clocktime();
      break;
    default:
      jj_la1[10] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void clocktime() throws ParseException {
    label_3:
    while (true) {
      pdigit();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DIGIT:
      case PDIGIT:
        ;
        break;
      default:
        jj_la1[11] = jj_gen;
        break label_3;
      }
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case COLON:
    case DOT:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DOT:
        jj_consume_token(DOT);
        label_4:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case DIGIT:
          case PDIGIT:
            ;
            break;
          default:
            jj_la1[12] = jj_gen;
            break label_4;
          }
          pdigit();
        }
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case TIMEUNIT:
          jj_consume_token(TIMEUNIT);
          break;
        default:
          jj_la1[13] = jj_gen;
          ;
        }
        break;
      case COLON:
        jj_consume_token(COLON);
        pdigit();
        pdigit();
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case COLON:
          jj_consume_token(COLON);
          pdigit();
          pdigit();
          break;
        default:
          jj_la1[14] = jj_gen;
          ;
        }
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case DOT:
          jj_consume_token(DOT);
          label_5:
          while (true) {
            switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
            case DIGIT:
            case PDIGIT:
              ;
              break;
            default:
              jj_la1[15] = jj_gen;
              break label_5;
            }
            pdigit();
          }
          break;
        default:
          jj_la1[16] = jj_gen;
          ;
        }
        break;
      default:
        jj_la1[17] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      break;
    default:
      jj_la1[18] = jj_gen;
      ;
    }
  }

  final public void othertimedef() throws ParseException {
    jj_consume_token(TIMEFORMAT);
    jj_consume_token(COLON);
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case DIGIT:
    case PDIGIT:
      frametime();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case COMMA:
        jj_consume_token(COMMA);
        frametime();
        break;
      default:
        jj_la1[19] = jj_gen;
        ;
      }
      break;
    case COMMA:
      jj_consume_token(COMMA);
      frametime();
      break;
    default:
      jj_la1[20] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void frametime() throws ParseException {
    label_6:
    while (true) {
      pdigit();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DIGIT:
      case PDIGIT:
        ;
        break;
      default:
        jj_la1[21] = jj_gen;
        break label_6;
      }
    }
    jj_consume_token(COLON);
    pdigit();
    pdigit();
    jj_consume_token(COLON);
    pdigit();
    pdigit();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case COLON:
      jj_consume_token(COLON);
      pdigit();
      pdigit();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DOT:
        jj_consume_token(DOT);
        pdigit();
        pdigit();
        break;
      default:
        jj_la1[22] = jj_gen;
        ;
      }
      break;
    default:
      jj_la1[23] = jj_gen;
      ;
    }
  }

  final public void spacesegment() throws ParseException {
    xywhdef();
  }

  final public void xywhdef() throws ParseException {
    jj_consume_token(XYWHPREFIX);
    jj_consume_token(EQ);
    xywhparam();
  }

  final public void xywhparam() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case XYWHUNIT:
      jj_consume_token(XYWHUNIT);
      jj_consume_token(COLON);
      break;
    default:
      jj_la1[24] = jj_gen;
      ;
    }
    label_7:
    while (true) {
      pdigit();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DIGIT:
      case PDIGIT:
        ;
        break;
      default:
        jj_la1[25] = jj_gen;
        break label_7;
      }
    }
    jj_consume_token(COMMA);
    label_8:
    while (true) {
      pdigit();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DIGIT:
      case PDIGIT:
        ;
        break;
      default:
        jj_la1[26] = jj_gen;
        break label_8;
      }
    }
    jj_consume_token(COMMA);
    label_9:
    while (true) {
      pdigit();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DIGIT:
      case PDIGIT:
        ;
        break;
      default:
        jj_la1[27] = jj_gen;
        break label_9;
      }
    }
    jj_consume_token(COMMA);
    label_10:
    while (true) {
      pdigit();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DIGIT:
      case PDIGIT:
        ;
        break;
      default:
        jj_la1[28] = jj_gen;
        break label_10;
      }
    }
  }

  final public void tracksegment() throws ParseException {
    jj_consume_token(TRACKPREFIX);
    jj_consume_token(EQ);
    trackparam();
  }

  final public void trackparam() throws ParseException {
    utf8string();
  }

  /** Generated Token Manager. */
  public FragmentParserTokenManager 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[29];
  static private int[] jj_la1_0;
  static {
      jj_la1_init_0();
   }
   private static void jj_la1_init_0() {
      jj_la1_0 = new int[] {0x28000,0xe81ee,0xe81ee,0x1a2,0xa2,0x800,0xa2,0x29018,0x8,0x1000,0x29000,0x28000,0x28000,0x4,0x200,0x28000,0x2000,0x2200,0x2200,0x1000,0x29000,0x28000,0x2000,0x200,0x40,0x28000,0x28000,0x28000,0x28000,};
   }

  /** Constructor with InputStream. */
  public FragmentParser(java.io.InputStream stream) {
     this(stream, null);
  }
  /** Constructor with InputStream and supplied encoding */
  public FragmentParser(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 FragmentParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 29; 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 < 29; i++) jj_la1[i] = -1;
  }

  /** Constructor. */
  public FragmentParser(java.io.Reader stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new FragmentParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 29; 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 < 29; i++) jj_la1[i] = -1;
  }

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

  /** Reinitialise. */
  public void ReInit(FragmentParserTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 29; 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<int[]> jj_expentries = new java.util.ArrayList<int[]>();
  private int[] jj_expentry;
  private int jj_kind = -1;

  /** Generate ParseException. */
  public ParseException generateParseException() {
    jj_expentries.clear();
    boolean[] la1tokens = new boolean[21];
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 29; i++) {
      if (jj_la1[i] == jj_gen) {
        for (int j = 0; j < 32; j++) {
          if ((jj_la1_0[i] & (1<<j)) != 0) {
            la1tokens[j] = true;
          }
        }
      }
    }
    for (int i = 0; i < 21; i++) {
      if (la1tokens[i]) {
        jj_expentry = new int[1];
        jj_expentry[0] = i;
        jj_expentries.add(jj_expentry);
      }
    }
    int[][] exptokseq = new int[jj_expentries.size()][];
    for (int i = 0; i < jj_expentries.size(); i++) {
      exptokseq[i] = jj_expentries.get(i);
    }
    return new ParseException(token, exptokseq, tokenImage);
  }

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

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

}
