예제 #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());
 }
예제 #55
0
 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());
 }
예제 #57
0
 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)
 {
 }