private NPathBooleanExpression ParseBooleanOperator(IValue leftOperand) { NPathBooleanExpression boolean = new NPathBooleanExpression(); boolean.LeftOperand = leftOperand; Token currentToken = tokenizer.GetCurrentToken(); #region parse operator if (currentToken.IsType("and")) { boolean.Operator = "and"; } if (currentToken.IsType("or")) { boolean.Operator = "or"; } #endregion tokenizer.MoveNext(); if (CurrentIsValue()) { IValue rightValue = ParseExpression(); boolean.RightOperand = rightValue; return(boolean); } else { //unknown value? throw GetExpectedTokenException("Value"); } }
protected virtual bool EvalBooleanExpression(object item, NPathBooleanExpression booleanExpression) { //get left operand bool leftExpression = EvalExpression(item, booleanExpression.LeftOperand); //short circuit "AND"... bailout if leftexpression is "false" if (booleanExpression.Operator == "and" && leftExpression == false) { return(false); } //short circuit "OR"... bailout if leftexpression is "true" if (booleanExpression.Operator == "or" && leftExpression == true) { return(true); } //get right operand bool rightExpression = EvalExpression(item, booleanExpression.RightOperand); //"and" left and right operand if (booleanExpression.Operator == "and") { return(leftExpression && rightExpression); } //"or" left and right operand if (booleanExpression.Operator == "or") { return(leftExpression || rightExpression); } throw new Exception(string.Format("unknown boolean expression {0}", booleanExpression.Operator)); // do not localize }
protected virtual void EmitBooleanExpression(NPathBooleanExpression booleanExpression) { Write("("); EmitExpression(booleanExpression.LeftOperand); Write(" " + booleanExpression.Operator + " "); EmitExpression(booleanExpression.RightOperand); Write(")"); }
protected virtual void EmitExpression(IValue expression) { if (expression is NPathNotExpression) { NPathNotExpression value = (NPathNotExpression)expression; EmitNot(value); } if (expression is NPathFunction) { NPathFunction value = (NPathFunction)expression; EmitFunction(value); } if (expression is NPathParameter) { NPathParameter value = (NPathParameter)expression; EmitParameter(value); } if (expression is NPathNullValue) { NPathNullValue value = (NPathNullValue)expression; EmitNullValue(value); } if (expression is NPathBetweenExpression) { NPathBetweenExpression value = (NPathBetweenExpression)expression; EmitBetween(value); } if (expression is NPathBooleanValue) { NPathBooleanValue value = (NPathBooleanValue)expression; EmitBooleanValue(value); } if (expression is NPathDecimalValue) { NPathDecimalValue value = (NPathDecimalValue)expression; EmitDecimalValue(value); } if (expression is NPathDateTimeValue) { NPathDateTimeValue value = (NPathDateTimeValue)expression; EmitDateTimeValue(value); } if (expression is NPathGuidValue) { NPathGuidValue value = (NPathGuidValue)expression; EmitGuidValue(value); } if (expression is NPathStringValue) { NPathStringValue value = (NPathStringValue)expression; EmitStringValue(value); } if (expression is NPathIdentifier) { NPathIdentifier propertyPath = (NPathIdentifier)expression; EmitPropertyPath(propertyPath); } if (expression is NPathPropertyFilter) { NPathPropertyFilter propertyFilter = (NPathPropertyFilter)expression; EmitPropertyFilter(propertyFilter); } if (expression is NPathParenthesisGroup) { NPathParenthesisGroup parenthesisGroup = (NPathParenthesisGroup)expression; EmitParenthesisGroup(parenthesisGroup); } if (expression is NPathMathExpression) { NPathMathExpression mathExpression = (NPathMathExpression)expression; EmitMathExpression(mathExpression); } if (expression is NPathCompareExpression) { NPathCompareExpression compareExpression = (NPathCompareExpression)expression; EmitCompareExpression(compareExpression); } if (expression is NPathBooleanExpression) { NPathBooleanExpression boolExpression = (NPathBooleanExpression)expression; EmitBooleanExpression(boolExpression); } if (expression is NPathInExpression) { NPathInExpression value = (NPathInExpression)expression; EmitIn(value); } if (expression is NPathSearchFunction) { NPathSearchFunction value = (NPathSearchFunction)expression; EmitSearchFunction(value); } }
protected virtual bool EvalBooleanExpression(object item, NPathBooleanExpression booleanExpression) { //get left operand bool leftExpression = EvalExpression(item, booleanExpression.LeftOperand); //short circuit "AND"... bailout if leftexpression is "false" if (booleanExpression.Operator == "and" && leftExpression == false) { return false; } //short circuit "OR"... bailout if leftexpression is "true" if (booleanExpression.Operator == "or" && leftExpression == true) { return true; } //get right operand bool rightExpression = EvalExpression(item, booleanExpression.RightOperand); //"and" left and right operand if (booleanExpression.Operator == "and") { return leftExpression && rightExpression; } //"or" left and right operand if (booleanExpression.Operator == "or") { return leftExpression || rightExpression; } throw new Exception(string.Format("unknown boolean expression {0}", booleanExpression.Operator)); // do not localize }
private SqlSearchCondition EvalBooleanExpression(NPathBooleanExpression booleanExpression) { SqlExpression leftExpression = EvalExpression(booleanExpression.LeftOperand); SqlSearchCondition search; if (leftExpression is SqlSearchCondition) search = (SqlSearchCondition) leftExpression; else { if (conditionChainOwner is SqlSearchCondition) search = (SqlSearchCondition) conditionChainOwner; else search = conditionChainOwner.GetCurrentSqlSearchCondition(); } bool orNext = String.Compare(booleanExpression.Operator, "or", true, CultureInfo.InvariantCulture) == 0 ; if (orNext) search.OrNext = orNext; EvalExpression(booleanExpression.RightOperand); return conditionChainOwner.GetCurrentSqlSearchCondition(); }
private NPathBooleanExpression ParseBooleanOperator(IValue leftOperand) { NPathBooleanExpression boolean = new NPathBooleanExpression(); boolean.LeftOperand = leftOperand; Token currentToken = tokenizer.GetCurrentToken(); #region parse operator if (currentToken.IsType("and")) boolean.Operator = "and"; if (currentToken.IsType("or")) boolean.Operator = "or"; #endregion tokenizer.MoveNext(); if (CurrentIsValue()) { IValue rightValue = ParseExpression(); boolean.RightOperand = rightValue; return boolean; } else { //unknown value? throw GetExpectedTokenException("Value"); } }