private void DealConstraintWord(string part) { if (_property == null) { _property = part; } else if (_comparison == null) { _comparison = part; } else { var propertyConstraint = CreatePropertyConstraint(_property, _comparison, part); if (_concat.HasValue && _current != null) { _current = _f.Binary(_current, _concat.Value, propertyConstraint); _concat = null; } else { _current = propertyConstraint; } _property = null; _comparison = null; } }
public void Parse(string filter, IQuery query) { _query = query; _mainTable = query.MainTable; _column = null; _comparison = null; _concat = null; _current = null; _f = QueryFactory.Instance; _bracketStack = new Stack <StackItem>(); _filter = filter; _filterIndex = 0; while (true) { var part = this.ReadPart(); if (part == string.Empty) { break; } this.DealPart(part); } query.Where = _current; }
/// <summary> /// Determines if this object is equal to another /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { BinaryOperator?op = obj as BinaryOperator?; if (op != null) { return(Equals(op.Value)); } return(false); }
private void DealPart(string part) { if (part == "(" || part == ")") { this.DealBracket(part); } else if (part.EqualsIgnoreCase("and") || part.EqualsIgnoreCase("or")) { _concat = part.EqualsIgnoreCase("and") ? BinaryOperator.And : BinaryOperator.Or; } else { this.DealConstraintWord(part); } }
public void Parse(string filter, IQuery query) { _query = query; _mainTable = query.MainTable; _column = null; _comparison = null; _concat = null; _current = null; _f = QueryFactory.Instance; _bracketStack = new Stack<StackItem>(); using (_reader = new StringReader(filter)) { while (true) { var part = this.ReadPart(); if (part == string.Empty) break; this.DealPart(part); } } query.Where = _current; }
public FieldComparsionViewModel(IValidationScope context, IVariable <Type> field, BinaryOperator?op = null, ComparsionValueViewModel value = null) { this.KeyDownCommand = new RelayCommand <KeyEventArgs>(args => { if (args.Key == Key.Return || args.Key == Key.Enter) { RequestReadyMode(); } }); this.context = context; this.field = field; this.op = op; this.value = value; this.state = field == null ? FieldComparsionState.Phase1_FieldMissing : op == null ? FieldComparsionState.Phase2_OperatorMissing : value == null ? FieldComparsionState.Phase3_ValueMissing : FieldComparsionState.ReadyToUse; ComputePossibleStates(); UpdateField(); }
public IConstraint Parse(string filter) { _property = null; _comparison = null; _concat = null; _current = null; _f = QueryFactory.Instance; _bracketStack = new Stack <StackItem>(); using (_reader = new StringReader(filter)) { while (true) { var part = this.ReadPart(); if (part == null) { break; } this.DealPart(part); } } return(_current); }
public async Task <BinaryOperator?> ParseLoneOperatorSymbol(Parser owner) { BinaryOperator?result = null; if (next != null) { result = await next.ParseLoneOperatorSymbol(owner); } if (result != null) { return(result); } foreach (BinaryOpSpec op in operators) { if (await owner.MaybeToken(op.token, op.alphaNum)) { return(op.op); } } return(null); }
private void DealBracket(string part) { if (part == "(") { if (_concat.HasValue && _current != null) { _bracketStack.Push(new StackItem { Concat = _concat.Value, Constraint = _current }); _concat = null; _current = null; } } else { if (_bracketStack.Count > 0) { var outBracket = _bracketStack.Pop(); _current = _f.Binary(outBracket.Constraint, outBracket.Concat, _current); } } }
private void DealConstraintWord(string part) { //part 表示列名 if (_column == null) { //可能使用了引用属性,例如表达式:User.Name eq 'huqf' var properties = part.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (properties.Length > 1) { ITableSource lastTable = _mainTable; for (int i = 0; i < properties.Length; i++) { var property = properties[i]; var mp = lastTable.EntityRepository.EntityMeta.ManagedProperties.GetCompiledProperties().Find(property); if (mp == null) { throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", property)); } var refProperty = mp as IRefEntityProperty; if (refProperty != null) { lastTable = _f.FindOrCreateJoinTable(_query, lastTable, refProperty); } else { _column = lastTable.Column(mp); } } if (_column == null) { throw new InvalidProgramException(string.Format("{0} 查询条件出错:属性表达式不能以引用实体属性结尾。", part)); } } else { var mp = _properties.Find(part, true); if (mp == null) { throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", part)); } _column = _mainTable.Column(mp); } } //part 表示操作符 else if (_comparison == null) { _comparison = part; } //part 表示值 else { var propertyConstraint = CreateColumnConstraint(_comparison, part); if (_concat.HasValue && _current != null) { _current = _f.Binary(_current, _concat.Value, propertyConstraint); _concat = null; } else { _current = propertyConstraint; } _column = null; _comparison = null; } }
private void DealConstraintWord(string part) { //part 表示列名 if (_column == null) { //可能使用了引用属性,例如表达式:User.Name eq 'huqf' var properties = part.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (properties.Length > 1) { ITableSource lastTable = _mainTable; for (int i = 0; i < properties.Length; i++) { var property = properties[i]; var mp = lastTable.EntityRepository.EntityMeta.ManagedProperties.GetCompiledProperties().Find(property); if (mp == null) throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", property)); var refProperty = mp as IRefEntityProperty; if (refProperty != null) { lastTable = _f.FindOrCreateJoinTable(_query, lastTable, refProperty); } else { _column = lastTable.Column(mp); } } if (_column == null) { throw new InvalidProgramException(string.Format("{0} 查询条件出错:属性表达式不能以引用实体属性结尾。", part)); } } else { var mp = _properties.Find(part, true); if (mp == null) throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", part)); _column = _mainTable.Column(mp); } } //part 表示操作符 else if (_comparison == null) { _comparison = part; } //part 表示值 else { var propertyConstraint = CreateColumnConstraint(_comparison, part); if (_concat.HasValue && _current != null) { _current = _f.Binary(_current, _concat.Value, propertyConstraint); _concat = null; } else { _current = propertyConstraint; } _column = null; _comparison = null; } }
private void DealBracket(string part) { if (part == "(") { if (_concat.HasValue && _current != null) { _bracketStack.Push(new StackItem { Concat = _concat.Value, Constraint = _current }); _concat = null; _current = null; } } else { if (_bracketStack.Count > 0) { var outBracket = _bracketStack.Pop(); _current = _f.Binary(outBracket.Constraint, outBracket.Concat, _current); } } }
private object EvaluateList() { LinkedList <object> list = new LinkedList <object>(_tokens); // evaluate unary operators LinkedListNode <object> x = list.First; while (x != null) { UnaryOperator?op = x.Value as UnaryOperator?; if (op != null) { x.Value = PerformUnaryOp(op.Value, x.Previous?.Value, x.Next.Value); list.Remove(x.Next); } x = x.Next; } // queue and evaluate binary operators BinaryOpQueue opqueue = new BinaryOpQueue(list); x = list.First.Next; // skip the first operand while (x != null) { BinaryOperator?op = x.Value as BinaryOperator?; if (op == null) { throw ThrowHelper.MissingBinaryOp(x.Previous.Value, x.Value); } else { if (x.Next == null) { throw new ArgumentException("Expression cannot end in a binary operation [" + x.Value + "]"); } } x = x.Next.Next; // skip the operand } BinOpNodePair nodePair; while (opqueue.Dequeue(out nodePair)) { nodePair.Node.Previous.Value = PerformBinaryOp( nodePair.Operator, nodePair.Node.Previous.Value, nodePair.Node.Next.Value ); list.Remove(nodePair.Node.Next); list.Remove(nodePair.Node); } IEvaluator expr = list.First.Value as IEvaluator; if (expr == null) { return(list.First.Value); } else { return(expr.Evaluate()); } }
public async Task <FunctionDefinition> ParseOperatorDefinition() { if (!await MaybeToken("operator", true)) { return(null); } TypeSyntax returnType; if (await MaybeToken("<", false)) { returnType = await ParseType(); if (!await MaybeToken(">", false)) { throw new NotImplementedException(); } } else { returnType = null; } string operatorName = null; BinaryOperator?binaryOperator = await binaryOpParsers[0].ParseLoneOperatorSymbol(this); if (binaryOperator != null) { operatorName = RuntimeUtil.NameForOperator(binaryOperator.Value); } // TODO: Unary operators, implicit operator if (operatorName == null) { throw new NotImplementedException(); } if (!await MaybeToken("(", false)) { throw new NotImplementedException(); } ParameterDefinition[] parameters; if (await MaybeToken(")", false)) { parameters = new ParameterDefinition[0]; } else { parameters = await ParseParameterList(); if (parameters == null) { throw new NotImplementedException(); } if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } } BlockStatement functionCode = await ParseBlock(); if (functionCode == null) { throw new NotImplementedException(); } return(new FunctionDefinition { Name = operatorName, Parameters = parameters, Body = functionCode, ReturnType = returnType, Static = true }); }
public AssignmentStatement(BinaryOperator?op, Expression left, Expression right, SourceRange source) : base(source) => (Op, Left, Right) = (op, left, right);
private void DealPart(string part) { if (part == "(" || part == ")") { this.DealBracket(part); } else if (part.EqualsIgnoreCase("and") || part.EqualsIgnoreCase("or")) { _concat = part.EqualsIgnoreCase("and") ? BinaryOperator.And : BinaryOperator.Or; } else { this.DealConstraintWord(part); } }
public OperatorDescriptor(BinaryOperator binaryOperator) { this.binaryOperator = binaryOperator; hash = (int)binaryOperator + Enum.GetNames(typeof(UnaryOperator)).Length; }