$ANTLR start "WHEN"
503907
public final void mWHEN() throws RecognitionException {
		try {
			int _type = WHEN;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// hql.g:70:6: ( 'when' )
			// hql.g:70:8: 'when'
			{
			match("when"); if (state.failed) return;

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
681918
public void mTokens() throws RecognitionException {
        // /home/victor/srec/core/src/main/antlr/srec.g:1:8: ( T__28 | T__29 | T__30 | T__31 | T__32 | T__33 | T__34 | BOOLEAN | NULL | ID | NUMBER | STRING | WS | NEWLINE | COMMENT )
        int alt12=15;
        alt12 = dfa12.predict(input);
        switch (alt12) {
            case 1 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:10: T__28
                {
                mT__28(); 

                }
                break;
            case 2 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:16: T__29
                {
                mT__29(); 

                }
                break;
            case 3 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:22: T__30
                {
                mT__30(); 

                }
                break;
            case 4 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:28: T__31
                {
                mT__31(); 

                }
                break;
            case 5 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:34: T__32
                {
                mT__32(); 

                }
                break;
            case 6 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:40: T__33
                {
                mT__33(); 

                }
                break;
            case 7 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:46: T__34
                {
                mT__34(); 

                }
                break;
            case 8 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:52: BOOLEAN
                {
                mBOOLEAN(); 

                }
                break;
            case 9 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:60: NULL
                {
                mNULL(); 

                }
                break;
            case 10 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:65: ID
                {
                mID(); 

                }
                break;
            case 11 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:68: NUMBER
                {
                mNUMBER(); 

                }
                break;
            case 12 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:75: STRING
                {
                mSTRING(); 

                }
                break;
            case 13 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:82: WS
                {
                mWS(); 

                }
                break;
            case 14 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:85: NEWLINE
                {
                mNEWLINE(); 

                }
                break;
            case 15 :
                // /home/victor/srec/core/src/main/antlr/srec.g:1:93: COMMENT
                {
                mCOMMENT(); 

                }
                break;

        }

    }
7609
public final void mCOMMENT() throws RecognitionException {
        try {
            int _type = COMMENT;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // /home/victor/srec/core/src/main/antlr/srec.g:155:2: ( '#' ( . )* NEWLINE )
            // /home/victor/srec/core/src/main/antlr/srec.g:155:4: '#' ( . )* NEWLINE
            {
            match('#'); 
            // /home/victor/srec/core/src/main/antlr/srec.g:155:8: ( . )*
            loop11:
            do {
                int alt11=2;
                int LA11_0 = input.LA(1);

                if ( (LA11_0=='\r') ) {
                    alt11=2;
                }
                else if ( (LA11_0=='\n') ) {
                    alt11=2;
                }
                else if ( ((LA11_0>='\u0000' && LA11_0<='\t')||(LA11_0>='\u000B' && LA11_0<='\f')||(LA11_0>='\u000E' && LA11_0<='\uFFFF')) ) {
                    alt11=1;
                }


                switch (alt11) {
            	case 1 :
            	    // /home/victor/srec/core/src/main/antlr/srec.g:155:8: .
            	    {
            	    matchAny(); 

            	    }
            	    break;

            	default :
            	    break loop11;
                }
            } while (true);

            skip();
            mNEWLINE(); 

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
334190
function initializeParser(document, debug) {
    const chars = new antlr.InputStream(document);
    const lexer = new grammar.DocumentLexer(chars);
    const listener = new CustomErrorListener(debug);
    lexer.removeErrorListeners();
    lexer.addErrorListener(listener);
    const tokens = new antlr.CommonTokenStream(lexer);
    const parser = new grammar.DocumentParser(tokens);
    parser.buildParseTrees = true;
    parser.removeErrorListeners();
    parser.addErrorListener(listener);
    parser._errHandler = new CustomErrorStrategy();
    return parser;
}
132051
function expect(value) {
        var token = lex();
        if (token.type !== Token.Punctuator || token.value !== value) {
            throwUnexpectedToken(token);
        }
    }
720665
public final void typeArgument() throws RecognitionException {
		try {
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:147:5: ( type | QUESTION ( ( extends_key | super_key ) type )? )
			int alt15=2;
			int LA15_0 = input.LA(1);
			if ( (LA15_0==ID) ) {
				alt15=1;
			}
			else if ( (LA15_0==QUESTION) ) {
				alt15=2;
			}

			else {
				if (state.backtracking>0) {state.failed=true; return;}
				NoViableAltException nvae =
					new NoViableAltException("", 15, 0, input);
				throw nvae;
			}

			switch (alt15) {
				case 1 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:147:7: type
					{
					pushFollow(FOLLOW_type_in_typeArgument668);
					type();
					state._fsp--;
					if (state.failed) return;
					}
					break;
				case 2 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:148:7: QUESTION ( ( extends_key | super_key ) type )?
					{
					match(input,QUESTION,FOLLOW_QUESTION_in_typeArgument676); if (state.failed) return;
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:148:16: ( ( extends_key | super_key ) type )?
					int alt14=2;
					int LA14_0 = input.LA(1);
					if ( (LA14_0==ID) && ((((helper.validateIdentifierKey(DroolsSoftKeywords.SUPER)))||((helper.validateIdentifierKey(DroolsSoftKeywords.EXTENDS)))))) {
						alt14=1;
					}
					switch (alt14) {
						case 1 :
							// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:148:17: ( extends_key | super_key ) type
							{
							// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:148:17: ( extends_key | super_key )
							int alt13=2;
							int LA13_0 = input.LA(1);
							if ( (LA13_0==ID) && ((((helper.validateIdentifierKey(DroolsSoftKeywords.SUPER)))||((helper.validateIdentifierKey(DroolsSoftKeywords.EXTENDS)))))) {
								int LA13_1 = input.LA(2);
								if ( (((helper.validateIdentifierKey(DroolsSoftKeywords.EXTENDS)))) ) {
									alt13=1;
								}
								else if ( (((helper.validateIdentifierKey(DroolsSoftKeywords.SUPER)))) ) {
									alt13=2;
								}

								else {
									if (state.backtracking>0) {state.failed=true; return;}
									int nvaeMark = input.mark();
									try {
										input.consume();
										NoViableAltException nvae =
											new NoViableAltException("", 13, 1, input);
										throw nvae;
									} finally {
										input.rewind(nvaeMark);
									}
								}

							}

							switch (alt13) {
								case 1 :
									// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:148:18: extends_key
									{
									pushFollow(FOLLOW_extends_key_in_typeArgument680);
									extends_key();
									state._fsp--;
									if (state.failed) return;
									}
									break;
								case 2 :
									// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:148:32: super_key
									{
									pushFollow(FOLLOW_super_key_in_typeArgument684);
									super_key();
									state._fsp--;
									if (state.failed) return;
									}
									break;

							}

							pushFollow(FOLLOW_type_in_typeArgument687);
							type();
							state._fsp--;
							if (state.failed) return;
							}
							break;

					}

					}
					break;

			}
		}

		catch (RecognitionException re) {
		    throw re;
		}

		finally {
			// do for sure before leaving
		}
	}
876330
public final void mANY() throws RecognitionException {
		try {
			int _type = ANY;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// hql.g:9:5: ( 'any' )
			// hql.g:9:7: 'any'
			{
			match("any"); if (state.failed) return;

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
552803
public final void forInit() throws RecognitionException {
		int forInit_StartIndex = input.index();

		ParserRuleReturnScope variableModifier12 =null;
		ParserRuleReturnScope type13 =null;

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

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1056:5: ( ( variableModifier )* type variableDeclarators | expressionList )
			int alt137=2;
			switch ( input.LA(1) ) {
			case 58:
			case 83:
				{
				alt137=1;
				}
				break;
			case Identifier:
				{
				switch ( input.LA(2) ) {
				case 53:
					{
					int LA137_26 = input.LA(3);
					if ( (synpred198_Java()) ) {
						alt137=1;
					}
					else if ( (true) ) {
						alt137=2;
					}

					}
					break;
				case 47:
					{
					int LA137_27 = input.LA(3);
					if ( (synpred198_Java()) ) {
						alt137=1;
					}
					else if ( (true) ) {
						alt137=2;
					}

					}
					break;
				case 59:
					{
					int LA137_28 = input.LA(3);
					if ( (synpred198_Java()) ) {
						alt137=1;
					}
					else if ( (true) ) {
						alt137=2;
					}

					}
					break;
				case Identifier:
					{
					alt137=1;
					}
					break;
				case EOF:
				case 30:
				case 31:
				case 32:
				case 33:
				case 34:
				case 35:
				case 36:
				case 38:
				case 39:
				case 40:
				case 41:
				case 42:
				case 43:
				case 44:
				case 45:
				case 46:
				case 49:
				case 50:
				case 52:
				case 54:
				case 55:
				case 56:
				case 57:
				case 61:
				case 62:
				case 91:
				case 122:
				case 123:
				case 124:
					{
					alt137=2;
					}
					break;
				default:
					if (state.backtracking>0) {state.failed=true; return;}
					int nvaeMark = input.mark();
					try {
						input.consume();
						NoViableAltException nvae =
							new NoViableAltException("", 137, 3, input);
						throw nvae;
					} finally {
						input.rewind(nvaeMark);
					}
				}
				}
				break;
			case 65:
			case 67:
			case 71:
			case 77:
			case 85:
			case 92:
			case 94:
			case 105:
				{
				switch ( input.LA(2) ) {
				case 59:
					{
					int LA137_55 = input.LA(3);
					if ( (synpred198_Java()) ) {
						alt137=1;
					}
					else if ( (true) ) {
						alt137=2;
					}

					}
					break;
				case Identifier:
					{
					alt137=1;
					}
					break;
				case 47:
					{
					alt137=2;
					}
					break;
				default:
					if (state.backtracking>0) {state.failed=true; return;}
					int nvaeMark = input.mark();
					try {
						input.consume();
						NoViableAltException nvae =
							new NoViableAltException("", 137, 4, input);
						throw nvae;
					} finally {
						input.rewind(nvaeMark);
					}
				}
				}
				break;
			case CharacterLiteral:
			case DecimalLiteral:
			case FloatingPointLiteral:
			case HexLiteral:
			case OctalLiteral:
			case StringLiteral:
			case 29:
			case 36:
			case 40:
			case 41:
			case 44:
			case 45:
			case 53:
			case 70:
			case 79:
			case 80:
			case 82:
			case 97:
			case 98:
			case 108:
			case 111:
			case 115:
			case 118:
			case 126:
				{
				alt137=2;
				}
				break;
			default:
				if (state.backtracking>0) {state.failed=true; return;}
				NoViableAltException nvae =
					new NoViableAltException("", 137, 0, input);
				throw nvae;
			}
			switch (alt137) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1056:7: ( variableModifier )* type variableDeclarators
					{
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1056:7: ( variableModifier )*
					loop136:
					while (true) {
						int alt136=2;
						int LA136_0 = input.LA(1);
						if ( (LA136_0==58||LA136_0==83) ) {
							alt136=1;
						}

						switch (alt136) {
						case 1 :
							// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1056:9: variableModifier
							{
							pushFollow(FOLLOW_variableModifier_in_forInit4596);
							variableModifier12=variableModifier();
							state._fsp--;
							if (state.failed) return;
							if ( state.backtracking==0 ) {
							                VarDecl_stack.peek().descr.updateStart( ((CommonToken)(variableModifier12!=null?(variableModifier12.start):null)).getStartIndex() - 1 );
							                VarDecl_stack.peek().descr.addModifier( (variableModifier12!=null?input.toString(variableModifier12.start,variableModifier12.stop):null) );
							            }
							}
							break;

						default :
							break loop136;
						}
					}

					pushFollow(FOLLOW_type_in_forInit4631);
					type13=type();
					state._fsp--;
					if (state.failed) return;
					if ( state.backtracking==0 ) {
					            VarDecl_stack.peek().descr.updateStart( ((CommonToken)(type13!=null?(type13.start):null)).getStartIndex() - 1 );
					            VarDecl_stack.peek().descr.setType( (type13!=null?input.toString(type13.start,type13.stop):null) );
					            VarDecl_stack.peek().descr.setEnd( ((CommonToken)(type13!=null?(type13.stop):null)).getStopIndex() );
					        }
					pushFollow(FOLLOW_variableDeclarators_in_forInit4651);
					variableDeclarators();
					state._fsp--;
					if (state.failed) return;
					}
					break;
				case 2 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1069:7: expressionList
					{
					pushFollow(FOLLOW_expressionList_in_forInit4659);
					expressionList();
					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, 101, forInit_StartIndex); }

		}
	}
275899
public final void literal() throws RecognitionException {
		CommonTree theliteral=null;

		try {
			// src/main/resources/org/drools/compiler/lang/dsl/DSLMapWalker.g:123:5: (theliteral= VT_LITERAL )
			// src/main/resources/org/drools/compiler/lang/dsl/DSLMapWalker.g:123:7: theliteral= VT_LITERAL
			{
			theliteral=(CommonTree)match(input,VT_LITERAL,FOLLOW_VT_LITERAL_in_literal403); 
			}

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
		}
	}
1128089
public final void mELEMENTS() throws RecognitionException {
		try {
			int _type = ELEMENTS;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// hql.g:21:10: ( 'elements' )
			// hql.g:21:12: 'elements'
			{
			match("elements"); if (state.failed) return;

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
95317
public final void mNULL() throws RecognitionException {
		try {
			int _type = NULL;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// src/main/resources/org/drools/compiler/lang/DRL5Lexer.g:149:6: ( 'null' )
			// src/main/resources/org/drools/compiler/lang/DRL5Lexer.g:149:8: 'null'
			{
			match("null"); if (state.failed) return;

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
511965
def __do_parse(self, pattern_str):
        
        in_ = antlr4.InputStream(pattern_str)
        lexer = STIXPatternLexer(in_)
        lexer.removeErrorListeners()  # remove the default "console" listener
        token_stream = antlr4.CommonTokenStream(lexer)

        parser = STIXPatternParser(token_stream)
        parser.removeErrorListeners()  # remove the default "console" listener
        error_listener = ParserErrorListener()
        parser.addErrorListener(error_listener)

        # I found no public API for this...
        # The default error handler tries to keep parsing, and I don't
        # think that's appropriate here.  (These error handlers are only for
        # handling the built-in RecognitionException errors.)
        parser._errHandler = antlr4.BailErrorStrategy()

        # To improve error messages, replace "<INVALID>" in the literal
        # names with symbolic names.  This is a hack, but seemed like
        # the simplest workaround.
        for i, lit_name in enumerate(parser.literalNames):
            if lit_name == u"<INVALID>":
                parser.literalNames[i] = parser.symbolicNames[i]

        # parser.setTrace(True)

        try:
            tree = parser.pattern()
            # print(tree.toStringTree(recog=parser))

            return tree
        except antlr4.error.Errors.ParseCancellationException as e:
            # The cancellation exception wraps the real RecognitionException
            # which caused the parser to bail.
            real_exc = e.args[0]

            # I want to bail when the first error is hit.  But I also want
            # a decent error message.  When an error is encountered in
            # Parser.match(), the BailErrorStrategy produces the
            # ParseCancellationException.  It is not a subclass of
            # RecognitionException, so none of the 'except' clauses which would
            # normally report an error are invoked.
            #
            # Error message creation is buried in the ErrorStrategy, and I can
            # (ab)use the API to get a message: register an error listener with
            # the parser, force an error report, then get the message out of the
            # listener.  Error listener registration is above; now we force its
            # invocation.  Wish this could be cleaner...
            parser._errHandler.reportError(parser, real_exc)

            # should probably chain exceptions if we can...
            # Should I report the cancellation or recognition exception as the
            # cause...?
            six.raise_from(ParseException(error_listener.error_message),
                           real_exc)
1078950
public final void mTILDE() throws RecognitionException {
		try {
			int _type = TILDE;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// src/main/resources/org/drools/compiler/lang/DRL5Lexer.g:287:5: ( '~' )
			// src/main/resources/org/drools/compiler/lang/DRL5Lexer.g:287:7: '~'
			{
			match('~'); if (state.failed) return;
			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
17079
public final void mSOME() throws RecognitionException {
		try {
			int _type = SOME;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// hql.g:61:6: ( 'some' )
			// hql.g:61:8: 'some'
			{
			match("some"); if (state.failed) return;

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
1113918
public final void mLESS() throws RecognitionException {
		try {
			int _type = LESS;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// src/main/resources/org/drools/compiler/lang/DRL5Lexer.g:230:5: ( '<' )
			// src/main/resources/org/drools/compiler/lang/DRL5Lexer.g:230:7: '<'
			{
			match('<'); if (state.failed) return;
			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
965759
public final void mLESSER() throws RecognitionException {
        try {
            int _type = LESSER;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // src/riemann/Query.g:12:8: ( '<' )
            // src/riemann/Query.g:12:10: '<'
            {
            match('<'); 

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
1141681
public function when(/* see docblock */)
    {
        $arguments = func_get_args();
        if ($arguments[0] instanceof Antecedent) {
            $antecedent = $arguments[0];
        } elseif ($arguments[0] instanceof PHPUnit_Framework_Constraint) {
            $antecedent = Antecedent\IndependentConstraintsAntecedent::fromAll($arguments);
        } elseif ($arguments[0] instanceof Constraint) {
            $antecedent = Antecedent\IndependentConstraintsAntecedent::fromAll($arguments);
        } elseif ($arguments && count($arguments) == 1) {
            $antecedent = Antecedent\SingleCallbackAntecedent::from($arguments[0]);
        } else {
            throw new \InvalidArgumentException("Invalid call to when(): " . var_export($arguments, true));
        }
        $this->antecedents[] = $antecedent;
        return $this;
    }