A {@link Parser} that tries each alternative parser in {@code alternatives}.

<p> Different than {@link #alt(Parser[])}, it requires all alternative parsers to have
type {@code T}.
183832
public static <T> Parser<T> or(final Parser<? extends T>... alternatives) {
    if (alternatives.length == 0) return never();
    if (alternatives.length == 1) return alternatives[0].cast();
    return new Parser<T>() {
      @Override boolean apply(ParseContext ctxt) {
        final Object result = ctxt.result;
        final int at = ctxt.at;
        final int step = ctxt.step;
        for(Parser<? extends T> p : alternatives) {
          if (p.apply(ctxt)) {
            return true;
          }
          ctxt.set(step, at, result);
        }
        return false;
      }
      @Override public String toString() {
        return "or";
      }
    };
  }
456990
final public void Or() throws ParseException {
    And();
    label_7:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case OR0:
      case OR1:
        ;
        break;
      default:
        jj_la1[10] = jj_gen;
        break label_7;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case OR0:
        jj_consume_token(OR0);
        break;
      case OR1:
        jj_consume_token(OR1);
        break;
      default:
        jj_la1[11] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
                           AstOr jjtn001 = new AstOr(JJTOR);
                           boolean jjtc001 = true;
                           jjtree.openNodeScope(jjtn001);
      try {
        And();
      } catch (Throwable jjte001) {
                           if (jjtc001) {
                             jjtree.clearNodeScope(jjtn001);
                             jjtc001 = false;
                           } else {
                             jjtree.popNode();
                           }
                           if (jjte001 instanceof RuntimeException) {
                             {if (true) throw (RuntimeException)jjte001;}
                           }
                           if (jjte001 instanceof ParseException) {
                             {if (true) throw (ParseException)jjte001;}
                           }
                           {if (true) throw (Error)jjte001;}
      } finally {
                           if (jjtc001) {
                             jjtree.closeNodeScope(jjtn001,  2);
                           }
      }
    }
  }
773376
private void parseArgs(MessageArgsParser parser) {
    while (tag.peek() != Chars.EOF) {
      tag.skip(COMMA_WS);

      // Look for the argument key
      if (!tag.seek(IDENTIFIER, choice)) {
        return;
      }

      // Parse the <key>(:<value>)? sequence
      String key = choice.toString();
      tag.jump(choice);
      if (tag.seek(ARG_SEP, choice)) {
        tag.jump(choice);
        if (tag.seek(ARG_VAL, choice)) {
          tag.jump(choice);
          parser.set(key, choice.toString());
        } else {
          parser.set(key, "");
        }
      } else {
        parser.set(key, "");
        if (!tag.seek(COMMA_WS, choice)) {
          return;
        }
      }
    }
  }
1055902
public final void typeParameter() throws RecognitionException {
		int typeParameter_StartIndex = input.index();

		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 9) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:310:5: ( Identifier ( 'extends' bound )? )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:310:7: Identifier ( 'extends' bound )?
			{
			match(input,Identifier,FOLLOW_Identifier_in_typeParameter363); if (state.failed) return;
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:310:18: ( 'extends' bound )?
			int alt16=2;
			int LA16_0 = input.LA(1);
			if ( (LA16_0==81) ) {
				alt16=1;
			}
			switch (alt16) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:310:19: 'extends' bound
					{
					match(input,81,FOLLOW_81_in_typeParameter366); if (state.failed) return;
					pushFollow(FOLLOW_bound_in_typeParameter368);
					bound();
					state._fsp--;
					if (state.failed) return;
					}
					break;

			}

			}

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 9, typeParameter_StartIndex); }

		}
	}
410684
public void setParser(RtfParser parser) {
		if(this.rtfParser != null && this.rtfParser.equals(parser)) return;
		this.rtfParser = parser;
	}
795837
public final <R> Parser<R> retn(R value) {
    return next(Parsers.constant(value));
  }
1343069
@SuppressWarnings("unchecked")
    @NotNull
    public final Parser<Object> getParser() {
        if (parser != null) {
            return parser;
        }
        LOG.info("Creating parser: {}", className);
        if (className == null) {
            throw new IllegalStateException("Class name was not set: " + getName());
        }
        if (context == null) {
            throw new IllegalStateException("Context class loader was not set: " + getName() + " / " + className);
        }
        final Object obj = Utils4J.createInstance(className, context.getClassLoader());
        if (!(obj instanceof Parser<?>)) {
            throw new IllegalStateException("Expected class to be of type '" + Parser.class.getName() + "', but was: " + className);
        }
        parser = (Parser<Object>) obj;
        parser.initialize(context, this);
        return parser;
    }
236833
public final Parser<?> not(String unexpected) {
    return peek().ifelse(Parsers.unexpected(unexpected), Parsers.always());
  }
290721
public final void normalInterfaceDeclaration() throws RecognitionException {
		int normalInterfaceDeclaration_StartIndex = input.index();

		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 17) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:343:5: ( 'interface' Identifier ( typeParameters )? ( 'extends' typeList )? interfaceBody )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:343:7: 'interface' Identifier ( typeParameters )? ( 'extends' typeList )? interfaceBody
			{
			match(input,93,FOLLOW_93_in_normalInterfaceDeclaration572); if (state.failed) return;
			match(input,Identifier,FOLLOW_Identifier_in_normalInterfaceDeclaration574); if (state.failed) return;
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:343:30: ( typeParameters )?
			int alt28=2;
			int LA28_0 = input.LA(1);
			if ( (LA28_0==53) ) {
				alt28=1;
			}
			switch (alt28) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:343:30: typeParameters
					{
					pushFollow(FOLLOW_typeParameters_in_normalInterfaceDeclaration576);
					typeParameters();
					state._fsp--;
					if (state.failed) return;
					}
					break;

			}

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:343:46: ( 'extends' typeList )?
			int alt29=2;
			int LA29_0 = input.LA(1);
			if ( (LA29_0==81) ) {
				alt29=1;
			}
			switch (alt29) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:343:47: 'extends' typeList
					{
					match(input,81,FOLLOW_81_in_normalInterfaceDeclaration580); if (state.failed) return;
					pushFollow(FOLLOW_typeList_in_normalInterfaceDeclaration582);
					typeList();
					state._fsp--;
					if (state.failed) return;
					}
					break;

			}

			pushFollow(FOLLOW_interfaceBody_in_normalInterfaceDeclaration586);
			interfaceBody();
			state._fsp--;
			if (state.failed) return;
			}

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 17, normalInterfaceDeclaration_StartIndex); }

		}
	}
532599
public final void addParser(@NotNull final ParserConfig parser) {
        Contract.requireArgNotNull("parser", parser);
        if (list == null) {
            list = new ArrayList<>();
        }
        list.add(parser);
    }
238943
public static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2) {
    return alt(p1, p2).cast();
  }
1127863
static BaseTypeSignature parse(final Parser parser) {
        switch (parser.peek()) {
        case 'B':
            parser.next();
            return new BaseTypeSignature("byte");
        case 'C':
            parser.next();
            return new BaseTypeSignature("char");
        case 'D':
            parser.next();
            return new BaseTypeSignature("double");
        case 'F':
            parser.next();
            return new BaseTypeSignature("float");
        case 'I':
            parser.next();
            return new BaseTypeSignature("int");
        case 'J':
            parser.next();
            return new BaseTypeSignature("long");
        case 'S':
            parser.next();
            return new BaseTypeSignature("short");
        case 'Z':
            parser.next();
            return new BaseTypeSignature("boolean");
        case 'V':
            parser.next();
            return new BaseTypeSignature("void");
        default:
            return null;
        }
    }
804064
public Parser<T> label(final String name) {
    return new Parser<T>() {
      @Override public Parser<T> label(String overrideName) {
        return Parser.this.label(overrideName);
      }
      @Override boolean apply(ParseContext ctxt) {
        return ctxt.applyNewNode(Parser.this, name);
      }
      @Override public String toString() {
        return name;
      }
    };
  }
354802
@SuppressWarnings({"unchecked", "rawtypes"})
  @Private static <T> Parser<T>[] toArray(Iterable<? extends Parser<? extends T>> parsers) {
    if (parsers instanceof Collection<?>) {
      return toArray((Collection) parsers);
    }
    return toArrayWithIteration(parsers);
  }
464617
public final <R> Parser<R> ifelse(
      final Function<? super T, ? extends Parser<? extends R>> consequence,
      final Parser<? extends R> alternative) {
    return new Parser<R>() {
      @Override boolean apply(ParseContext ctxt) {
        final Object ret = ctxt.result;
        final int step = ctxt.step;
        final int at = ctxt.at;
        if (ctxt.withErrorSuppressed(Parser.this)) {
          Parser<? extends R> parser = consequence.apply(Parser.this.getReturn(ctxt));
          return parser.apply(ctxt);
        }
        ctxt.set(step, at, ret);
        return alternative.apply(ctxt);
      }
      @Override public String toString() {
        return "ifelse";
      }
    };
  }
1084609
public final QueryParser.t_return t() throws RecognitionException {
        QueryParser.t_return retval = new QueryParser.t_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token string_literal84=null;

        CommonTree string_literal84_tree=null;

        try {
            // src/riemann/Query.g:71:3: ( 'true' )
            // src/riemann/Query.g:71:5: 'true'
            {
            root_0 = (CommonTree)adaptor.nil();

            string_literal84=(Token)match(input,27,FOLLOW_27_in_t552); 
            string_literal84_tree = (CommonTree)adaptor.create(string_literal84);
            adaptor.addChild(root_0, string_literal84_tree);


            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
821828
public final TypeParser.typeParameterization_return typeParameterization() throws RecognitionException {
        TypeParser.typeParameterization_return retval = new TypeParser.typeParameterization_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token UNKNOWN8=null;
        Token UNKNOWN9=null;
        Token EXTENDS10=null;
        Token UNKNOWN11=null;
        Token SUPER12=null;
        TypeParser.typeExpression_return typExp = null;

        TypeParser.typeExpression_return typeExpression7 = null;


        CommonTree UNKNOWN8_tree=null;
        CommonTree UNKNOWN9_tree=null;
        CommonTree EXTENDS10_tree=null;
        CommonTree UNKNOWN11_tree=null;
        CommonTree SUPER12_tree=null;
        RewriteRuleTokenStream stream_SUPER=new RewriteRuleTokenStream(adaptor,"token SUPER");
        RewriteRuleTokenStream stream_UNKNOWN=new RewriteRuleTokenStream(adaptor,"token UNKNOWN");
        RewriteRuleTokenStream stream_EXTENDS=new RewriteRuleTokenStream(adaptor,"token EXTENDS");
        RewriteRuleSubtreeStream stream_typeExpression=new RewriteRuleSubtreeStream(adaptor,"rule typeExpression");
        try {
            // org/javaruntype/type/parser/Type.g:112:5: ( typeExpression | UNKNOWN | UNKNOWN EXTENDS typExp= typeExpression -> ^( EXT $typExp) | UNKNOWN SUPER typExp= typeExpression -> ^( SUP $typExp) )
            int alt5=4;
            int LA5_0 = input.LA(1);

            if ( (LA5_0==CLASSNAME) ) {
                alt5=1;
            }
            else if ( (LA5_0==UNKNOWN) ) {
                switch ( input.LA(2) ) {
                case EXTENDS:
                    {
                    alt5=3;
                    }
                    break;
                case SUPER:
                    {
                    alt5=4;
                    }
                    break;
                case ENDTYPEPARAM:
                case COMMA:
                    {
                    alt5=2;
                    }
                    break;
                default:
                    NoViableAltException nvae =
                        new NoViableAltException("", 5, 2, input);

                    throw nvae;
                }

            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 5, 0, input);

                throw nvae;
            }
            switch (alt5) {
                case 1 :
                    // org/javaruntype/type/parser/Type.g:112:7: typeExpression
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    pushFollow(FOLLOW_typeExpression_in_typeParameterization291);
                    typeExpression7=typeExpression();

                    state._fsp--;

                    adaptor.addChild(root_0, typeExpression7.getTree());

                    }
                    break;
                case 2 :
                    // org/javaruntype/type/parser/Type.g:113:7: UNKNOWN
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    UNKNOWN8=(Token)match(input,UNKNOWN,FOLLOW_UNKNOWN_in_typeParameterization299); 
                    UNKNOWN8_tree = (CommonTree)adaptor.create(UNKNOWN8);
                    adaptor.addChild(root_0, UNKNOWN8_tree);


                    }
                    break;
                case 3 :
                    // org/javaruntype/type/parser/Type.g:114:7: UNKNOWN EXTENDS typExp= typeExpression
                    {
                    UNKNOWN9=(Token)match(input,UNKNOWN,FOLLOW_UNKNOWN_in_typeParameterization307);  
                    stream_UNKNOWN.add(UNKNOWN9);

                    EXTENDS10=(Token)match(input,EXTENDS,FOLLOW_EXTENDS_in_typeParameterization309);  
                    stream_EXTENDS.add(EXTENDS10);

                    pushFollow(FOLLOW_typeExpression_in_typeParameterization313);
                    typExp=typeExpression();

                    state._fsp--;

                    stream_typeExpression.add(typExp.getTree());


                    // AST REWRITE
                    // elements: typExp
                    // token labels: 
                    // rule labels: retval, typExp
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);
                    RewriteRuleSubtreeStream stream_typExp=new RewriteRuleSubtreeStream(adaptor,"rule typExp",typExp!=null?typExp.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 114:45: -> ^( EXT $typExp)
                    {
                        // org/javaruntype/type/parser/Type.g:114:48: ^( EXT $typExp)
                        {
                        CommonTree root_1 = (CommonTree)adaptor.nil();
                        root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(EXT, "EXT"), root_1);

                        adaptor.addChild(root_1, stream_typExp.nextTree());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;
                    }
                    break;
                case 4 :
                    // org/javaruntype/type/parser/Type.g:115:7: UNKNOWN SUPER typExp= typeExpression
                    {
                    UNKNOWN11=(Token)match(input,UNKNOWN,FOLLOW_UNKNOWN_in_typeParameterization330);  
                    stream_UNKNOWN.add(UNKNOWN11);

                    SUPER12=(Token)match(input,SUPER,FOLLOW_SUPER_in_typeParameterization332);  
                    stream_SUPER.add(SUPER12);

                    pushFollow(FOLLOW_typeExpression_in_typeParameterization336);
                    typExp=typeExpression();

                    state._fsp--;

                    stream_typeExpression.add(typExp.getTree());


                    // AST REWRITE
                    // elements: typExp
                    // token labels: 
                    // rule labels: retval, typExp
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);
                    RewriteRuleSubtreeStream stream_typExp=new RewriteRuleSubtreeStream(adaptor,"rule typExp",typExp!=null?typExp.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 115:43: -> ^( SUP $typExp)
                    {
                        // org/javaruntype/type/parser/Type.g:115:46: ^( SUP $typExp)
                        {
                        CommonTree root_1 = (CommonTree)adaptor.nil();
                        root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(SUP, "SUP"), root_1);

                        adaptor.addChild(root_1, stream_typExp.nextTree());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;
                    }
                    break;

            }
            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }

            catch (RecognitionException e) {
            	throw e;
            }
        finally {
        }
        return retval;
    }