in hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/expr/AlertExpressionParser.java [299:440]
private ExprContext expr(int _p) throws RecognitionException {
ParserRuleContext _parentctx = _ctx;
int _parentState = getState();
ExprContext _localctx = new ExprContext(_ctx, _parentState);
ExprContext _prevctx = _localctx;
int _startState = 2;
enterRecursionRule(_localctx, 2, RULE_expr, _p);
int _la;
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(18);
_errHandler.sync(this);
switch (_input.LA(1)) {
case LPAREN:
{
_localctx = new ParenExprContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(12);
match(LPAREN);
setState(13);
expr(0);
setState(14);
match(RPAREN);
}
break;
case IDENTIFIER:
{
_localctx = new QueryExprContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(16);
identifier();
}
break;
case NUMBER:
{
_localctx = new LiteralExprContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(17);
number();
}
break;
default:
throw new NoViableAltException(this);
}
_ctx.stop = _input.LT(-1);
setState(34);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,2,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( _parseListeners!=null ) triggerExitRuleEvent();
_prevctx = _localctx;
{
setState(32);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) {
case 1:
{
_localctx = new ComparisonExprContext(new ExprContext(_parentctx, _parentState));
((ComparisonExprContext)_localctx).left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(20);
if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)");
setState(21);
((ComparisonExprContext)_localctx).op = _input.LT(1);
_la = _input.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 1008L) != 0)) ) {
((ComparisonExprContext)_localctx).op = (Token)_errHandler.recoverInline(this);
}
else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
_errHandler.reportMatch(this);
consume();
}
setState(22);
((ComparisonExprContext)_localctx).right = expr(7);
}
break;
case 2:
{
_localctx = new AndExprContext(new ExprContext(_parentctx, _parentState));
((AndExprContext)_localctx).left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(23);
if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)");
setState(24);
match(AND);
setState(25);
((AndExprContext)_localctx).right = expr(6);
}
break;
case 3:
{
_localctx = new UnlessExprContext(new ExprContext(_parentctx, _parentState));
((UnlessExprContext)_localctx).left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(26);
if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)");
setState(27);
match(UNLESS);
setState(28);
((UnlessExprContext)_localctx).right = expr(5);
}
break;
case 4:
{
_localctx = new OrExprContext(new ExprContext(_parentctx, _parentState));
((OrExprContext)_localctx).left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(29);
if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)");
setState(30);
match(OR);
setState(31);
((OrExprContext)_localctx).right = expr(4);
}
break;
}
}
}
setState(36);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,2,_ctx);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
unrollRecursionContexts(_parentctx);
}
return _localctx;
}