SearchOperand ParseAndExpression() { SearchOperand op1 = ParseAndGExpression(); SearchOperand op2; while (pos != searchRequest.Text.Length && searchRequest.Text[pos] == ' ') { pos++; } while (pos != searchRequest.Text.Length && (searchRequest.Text[pos] == '*' || searchRequest.Text[pos] == '^')) { switch (searchRequest.Text[pos]) { case '*': pos++; op2 = ParseAndGExpression(); op1.Add(op2, "*"); break; case '^': pos++; op2 = ParseAndGExpression(); op1.Add(op2, "^"); break; } } return(op1); }
public void Add(SearchOperand op2, string oper_sign) { if (oper_sign == "^") { for (int i = 0; i < op2.SearchTerms.Count; i++) { op2.SearchTerms[i].IsPresent = !op2.SearchTerms[i].IsPresent; } } this.Add(op2); this.UserText = String.Format("{0}{1}{2}", UserText, UserWordsForOperators.ContainsKey(oper_sign) ? UserWordsForOperators[oper_sign] : oper_sign, op2.UserText); }
SearchOperand ParseTerm() { while (searchRequest.Text[pos] == ' ') { pos++; } if (searchRequest.Text[pos] == '#') { int pos0 = ++pos; while (pos != searchRequest.Text.Length && searchRequest.Text[pos] >= '0' && searchRequest.Text[pos] <= '9') { pos++; } int index = Convert.ToInt32(searchRequest.Text.Substring(pos0, pos - pos0)); if (index < 1 || index > SearchRequests.Count) { throw new RequestParsingException(); } searchRequest.Text = searchRequest.Text.Substring(0, pos0 - 1) + "(" + SearchRequests[index - 1].Text + ")" + searchRequest.Text.Substring(pos); pos = pos0 - 1; } switch (searchRequest.Text[pos]) { case '\"': return(ParseSimpleRequest()); case '(': pos++; SearchOperand searchTerms = ParseOrExpression(); if (pos >= searchRequest.Text.Length || searchRequest.Text[pos] != ')') { throw new RequestParsingException(); } pos++; while (pos != searchRequest.Text.Length && searchRequest.Text[pos] == ' ') { pos++; } searchTerms.UserText = "(" + searchTerms.UserText + ")"; return(searchTerms); default: throw new RequestParsingException(); } }
SearchOperand ParseOrExpression() { SearchOperand op1 = ParseAndExpression(); SearchOperand op2; while (pos != searchRequest.Text.Length && searchRequest.Text[pos] == ' ') { pos++; } while (pos != searchRequest.Text.Length && searchRequest.Text[pos] == '+') { pos++; op2 = ParseAndExpression(); op1.Add(op2, "+"); } return(op1); }
SearchOperand ParseAnd_Expression() { SearchOperand op1 = ParseTerm(); SearchOperand op2; while (pos != searchRequest.Text.Length && searchRequest.Text[pos] == ' ') { pos++; } while (pos != searchRequest.Text.Length && searchRequest.Text[pos] == '.') { pos++; if (pos == searchRequest.Text.Length || searchRequest.Text[pos] != ' ') { throw new RequestParsingException(); } op2 = ParseTerm(); op1.Add(op2, ". "); } return(op1); }
public void Add(SearchOperand op2) { SearchTerms.AddRange(op2.SearchTerms); }
SearchOperand ParseSimpleRequest() { while (++pos < searchRequest.Text.Length && searchRequest.Text[pos] == ' ') { ; } int pos0 = pos; int length = 0; while (pos < searchRequest.Text.Length && searchRequest.Text[pos] != '\"') { length++; pos++; } if (pos == searchRequest.Text.Length) { throw new RequestParsingException(); } String termKey = searchRequest.Text.Substring(pos0, length); SearchOperand op = new SearchOperand(); SearchTerm searchTerm = new SearchTerm(termKey); pos++; while (pos < searchRequest.Text.Length && searchRequest.Text[pos] == ' ') { pos++; } if (pos < searchRequest.Text.Length - 1 && searchRequest.Text[pos] == '/' && searchRequest.Text[pos + 1] == '(') { pos++; pos0 = ++pos; length = 0; while (pos < searchRequest.Text.Length && searchRequest.Text[pos] != ')') { length++; pos++; } if (pos >= searchRequest.Text.Length) { throw new RequestParsingException(); } searchTerm.Fields = searchRequest.Text.Substring(pos0, length).Split(','); while (++pos != searchRequest.Text.Length && searchRequest.Text[pos] == ' ') { ; } } else { searchTerm.Fields = new string[0]; } op.UserText = null; foreach (SearchScenario scenario in SearchScenarios) { if (scenario.ItemPref == searchTerm.Key) { op.UserText = String.Format(UserTextMask, searchTerm.Name, scenario.ItemName); break; } } searchTerm.Name = searchTerm.Name.ToUpper(); op.SearchTerms.Add(searchTerm); return(op); }
/// <summary> A binary operation between two other operations. </summary> public SearchCombinator(SearchOperand a, LogicalOperator logicalOperator, SearchOperand b) { A = a; Operator = logicalOperator; B = b; }