private static void StructureSyntax(List <LexCapture> elements, ScopeBuilder scopebuilder) { foreach (var element in elements) { switch (element.Type.Name) { case LuceneQueryParser.KeywordParenthesesOpen: scopebuilder.BeginSubGroup(); break; case LuceneQueryParser.KeywordParenthesesClose: scopebuilder.ExitSubGroup(); break; case LuceneQueryParser.KeywordQuoteContent: switch (scopebuilder.LastestGroup.LastOrDefault()) { case StringSanitizerToken stringToken: var stringGroup = new StringGroupSanitizerToken(); scopebuilder.LastestGroup.Last.Value = stringGroup; stringGroup.Tokens.Add(stringToken); stringGroup.Tokens.Add(new StringSanitizerToken(element.Value)); break; case StringGroupSanitizerToken group: group.Tokens.Add(new StringSanitizerToken(element.Value)); break; default: scopebuilder.LastestGroup.AddLast(new StringSanitizerToken(element.Value)); break; } break; case LuceneQueryParser.KeywordOperator: switch (element.Value) { case "AND": case "OR": scopebuilder.LastestGroup.AddLast(new BinaryOperatorSanitizerToken(element.Value)); break; case "NOT": scopebuilder.LastestGroup.AddLast(new UnaryOperatorSanitizerToken("!")); break; case "+": case "-": case "!": scopebuilder.LastestGroup.AddLast(new UnaryOperatorSanitizerToken(element.Value)); break; default: throw new InvalidOperationException(); } break; case LuceneQueryParser.KeywordOperand: scopebuilder.LastestGroup.AddLast(new OperandSanitizerToken(element.Value)); break; case LuceneQueryParser.KeywordWhiteSpace: scopebuilder.LastestGroup.AddLast(new DelimiterSanitizerToken()); break; } } }