public static BonsaiExpression PostProcess(BonsaiExpression expression, PostProcessor top, PostProcessor next) => Switch <BonsaiExpression> .On(expression) .Match <BinaryLogic>(x => new BinaryLogic(x.Operator, top(x.Left), top(x.Right))) .Match <Column>(x => x) .Match <Comparison>(x => new Comparison(x.Operator, top(x.Left), top(x.Right))) .Match <Constant>(x => x) .Match <UnaryLogic>(x => new UnaryLogic(x.Operator, top(x.Expression))) .Match <List>(x => new List(x.Values.Select(top.Invoke), x.ElementType, x.Type)) .OrThrow();
public override string Emit(BonsaiExpression exp, Emitter top, Emitter next) => Switch <string> .On(exp) .Match <In>(@in => { var list = top(@in.Haystack); return(list != string.Empty ? $"{top(@in.Needle)} IN ({list})" : "0 <> 0"); }) .Else(() => next(exp));
public override BonsaiExpression PostProcess(BonsaiExpression exp, PostProcessor top, PostProcessor next) { return(Switch <BonsaiExpression> .On(exp) .Match <Comparison>(x => { if (x.Left is Column) { return next(x); } if (x.Right is Column) { return new Comparison(x.Operator, top(x.Right), top(x.Left)); } return next(x); }) .Else(() => next(exp))); }
public UnaryLogic(UnaryLogicOperator @operator, BonsaiExpression expression) : base(typeof(bool)) { Operator = @operator; Expression = expression; }
public Comparison(ComparisonOperator @operator, BonsaiExpression left, BonsaiExpression right) : base(typeof(bool)) { Operator = @operator; Left = AssertNotNull(left); Right = AssertNotNull(right); }
public static string Emit(BonsaiExpression exp, Emitter top, Emitter next) => Switch <string> .On(exp) .Match <Constant>(constant =>
public In(BonsaiExpression needle, BonsaiExpression haystack) : base(typeof(bool)) { Needle = needle; Haystack = haystack; }
public override BonsaiExpression PostProcess(BonsaiExpression exp, PostProcessor top, PostProcessor next) => exp is In @in
public BinaryLogic(BinaryLogicOperator @operator, BonsaiExpression left, BonsaiExpression right) : base(typeof(bool)) { Operator = @operator; Left = AssertNotNull(left); Right = AssertNotNull(right); }
/// <summary> /// Expects PostCompilers.NormalizeComparisons to have been applied. /// </summary> public override BonsaiExpression PostProcess(BonsaiExpression exp, PostProcessor top, PostProcessor next) => Switch <BonsaiExpression> .On(exp) .Match <Comparison>(x =>
public virtual string Emit(BonsaiExpression exp, Emitter top, Emitter next) => next(exp);
public virtual BonsaiExpression PostProcess(BonsaiExpression exp, PostProcessor top, PostProcessor next) => next(exp);
public override string Emit(BonsaiExpression exp, Emitter top, Emitter next) => SqlEmitter.Emit(exp, top, next);
public override BonsaiExpression PostProcess(BonsaiExpression exp, PostProcessor top, PostProcessor next) => RootCompiler.PostProcess(exp, top, next);