예제 #1
0
        public override object VisitStringExpression([NotNull] StringExpressionContext context)
        {
            var text = context.Text().GetText();

            foreach (var item in context.stringExpressionElement())
            {
                text += " + " + Visit(item);
            }
            return(new Result {
                data = str,
                text = text,
            });
        }
예제 #2
0
        public override SLValue VisitStringExpression(StringExpressionContext ctx)
        {
            String text = ctx.GetText();

            text = text.Substring(1, text.Length - 2);
            SLValue val = new SLValue(text);

            if (ctx.indexes() != null)
            {
                List <ExpressionContext> exps = ctx.indexes().expression().ToList();
                val = resolveIndexes(val, exps);
            }
            return(val);
        }
예제 #3
0
        private ExpressionContext expression(int _p)
        {
            ParserRuleContext _parentctx = Context;
            int _parentState             = State;
            ExpressionContext _localctx  = new ExpressionContext(Context, _parentState);
            ExpressionContext _prevctx   = _localctx;
            int _startState = 2;

            EnterRecursionRule(_localctx, 2, RULE_expression, _p);
            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    State = 24;
                    ErrorHandler.Sync(this);
                    switch (TokenStream.LA(1))
                    {
                    case LPAREN:
                    {
                        _localctx = new ParenExpressionContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;

                        State = 14; Match(LPAREN);
                        State = 15; expression(0);
                        State = 16; Match(RPAREN);
                    }
                    break;

                    case NOT:
                    {
                        _localctx = new NotExpressionContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 18; Match(NOT);
                        State     = 19; expression(7);
                    }
                    break;

                    case TRUE:
                    case FALSE:
                    {
                        _localctx = new BoolExpressionContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 20; @bool();
                    }
                    break;

                    case IDENTIFIER:
                    {
                        _localctx = new IdentifierExpressionContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 21; Match(IDENTIFIER);
                    }
                    break;

                    case DECIMAL:
                    {
                        _localctx = new DecimalExpressionContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 22; Match(DECIMAL);
                    }
                    break;

                    case STRING:
                    {
                        _localctx = new StringExpressionContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 23; Match(STRING);
                    }
                    break;

                    default:
                        throw new NoViableAltException(this);
                    }
                    Context.Stop = TokenStream.LT(-1);
                    State        = 36;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context);
                    while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                    {
                        if (_alt == 1)
                        {
                            if (ParseListeners != null)
                            {
                                TriggerExitRuleEvent();
                            }
                            _prevctx = _localctx;
                            {
                                State = 34;
                                ErrorHandler.Sync(this);
                                switch (Interpreter.AdaptivePredict(TokenStream, 1, Context))
                                {
                                case 1:
                                {
                                    _localctx = new ComparatorExpressionContext(new ExpressionContext(_parentctx, _parentState));
                                    ((ComparatorExpressionContext)_localctx).left = _prevctx;
                                    PushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    State = 26;
                                    if (!(Precpred(Context, 6)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 6)");
                                    }
                                    State = 27; ((ComparatorExpressionContext)_localctx).op = comparator();
                                    State = 28; ((ComparatorExpressionContext)_localctx).right = expression(7);
                                }
                                break;

                                case 2:
                                {
                                    _localctx = new BinaryExpressionContext(new ExpressionContext(_parentctx, _parentState));
                                    ((BinaryExpressionContext)_localctx).left = _prevctx;
                                    PushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    State = 30;
                                    if (!(Precpred(Context, 5)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 5)");
                                    }
                                    State = 31; ((BinaryExpressionContext)_localctx).op = binary();
                                    State = 32; ((BinaryExpressionContext)_localctx).right = expression(6);
                                }
                                break;
                                }
                            }
                        }
                        State = 38;
                        ErrorHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                UnrollRecursionContexts(_parentctx);
            }
            return(_localctx);
        }