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

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