/// <inheritdoc /> protected override IEnumerable <GrammerDefinition> LogicalOperatorDefinitions() { var logicalOperations = base.LogicalOperatorDefinitions().ToDictionary(g => g.Name); logicalOperations["EQ"] = logicalOperations["EQ"].As <BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.Equals))); logicalOperations["NE"] = logicalOperations["NE"].As <BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.NotEquals))); logicalOperations["GT"] = logicalOperations["GT"].As <BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.GreaterThan))); logicalOperations["GE"] = logicalOperations["GE"].As <BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.GreaterThanOrEquals))); logicalOperations["LT"] = logicalOperations["LT"].As <BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.LessThan))); logicalOperations["LE"] = logicalOperations["LE"].As <BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.LessThanOrEquals))); logicalOperations["AND"] = logicalOperations["AND"].As <BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => (Expression)Expression.And(Expression.Convert(left, typeof(bool)), Expression.Convert(right, typeof(bool)))); logicalOperations["OR"] = logicalOperations["OR"].As <BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => (Expression)Expression.Or(Expression.Convert(left, typeof(bool)), Expression.Convert(right, typeof(bool)))); logicalOperations["CT"] = new BinaryOperatorDefinition("CT", "ct", 16, (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.Contains))); logicalOperations["RX"] = new BinaryOperatorDefinition("RX", "rx", 16, (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.Regex))); //logicalOperations["CT"].As<BinaryOperatorDefinition>().With(expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.Contains))); //Niceties that don't seem work because they mess up the parser (other operators are contained within them) //logicalOperations["NEQ"] = logicalOperations["NE"].As<BinaryOperatorDefinition>().With(name: "NEQ", regex: "neq", expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.NotEquals))); //logicalOperations["GTE"] = logicalOperations["GE"].As<BinaryOperatorDefinition>().With(name: "GTE", regex: "gte", expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.GreaterThanOrEquals))); //logicalOperations["LTE"] = logicalOperations["LE"].As<BinaryOperatorDefinition>().With(name: "LTE", regex: "lte", expressionBuilder: (left, right) => Expression.Call(CompareMethod, left, right, Expression.Constant(CompareType.LessThanOrEquals))); return(logicalOperations.Values); }
/// <summary> /// Creates a new BinaryOperatorDefinition with the given expression builder. /// </summary> /// <param name="definition">The existing BinaryOperatorDefinition.</param> /// <param name="name">New name.</param> /// <param name="regex">New regex.</param> /// <param name="orderOfPrecedence">New order of precedence.</param> /// <param name="expressionBuilder">The expression builder.</param> /// <returns>The new BinaryOperatorDefinition.</returns> public static BinaryOperatorDefinition With(this BinaryOperatorDefinition definition, String name = null, String regex = null, int?orderOfPrecedence = null, Func <Expression, Expression, Expression> expressionBuilder = null) { return(new BinaryOperatorDefinition( name ?? definition.Name, regex ?? definition.Regex, orderOfPrecedence ?? definition.OrderOfPrecedence ?? -1, expressionBuilder)); }