示例#1
0
        public object Visit(Index expr)
        {
            object callee = Evaluate(expr.callee);

            if (!(callee is ICollection))
            {
                throw new ErrorHandler.RuntimeError(expr.bracket, "Expected indexable type");
            }

            ICollection called = (ICollection)callee;

            object first  = Evaluate(expr.first);
            object second = expr.second != null?Evaluate(expr.second) : null;

            object third = expr.third != null?Evaluate(expr.third) : null;

            return(called.Access(this, expr.bracket, first, second, third));
        }
示例#2
0
        public object Visit(Index expr)
        {
            object callee = Evaluate(expr.callee);

            if (callee is ICollection)
            {
                ICollection called = (ICollection)callee;

                object first  = Evaluate(expr.first);
                object second = expr.second != null?Evaluate(expr.second) : null;

                object third = expr.third != null?Evaluate(expr.third) : null;

                return(called.Access(this, expr.bracket, first, second, third));
            }

            if (callee is string)
            {
                string str = (string)callee;

                object first  = Evaluate(expr.first);
                object second = expr.second != null?Evaluate(expr.second) : null;

                object third = expr.third != null?Evaluate(expr.third) : null;

                if (expr.callee is Literal)
                {
                    return(Toy.Library.String.SliceNotationLiteral(expr.callee, expr.bracket, first, second, third));
                }

                if (expr.callee is Variable)
                {
                    return(Toy.Library.String.SliceNotationVariable(expr.callee, expr.bracket, this, first, second, third));
                }
            }

            throw new ErrorHandler.RuntimeError(expr.bracket, "Expected indexable type (found " + (callee == null ? "null" : callee.ToString()) + ")");
        }