public static ParseResult parse(String expression,String eplStatementErrorMsg,boolean addPleaseCheck,ParseRuleSelector parseRuleSelector,boolean rewriteScript) throws EPException {
  if (log.isDebugEnabled()) {
    log.debug(".parse Parsing expr=" + expression);
  }
  CharStream input;
  try {
    input=new NoCaseSensitiveStream(new StringReader(expression));
  }
 catch (  IOException ex) {
    throw new EPException("IOException parsing expression '" + expression + '\'',ex);
  }
  EsperEPL2GrammarLexer lex=newLexer(input);
  CommonTokenStream tokens=new CommonTokenStream(lex);
  EsperEPL2GrammarParser parser=ParseHelper.newParser(tokens);
  Tree tree;
  try {
    tree=parseRuleSelector.invokeParseRule(parser);
  }
 catch (  RecognitionException ex) {
    tokens.fill();
    if (rewriteScript && isContainsScriptExpression(tokens)) {
      return handleScriptRewrite(tokens,eplStatementErrorMsg,addPleaseCheck,parseRuleSelector);
    }
    log.debug("Error parsing statement [" + expression + "]",ex);
    throw ExceptionConvertor.convertStatement(ex,eplStatementErrorMsg,addPleaseCheck,parser);
  }
catch (  RuntimeException e) {
    try {
      tokens.fill();
    }
 catch (    RuntimeException ex) {
      log.debug("Token-fill produced exception: " + e.getMessage(),e);
    }
    if (log.isDebugEnabled()) {
      log.debug("Error parsing statement [" + eplStatementErrorMsg + "]",e);
    }
    if (e.getCause() instanceof RecognitionException) {
      if (rewriteScript && isContainsScriptExpression(tokens)) {
        return handleScriptRewrite(tokens,eplStatementErrorMsg,addPleaseCheck,parseRuleSelector);
      }
      throw ExceptionConvertor.convertStatement((RecognitionException)e.getCause(),eplStatementErrorMsg,addPleaseCheck,parser);
    }
 else {
      throw e;
    }
  }
  if (rewriteScript && isContainsScriptExpression(tokens)) {
    return handleScriptRewrite(tokens,eplStatementErrorMsg,addPleaseCheck,parseRuleSelector);
  }
  if (log.isDebugEnabled()) {
    log.debug(".parse Dumping AST...");
    ASTUtil.dumpAST(tree);
  }
  String expressionWithoutAnnotation=expression;
  if (tree instanceof EsperEPL2GrammarParser.StartEPLExpressionRuleContext) {
    EsperEPL2GrammarParser.StartEPLExpressionRuleContext epl=(EsperEPL2GrammarParser.StartEPLExpressionRuleContext)tree;
    expressionWithoutAnnotation=getNoAnnotation(expression,epl.annotationEnum(),tokens);
  }
 else   if (tree instanceof EsperEPL2GrammarParser.StartPatternExpressionRuleContext) {
    EsperEPL2GrammarParser.StartPatternExpressionRuleContext pattern=(EsperEPL2GrammarParser.StartPatternExpressionRuleContext)tree;
    expressionWithoutAnnotation=getNoAnnotation(expression,pattern.annotationEnum(),tokens);
  }
  return new ParseResult(tree,expressionWithoutAnnotation,tokens,Collections.<String>emptyList());
}

public static ParseResult parse ( String expression , String eplStatementErrorMsg , boolean addPleaseCheck , ParseRuleSelector parseRuleSelector , boolean rewriteScript ) throws EPException { if ( log . isDebugEnabled ( ) ) { log . debug ( ".parse Parsing expr=" + expression ) ; } CharStream input ; try { input = new NoCaseSensitiveStream ( new StringReader ( expression ) ) ; } catch ( IOException ex ) { throw new EPException ( "IOException parsing expression '" + expression + '\'' , ex ) ; } EsperEPL2GrammarLexer lex = newLexer ( input ) ; CommonTokenStream tokens = new CommonTokenStream ( lex ) ; EsperEPL2GrammarParser parser = ParseHelper . newParser ( tokens ) ; Tree tree ; try { tree = parseRuleSelector . invokeParseRule ( parser ) ; } catch ( RecognitionException ex ) { tokens . fill ( ) ; if ( rewriteScript && isContainsScriptExpression ( tokens ) ) { return handleScriptRewrite ( tokens , eplStatementErrorMsg , addPleaseCheck , parseRuleSelector ) ; } log . debug ( "Error parsing statement [" + expression + "]" , ex ) ; throw ExceptionConvertor . convertStatement ( ex , eplStatementErrorMsg , addPleaseCheck , parser ) ; } catch ( RuntimeException e ) { try { tokens . fill ( ) ; } catch ( RuntimeException ex ) { log . debug ( "Token-fill produced exception: " + e . getMessage ( ) , e ) ; } if ( log . isDebugEnabled ( ) ) { log . debug ( "Error parsing statement [" + eplStatementErrorMsg + "]" , e ) ; } if ( e . getCause ( ) instanceof RecognitionException ) { if ( rewriteScript && isContainsScriptExpression ( tokens ) ) { return handleScriptRewrite ( tokens , eplStatementErrorMsg , addPleaseCheck , parseRuleSelector ) ; } throw ExceptionConvertor . convertStatement ( ( RecognitionException ) e . getCause ( ) , eplStatementErrorMsg , addPleaseCheck , parser ) ; } else { throw e ; } } if ( rewriteScript && isContainsScriptExpression ( tokens ) ) { return handleScriptRewrite ( tokens , eplStatementErrorMsg , addPleaseCheck , parseRuleSelector ) ; } if ( log . isDebugEnabled ( ) ) { log . debug ( ".parse Dumping AST..." ) ; ASTUtil . dumpAST ( tree ) ; } String expressionWithoutAnnotation = expression ; if ( tree instanceof EsperEPL2GrammarParser . StartEPLExpressionRuleContext ) { EsperEPL2GrammarParser . StartEPLExpressionRuleContext epl = ( EsperEPL2GrammarParser . StartEPLExpressionRuleContext ) tree ; expressionWithoutAnnotation = getNoAnnotation ( expression , epl . annotationEnum ( ) , tokens ) ; } else if ( tree instanceof EsperEPL2GrammarParser . StartPatternExpressionRuleContext ) { EsperEPL2GrammarParser . StartPatternExpressionRuleContext pattern = ( EsperEPL2GrammarParser . StartPatternExpressionRuleContext ) tree ; expressionWithoutAnnotation = getNoAnnotation ( expression , pattern . annotationEnum ( ) , tokens ) ; } return new ParseResult ( tree , expressionWithoutAnnotation , tokens , Collections . < String > emptyList ( ) ) ; }
parse expression using the rule the parseruleselector instance supplies .
