private static void RemoveDisallowedRepeats(LexerCursor inputCursor, List <LexCapture> elements) { LexCapture lastOperator = null; foreach (var element in inputCursor.GetVitalCapture()) { if (element.Type.Name == null) { continue; } element.Value = (element.Value ?? "").Trim(); if (string.IsNullOrWhiteSpace(element.Value)) { element.Value = " "; } if (IsDisallowedRepeats(elements, lastOperator, element)) { continue; } elements.Add(element); switch (element.Type.Name) { case LuceneQueryParser.KeywordParenthesesClose: case LuceneQueryParser.KeywordParenthesesOpen: case LuceneQueryParser.KeywordQuoteContent: case LuceneQueryParser.KeywordOperand: lastOperator = null; break; case LuceneQueryParser.KeywordOperator: lastOperator = element; break; // ReSharper disable once RedundantEmptySwitchSection default: break; } } }
private static bool IsDisallowedRepeats(List <LexCapture> elements, LexCapture lastOperator, LexCapture element) { if (lastOperator?.Value == element.Value && lastOperator?.Type?.Name == element.Type.Name) { return(true); } if (elements.LastOrDefault()?.Value != element.Value) { return(false); } if (element.Value?.Length != 1) { return(true); } return(!Repeatables.Contains(element.Value[0])); }