public ConditionalExpression(TokenPosition position, Expression condition, Expression trueValue, Expression falseValue) : base(position) { _condition = condition; _trueValue = trueValue; _falseValue = falseValue; }
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; }
public void ChangeBase(TokenPosition basePosition) { if (Line <= 1) Column = basePosition.Column + Column - 1; Line = basePosition.Line + Line - 1; }
/// <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; }
public FunctionCallToken(string text, TokenEvaluator evaluator, TokenPosition position) : base(text) { Precedence = 20; TokenType = TokenType.FunctionCall; Evaluator = evaluator; TokenPosition = position; }
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; }
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); }
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; }
public ValueExpression(TokenPosition position, object value, Type type) : base(position) { Value = value; Type = type; if (Type == typeof(object) && Value != null) Type = Value.GetType(); }
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; }
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); } }
public SubtractExpression(TokenPosition position, Expression left, Expression right) : base(position, "-", left, right) { }
public static Expression Ternary(string token, TokenPosition position, Expression[] terms) { return new ConditionalExpression(position, terms[0], terms[1], terms[2]); }
public MultiplyExpression(TokenPosition position, Expression left, Expression right) : base(position, "*", left, right) { }
public TypeOfExpression(TokenPosition tokenPosition) : base(tokenPosition) { }
public DefaultValueExpression(TokenPosition position, Expression value, Expression defaultValue) : base(position, value, defaultValue) { }
public AsExpression(TokenPosition position, Expression objectExpression, Expression typeExpression) : base(position) { _objectExpression = objectExpression; _typeExpression = typeExpression; }
public static Expression Assignment(string token, TokenPosition position, Expression[] terms) { return(new AssignmentExpression(position, terms[0], terms[1])); }
public static Expression TypeOf(string token, TokenPosition position, Expression[] terms) { return(new TypeOfExpression(position)); }
public static Expression StatementSeperator(string token, TokenPosition position, Expression[] terms) { return(new SequenceExpression(position, terms)); }
public static Expression Operator(string token, TokenPosition position, Expression[] terms) { return(Exp.Op(position, token, terms[0], terms[1])); }
public static Expression DefaultValueOperator(string token, TokenPosition position, Expression[] terms) { return(new DefaultValueExpression(position, terms[0], terms[1])); }
public static Expression Coalesce(string token, TokenPosition position, Expression[] terms) { return(new CoalesceExpression(position, terms[0], terms[1])); }
public static Expression VarName(string token, TokenPosition position, Expression[] terms) { return(new VariableExpression(position, token)); }
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)); } } }
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; }
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; }
public DivideExpression(TokenPosition position, Expression left, Expression right) : base(position, "/" , left, right) { }
public TemplateRenderingException(string message, Exception innerException, TokenPosition tokenPosition) : base(message, innerException, tokenPosition) { }
public CallExpression(TokenPosition position, Expression methodExpression, Expression[] parameters) : base(position) { _methodExpression = methodExpression; _parameters = parameters; }
public NegationExpression(TokenPosition position, Expression value) : base(position, value) { }
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; }
public AddExpression(TokenPosition position, Expression left, Expression right) : base(position, "+", left, right) { }
public SequenceExpression(TokenPosition tokenPosition, Expression[] expressions) : base(tokenPosition) { _expressions = expressions; }
public ReturnExpression(TokenPosition tokenPosition, Expression expression) : base(tokenPosition, expression) { }
public static Expression InOperator(string token, TokenPosition position, Expression[] terms) { VariableExpression varExpression = terms[0] as VariableExpression; return new InExpression(position, varExpression, terms[1]); }
public UnaryMinusExpression(TokenPosition position, Expression value) : base(position, value) { }
public static Expression NumericRange(string token, TokenPosition position, Expression[] terms) { return(new RangeExpression(position, terms[0], terms[1])); }
public static Expression CharLiteral(string token, TokenPosition position, Expression[] terms) { return(Exp.Value(position, UnEscape(token.Substring(1, token.Length - 2), position))); }
public IndexExpression(TokenPosition position, Expression target, Expression[] parameters) : base(position) { _target = target; _parameters = parameters; }
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])); }
public static Expression InOperator(string token, TokenPosition position, Expression[] terms) { VariableExpression varExpression = terms[0] as VariableExpression; return(new InExpression(position, varExpression, terms[1])); }
public static Expression Ternary(string token, TokenPosition position, Expression[] terms) { return(new ConditionalExpression(position, terms[0], terms[1], terms[2])); }
public ConstructorExpression(TokenPosition position, VariableExpression className, Expression[] parameters) : base(position) { _className = className; _parameters = parameters; }
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) { }
public IExpressionWithContext ParseWithContext(string s, TokenPosition position) { return(new ExpressionWithContext(Parse(s, position), _defaultContext)); }
public TemplateParsingException(string message, TokenPosition tokenPosition) : base(message, tokenPosition) { }
public IValueWithType Evaluate(string s, IParserContext context, TokenPosition tokenPosition) { return(ParseWithContext(s, context, tokenPosition).Evaluate()); }
public object EvaluateToObject(string s, IParserContext context, TokenPosition tokenPosition) { return(ParseWithContext(s, context, tokenPosition).EvaluateToObject()); }
public BitwiseComplementExpression(TokenPosition position, Expression value) : base(position, value) { }
public T Evaluate <T>(string s, IParserContext context, TokenPosition tokenPosition) { return(ParseWithContext(s, context, tokenPosition).Evaluate <T>()); }