Beispiel #1
0
 public ConditionalExpression(TokenPosition position, Expression condition, Expression trueValue, Expression falseValue)
     : base(position)
 {
     _condition = condition;
     _trueValue = trueValue;
     _falseValue = falseValue;
 }
Beispiel #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;
        }
Beispiel #3
0
        public void ChangeBase(TokenPosition basePosition)
        {
            if (Line <= 1)
                Column = basePosition.Column + Column - 1;

            Line = basePosition.Line + Line - 1;
        }
Beispiel #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;
 }
Beispiel #5
0
 public FunctionCallToken(string text, TokenEvaluator evaluator, TokenPosition position) : base(text)
 {
     Precedence = 20;
     TokenType = TokenType.FunctionCall;
     Evaluator = evaluator;
     TokenPosition = position;
 }
Beispiel #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;
        }
Beispiel #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);
        }
Beispiel #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;
        }
Beispiel #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();
        }
Beispiel #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;
        }
Beispiel #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);
            }
        }
Beispiel #12
0
 public SubtractExpression(TokenPosition position, Expression left, Expression right) : base(position, "-", left, right)
 {
 }
Beispiel #13
0
 public static Expression Ternary(string token, TokenPosition position, Expression[] terms)
 {
     return new ConditionalExpression(position, terms[0], terms[1], terms[2]);
 }
Beispiel #14
0
 public MultiplyExpression(TokenPosition position, Expression left, Expression right) : base(position, "*", left, right) { }
Beispiel #15
0
 public TypeOfExpression(TokenPosition tokenPosition) : base(tokenPosition)
 {
 }
 public DefaultValueExpression(TokenPosition position, Expression value, Expression defaultValue)
     : base(position, value, defaultValue)
 {
 }
Beispiel #17
0
 public AsExpression(TokenPosition position, Expression objectExpression, Expression typeExpression) : base(position)
 {
     _objectExpression = objectExpression;
     _typeExpression   = typeExpression;
 }
Beispiel #18
0
 public static Expression Assignment(string token, TokenPosition position, Expression[] terms)
 {
     return(new AssignmentExpression(position, terms[0], terms[1]));
 }
Beispiel #19
0
 public static Expression TypeOf(string token, TokenPosition position, Expression[] terms)
 {
     return(new TypeOfExpression(position));
 }
Beispiel #20
0
 public static Expression StatementSeperator(string token, TokenPosition position, Expression[] terms)
 {
     return(new SequenceExpression(position, terms));
 }
Beispiel #21
0
 public static Expression Operator(string token, TokenPosition position, Expression[] terms)
 {
     return(Exp.Op(position, token, terms[0], terms[1]));
 }
Beispiel #22
0
 public static Expression DefaultValueOperator(string token, TokenPosition position, Expression[] terms)
 {
     return(new DefaultValueExpression(position, terms[0], terms[1]));
 }
Beispiel #23
0
 public static Expression Coalesce(string token, TokenPosition position, Expression[] terms)
 {
     return(new CoalesceExpression(position, terms[0], terms[1]));
 }
Beispiel #24
0
 public static Expression VarName(string token, TokenPosition position, Expression[] terms)
 {
     return(new VariableExpression(position, token));
 }
Beispiel #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));
                }
            }
        }
Beispiel #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()));
        }
 public TemplateParserException(string message, Exception innerException, TokenPosition tokenPosition)
     : base(message, innerException)
 {
     _tokenPosition = tokenPosition;
 }
Beispiel #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));
        }
 public BinaryArithmicExpression(TokenPosition position, string op, Expression left, Expression right)
     : base(position, left, right)
 {
     _operator = op;
 }
Beispiel #30
0
 public DivideExpression(TokenPosition position, Expression left, Expression right) : base(position, "/" , left, right)
 {
 }
Beispiel #31
0
 public TemplateRenderingException(string message, Exception innerException, TokenPosition tokenPosition) : base(message, innerException, tokenPosition)
 {
 }
Beispiel #32
0
 public CallExpression(TokenPosition position, Expression methodExpression, Expression[] parameters) : base(position)
 {
     _methodExpression = methodExpression;
     _parameters = parameters;
 }
Beispiel #33
0
 public NegationExpression(TokenPosition position, Expression value) : base(position, value)
 {
 }
Beispiel #34
0
 public IfExpression(TokenPosition position, Expression condition)
     : base(position)
 {
     Condition = condition;
 }
 public ConditionalExpression(TokenPosition position, Expression condition, Expression trueValue, Expression falseValue) : base(position)
 {
     Condition  = condition;
     TrueValue  = trueValue;
     FalseValue = falseValue;
 }
Beispiel #36
0
 public AddExpression(TokenPosition position, Expression left, Expression right) : base(position, "+", left, right) { }
Beispiel #37
0
 public SequenceExpression(TokenPosition tokenPosition, Expression[] expressions) : base(tokenPosition)
 {
     _expressions = expressions;
 }
Beispiel #38
0
 public ReturnExpression(TokenPosition tokenPosition, Expression expression) : base(tokenPosition, expression)
 {
 }
Beispiel #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]);
        }
Beispiel #40
0
 public UnaryMinusExpression(TokenPosition position, Expression value) : base(position, value)
 {
 }
Beispiel #41
0
 public static Expression NumericRange(string token, TokenPosition position, Expression[] terms)
 {
     return(new RangeExpression(position, terms[0], terms[1]));
 }
Beispiel #42
0
 public static Expression CharLiteral(string token, TokenPosition position, Expression[] terms)
 {
     return(Exp.Value(position, UnEscape(token.Substring(1, token.Length - 2), position)));
 }
Beispiel #43
0
 public IndexExpression(TokenPosition position, Expression target, Expression[] parameters)
     : base(position)
 {
     _target = target;
     _parameters = parameters;
 }
Beispiel #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]));
 }
Beispiel #45
0
 public NegationExpression(TokenPosition position, Expression value) : base(position, value)
 {
 }
Beispiel #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]));
        }
Beispiel #47
0
 public MultiplyExpression(TokenPosition position, Expression left, Expression right)
     : base(position, "*", left, right)
 {
 }
Beispiel #48
0
 public static Expression Ternary(string token, TokenPosition position, Expression[] terms)
 {
     return(new ConditionalExpression(position, terms[0], terms[1], terms[2]));
 }
Beispiel #49
0
 public ConstructorExpression(TokenPosition position, VariableExpression className, Expression[] parameters)
     : base(position)
 {
     _className = className;
     _parameters = parameters;
 }
Beispiel #50
0
 public IExpressionWithContext ParseWithContext(string s, IParserContext context, TokenPosition position)
 {
     return(new ExpressionWithContext(Parse(s, position), context));
 }
 public UnknownTokenException(TokenPosition position, string token)
     : base(position,token)
 {
 }
Beispiel #52
0
 public IExpressionWithContext ParseWithContext(string s, TokenPosition position)
 {
     return(new ExpressionWithContext(Parse(s, position), _defaultContext));
 }
 public TemplateParsingException(string message, TokenPosition tokenPosition)
     : base(message, tokenPosition)
 {
 }
Beispiel #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)
 {
 }
Beispiel #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)
 {
 }
Beispiel #58
0
 public T Evaluate <T>(string s, IParserContext context, TokenPosition tokenPosition)
 {
     return(ParseWithContext(s, context, tokenPosition).Evaluate <T>());
 }
Beispiel #59
0
 public AsExpression(TokenPosition position, Expression objectExpression, Expression typeExpression)
     : base(position)
 {
     _objectExpression = objectExpression;
     _typeExpression = typeExpression;
 }
Beispiel #60
0
 public ReturnExpression(TokenPosition tokenPosition, Expression expression) : base(tokenPosition, expression)
 {
 }