protected Expression ExpressionInfixRight(Parsed.Expression left, InfixOperator op) { Whitespace(); var right = Parse(() => Expression(op.precedence)); if (right) { // We assume that the character we use for the operator's type is the same // as that used internally by e.g. Runtime.Expression.Add, Runtime.Expression.Multiply etc var expr = new BinaryExpression(left, right, op.type); return(expr); } return(null); }
private static bool compare(this IFluentPathValue left, InfixOperator comp, IFluentPathValue right) { if (left.Value == null || right.Value == null) { throw Error.InvalidOperation("'{0)' requires both operands to be values".FormatWith(comp)); } if (left.Value.GetType() != right.Value.GetType()) { throw Error.InvalidOperation("Operands to '{0}' must be of the same type".FormatWith(comp)); } if (left.Value is string) { var result = String.Compare(left.AsString(), right.AsString()); if (comp == InfixOperator.LessThan) { return(result == -1); } if (comp == InfixOperator.GreaterThan) { return(result == 1); } } else { if (comp == InfixOperator.LessThan) { return((dynamic)left.Value < (dynamic)right.Value); } if (comp == InfixOperator.GreaterThan) { return((dynamic)left.Value > (dynamic)right.Value); } } throw Error.InvalidOperation("Comparison failed on operator '{0}'".FormatWith(comp)); }
internal static Parser <InfixOperator> Operator(string op, InfixOperator opType) { return(Parse.String(op).Token().Return(opType)); }
protected Expression ExpressionInfixRight(Parsed.Expression left, InfixOperator op) { Whitespace (); var right = Parse(() => Expression (op.precedence)); if (right) { // We assume that the character we use for the operator's type is the same // as that used internally by e.g. Runtime.Expression.Add, Runtime.Expression.Multiply etc var expr = new BinaryExpression (left, right, op.type); return expr; } return null; }
public static Evaluator Infix(this Evaluator left, InfixOperator op, Evaluator right) { return((f, c) => { var leftNodes = left(f, c); var rightNodes = right(f, c); IEnumerable <IFluentPathValue> result = null; switch (op) { case InfixOperator.Equals: result = leftNodes.IsEqualTo(rightNodes); break; case InfixOperator.Equivalent: result = leftNodes.IsEquivalentTo(rightNodes); break; case InfixOperator.GreaterThan: result = leftNodes.GreaterThan(rightNodes); break; case InfixOperator.GreaterOrEqual: result = leftNodes.GreaterOrEqual(rightNodes); break; case InfixOperator.LessThan: result = leftNodes.LessThan(rightNodes); break; case InfixOperator.LessOrEqual: result = leftNodes.LessOrEqual(rightNodes); break; case InfixOperator.Add: result = leftNodes.Add(rightNodes); break; case InfixOperator.Sub: result = leftNodes.Sub(rightNodes); break; case InfixOperator.Mul: result = leftNodes.Mul(rightNodes); break; case InfixOperator.Div: result = leftNodes.Div(rightNodes); break; case InfixOperator.And: result = leftNodes.And(rightNodes); break; case InfixOperator.Or: result = leftNodes.Or(rightNodes); break; case InfixOperator.Xor: result = leftNodes.Xor(rightNodes); break; case InfixOperator.Implies: result = leftNodes.Implies(rightNodes); break; case InfixOperator.Union: result = leftNodes.Union(rightNodes); break; case InfixOperator.Concat: result = leftNodes.Add(rightNodes); break; // should only work for strings ;-) case InfixOperator.In: result = leftNodes.SubsetOf(rightNodes); break; default: throw Error.NotImplemented("Infix operator '{0}' is not yet implemented".FormatWith(op)); } return result; }); }
public Group(string start, string end, InfixOperator op) : this(start, end, op.Lbp, op.Function) { }
public IType GetInfixOperationResultType(InfixOperator @operator) => null;