Esempio n. 1
0
 public ConditionalExpression(TokenPosition position, Expression condition, Expression trueValue, Expression falseValue)
     : base(position)
 {
     _condition = condition;
     _trueValue = trueValue;
     _falseValue = falseValue;
 }
Esempio n. 2
0
        public static TokenPosition[] GetPositionsFromString(string s, TokenPosition? basePosition)
        {
            TokenPosition[] positions = new TokenPosition[s.Length];

            int currentLine = 1;
            int currentColumn = 1;

            for (int textIndex = 0; textIndex < s.Length; textIndex++)
            {
                char c = s[textIndex];

                positions[textIndex].Line = currentLine;
                positions[textIndex].Column = currentColumn;

                if (basePosition != null)
                    positions[textIndex].ChangeBase(basePosition.Value);

                if (c == '\n')
                {
                    currentLine++;
                    currentColumn = 1;
                }
                else if (c != '\r')
                    currentColumn++;
            }

            return positions;
        }
Esempio n. 3
0
        public void ChangeBase(TokenPosition basePosition)
        {
            if (Line <= 1)
                Column = basePosition.Column + Column - 1;

            Line = basePosition.Line + Line - 1;
        }
Esempio n. 4
0
 /// <summary>
 /// Create a field expression.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="target"></param>
 /// <param name="member"></param>
 /// <param name="generics">An optional collection of genericTypes</param>
 public FieldExpression(TokenPosition position, Expression target, string member, Type[] genericTypes = null)
     : base(position)
 {
     _target = target;
     _member = member;
     _genericTypes = genericTypes;
 }
Esempio n. 5
0
 public FunctionCallToken(string text, TokenEvaluator evaluator, TokenPosition position) : base(text)
 {
     Precedence = 20;
     TokenType = TokenType.FunctionCall;
     Evaluator = evaluator;
     TokenPosition = position;
 }
Esempio n. 6
0
        public TokenPosition(TokenPosition parent, TokenPosition current) : this()
        {
            Line = parent.Line + current.Line - 1;

            Column = current.Column;

            if (current.Line <= 1)
                Column = parent.Column + current.Column - 1;
        }
Esempio n. 7
0
        public static Expression DotOperator(string token, TokenPosition position, Expression[] terms)
        {
            VariableExpression varExpression = terms[1] as VariableExpression;

            if (varExpression == null)
                throw new UnknownPropertyException("Unkown member " + terms[1], terms[1]);

            return new FieldExpression(position, terms[0], varExpression.VarName);
        }
Esempio n. 8
0
        public TokenPosition(TokenPosition parent, TokenPosition current)
        {
            _line = parent.Line + current.Line - 1;

            _column = current.Column;

            if (current.Line <= 1)
                _column = parent.Column + current.Column - 1;
        }
Esempio n. 9
0
        public ValueExpression(TokenPosition position, object value, Type type)
            : base(position)
        {
            Value = value;
            Type = type;

            if (Type == typeof(object) && Value != null)
                Type = Value.GetType();
        }
Esempio n. 10
0
        public static Expression IsAsOperator(string token, TokenPosition position, Expression[] terms)
        {
            if (token == "as")
                return new AsExpression(position, terms[0], terms[1]);

            if (token == "is")
                return new IsExpression(position, terms[0], terms[1]);

            return null;
        }
Esempio n. 11
0
        private static char UnEscape(string s, TokenPosition position)
        {
            if (s.Length == 1)
                return s[0];

            if (s.Length == 2)
            {
                switch (s[1])
                {
                    case '\\':
                    case '\"':
                    case '\'':
                        return s[1];
                    case '0':
                        return (char)0;
                    case 'a':
                        return '\a';
                    case 'b':
                        return '\b';
                    case 'f':
                        return '\f';
                    case 'n':
                        return '\n';
                    case 'r':
                        return '\r';
                    case 't':
                        return '\t';
                    case 'v':
                        return '\v';
                    default:
                        throw new UnknownTokenException(position,s);
                }
            }
            else
            {
                return (char)Convert.ToUInt16(s.Substring(2), 16);
            }
        }
Esempio n. 12
0
 public SubtractExpression(TokenPosition position, Expression left, Expression right) : base(position, "-", left, right)
 {
 }
Esempio n. 13
0
 public static Expression Ternary(string token, TokenPosition position, Expression[] terms)
 {
     return new ConditionalExpression(position, terms[0], terms[1], terms[2]);
 }
Esempio n. 14
0
 public MultiplyExpression(TokenPosition position, Expression left, Expression right) : base(position, "*", left, right) { }
Esempio n. 15
0
 public TypeOfExpression(TokenPosition tokenPosition) : base(tokenPosition)
 {
 }
Esempio n. 16
0
 public DefaultValueExpression(TokenPosition position, Expression value, Expression defaultValue)
     : base(position, value, defaultValue)
 {
 }
Esempio n. 17
0
 public AsExpression(TokenPosition position, Expression objectExpression, Expression typeExpression) : base(position)
 {
     _objectExpression = objectExpression;
     _typeExpression   = typeExpression;
 }
Esempio n. 18
0
 public static Expression Assignment(string token, TokenPosition position, Expression[] terms)
 {
     return(new AssignmentExpression(position, terms[0], terms[1]));
 }
Esempio n. 19
0
 public static Expression TypeOf(string token, TokenPosition position, Expression[] terms)
 {
     return(new TypeOfExpression(position));
 }
Esempio n. 20
0
 public static Expression StatementSeperator(string token, TokenPosition position, Expression[] terms)
 {
     return(new SequenceExpression(position, terms));
 }
Esempio n. 21
0
 public static Expression Operator(string token, TokenPosition position, Expression[] terms)
 {
     return(Exp.Op(position, token, terms[0], terms[1]));
 }
Esempio n. 22
0
 public static Expression DefaultValueOperator(string token, TokenPosition position, Expression[] terms)
 {
     return(new DefaultValueExpression(position, terms[0], terms[1]));
 }
Esempio n. 23
0
 public static Expression Coalesce(string token, TokenPosition position, Expression[] terms)
 {
     return(new CoalesceExpression(position, terms[0], terms[1]));
 }
Esempio n. 24
0
 public static Expression VarName(string token, TokenPosition position, Expression[] terms)
 {
     return(new VariableExpression(position, token));
 }
Esempio n. 25
0
        public static Expression Number(string token, TokenPosition position, Expression[] terms)
        {
            string s = token;

            Type type = null;

            if (!char.IsDigit(s[s.Length - 1]))
            {
                string suffix = "" + char.ToUpper(s[s.Length - 1]);

                s = s.Remove(s.Length - 1);

                if (!char.IsDigit(s[s.Length - 1]))
                {
                    suffix = char.ToUpper(s[s.Length - 1]) + suffix;

                    s = s.Remove(s.Length - 1);
                }

                switch (suffix)
                {
                case "M":
                    type = typeof(decimal);
                    break;

                case "D":
                    type = typeof(double);
                    break;

                case "F":
                    type = typeof(float);
                    break;

                case "L":
                    type = typeof(long);
                    break;

                case "U":
                    type = typeof(uint);
                    break;

                case "LU":
                case "UL":
                    type = typeof(ulong);
                    break;
                }
            }

            if (type != null)
            {
                return(new ValueExpression(position, Convert.ChangeType(s, type, _numberFormat), type));
            }

            if (s.LastIndexOf('.') >= 0)
            {
                return(Exp.Value(position, Convert.ToDouble(s, _numberFormat)));
            }
            else
            {
                long n = Convert.ToInt64(s);

                if (n > Int32.MaxValue || n < Int32.MinValue)
                {
                    return(Exp.Value(position, n));
                }
                else
                {
                    return(Exp.Value(position, (int)n));
                }
            }
        }
Esempio n. 26
0
        public static Expression StringLiteral(string token, TokenPosition position, Expression[] terms)
        {
            string s = token.Substring(1, token.Length - 2);

            if (s.IndexOf('\\') < 0)
            {
                return(Exp.Value(position, s));
            }

            StringBuilder output = new StringBuilder(token.Length);

            bool   inEscape  = false;
            string hexString = null;

            for (int i = 0; i < s.Length; i++)
            {
                char c = s[i];

                if (inEscape)
                {
                    if (c == 'x')
                    {
                        hexString = "";
                        continue;
                    }

                    if (hexString == null && (c != 'x' || c != 'X'))
                    {
                        output.Append(UnEscape("\\" + c, position));
                        inEscape = false;
                        continue;
                    }

                    if (hexString == null)
                    {
                        inEscape = false;
                    }
                    else
                    {
                        if (((char.ToLower(c) < 'a' || char.ToLower(c) > 'f') && (c < '0' || c > '9')) || hexString.Length == 4)
                        {
                            output.Append(UnEscape("\\x" + hexString, position));
                            inEscape  = false;
                            hexString = null;
                        }
                        else
                        {
                            hexString += c;
                            continue;
                        }
                    }
                }

                if (c != '\\')
                {
                    output.Append(c);

                    continue;
                }

                inEscape = true;
            }

            return(Exp.Value(position, output.ToString()));
        }
Esempio n. 27
0
 public TemplateParserException(string message, Exception innerException, TokenPosition tokenPosition)
     : base(message, innerException)
 {
     _tokenPosition = tokenPosition;
 }
Esempio n. 28
0
        public static Expression Constructor(string token, TokenPosition position, Expression[] terms)
        {
            string className = token.Substring(3).Trim();

            return(new ConstructorExpression(position, new VariableExpression(position, className), terms));
        }
Esempio n. 29
0
 public BinaryArithmicExpression(TokenPosition position, string op, Expression left, Expression right)
     : base(position, left, right)
 {
     _operator = op;
 }
Esempio n. 30
0
 public DivideExpression(TokenPosition position, Expression left, Expression right) : base(position, "/" , left, right)
 {
 }
Esempio n. 31
0
 public TemplateRenderingException(string message, Exception innerException, TokenPosition tokenPosition) : base(message, innerException, tokenPosition)
 {
 }
Esempio n. 32
0
 public CallExpression(TokenPosition position, Expression methodExpression, Expression[] parameters) : base(position)
 {
     _methodExpression = methodExpression;
     _parameters = parameters;
 }
Esempio n. 33
0
 public NegationExpression(TokenPosition position, Expression value) : base(position, value)
 {
 }
Esempio n. 34
0
 public IfExpression(TokenPosition position, Expression condition)
     : base(position)
 {
     Condition = condition;
 }
Esempio n. 35
0
 public ConditionalExpression(TokenPosition position, Expression condition, Expression trueValue, Expression falseValue) : base(position)
 {
     Condition  = condition;
     TrueValue  = trueValue;
     FalseValue = falseValue;
 }
Esempio n. 36
0
 public AddExpression(TokenPosition position, Expression left, Expression right) : base(position, "+", left, right) { }
Esempio n. 37
0
 public SequenceExpression(TokenPosition tokenPosition, Expression[] expressions) : base(tokenPosition)
 {
     _expressions = expressions;
 }
Esempio n. 38
0
 public ReturnExpression(TokenPosition tokenPosition, Expression expression) : base(tokenPosition, expression)
 {
 }
Esempio n. 39
0
        public static Expression InOperator(string token, TokenPosition position, Expression[] terms)
        {
            VariableExpression varExpression = terms[0] as VariableExpression;

            return new InExpression(position, varExpression, terms[1]);
        }
Esempio n. 40
0
 public UnaryMinusExpression(TokenPosition position, Expression value) : base(position, value)
 {
 }
Esempio n. 41
0
 public static Expression NumericRange(string token, TokenPosition position, Expression[] terms)
 {
     return(new RangeExpression(position, terms[0], terms[1]));
 }
Esempio n. 42
0
 public static Expression CharLiteral(string token, TokenPosition position, Expression[] terms)
 {
     return(Exp.Value(position, UnEscape(token.Substring(1, token.Length - 2), position)));
 }
Esempio n. 43
0
 public IndexExpression(TokenPosition position, Expression target, Expression[] parameters)
     : base(position)
 {
     _target = target;
     _parameters = parameters;
 }
Esempio n. 44
0
 public static Expression TypeCast(string token, TokenPosition position, Expression[] terms)
 {
     return(new TypeCastExpression(position, new VariableExpression(position, token.Substring(1, token.Length - 2).Trim()), terms[0]));
 }
Esempio n. 45
0
 public NegationExpression(TokenPosition position, Expression value) : base(position, value)
 {
 }
Esempio n. 46
0
        public static Expression InOperator(string token, TokenPosition position, Expression[] terms)
        {
            VariableExpression varExpression = terms[0] as VariableExpression;

            return(new InExpression(position, varExpression, terms[1]));
        }
Esempio n. 47
0
 public MultiplyExpression(TokenPosition position, Expression left, Expression right)
     : base(position, "*", left, right)
 {
 }
Esempio n. 48
0
 public static Expression Ternary(string token, TokenPosition position, Expression[] terms)
 {
     return(new ConditionalExpression(position, terms[0], terms[1], terms[2]));
 }
Esempio n. 49
0
 public ConstructorExpression(TokenPosition position, VariableExpression className, Expression[] parameters)
     : base(position)
 {
     _className = className;
     _parameters = parameters;
 }
Esempio n. 50
0
 public IExpressionWithContext ParseWithContext(string s, IParserContext context, TokenPosition position)
 {
     return(new ExpressionWithContext(Parse(s, position), context));
 }
Esempio n. 51
0
 public UnknownTokenException(TokenPosition position, string token)
     : base(position,token)
 {
 }
Esempio n. 52
0
 public IExpressionWithContext ParseWithContext(string s, TokenPosition position)
 {
     return(new ExpressionWithContext(Parse(s, position), _defaultContext));
 }
Esempio n. 53
0
 public TemplateParsingException(string message, TokenPosition tokenPosition)
     : base(message, tokenPosition)
 {
 }
Esempio n. 54
0
 public IValueWithType Evaluate(string s, IParserContext context, TokenPosition tokenPosition)
 {
     return(ParseWithContext(s, context, tokenPosition).Evaluate());
 }
 public TemplateRenderingException(string message, Exception innerException, TokenPosition tokenPosition)
     : base(message, innerException, tokenPosition)
 {
 }
Esempio n. 56
0
 public object EvaluateToObject(string s, IParserContext context, TokenPosition tokenPosition)
 {
     return(ParseWithContext(s, context, tokenPosition).EvaluateToObject());
 }
 public BitwiseComplementExpression(TokenPosition position, Expression value) : base(position, value)
 {
 }
Esempio n. 58
0
 public T Evaluate <T>(string s, IParserContext context, TokenPosition tokenPosition)
 {
     return(ParseWithContext(s, context, tokenPosition).Evaluate <T>());
 }
Esempio n. 59
0
 public AsExpression(TokenPosition position, Expression objectExpression, Expression typeExpression)
     : base(position)
 {
     _objectExpression = objectExpression;
     _typeExpression = typeExpression;
 }
Esempio n. 60
0
 public ReturnExpression(TokenPosition tokenPosition, Expression expression) : base(tokenPosition, expression)
 {
 }