private async Task <List <ParsedInput> > ParseInput(string inputText, IRequestContext context, CancellationToken cancellationToken) { _synchronizationToken.Increment(); try { var parsedInputs = new List <ParsedInput>(); var processedInputText = inputText; var textPreprocessors = _textPreprocessors.OrderBy(p => p.Priority); foreach (var preprocessor in textPreprocessors) { cancellationToken.ThrowIfCancellationRequested(); processedInputText = await preprocessor.ProcessTextAsync(processedInputText, context, cancellationToken) .ConfigureAwait(false); } var textCursor = new TextCursor(processedInputText, context); foreach (var commandProcessor in _commandProcessors) { // Gets all the syntaxes that are of the same culture of the context or are culture invariant var syntaxes = commandProcessor.Syntaxes.Where( s => s.Culture.Equals(context.Culture) || s.Culture.Equals(CultureInfo.InvariantCulture)); foreach (var syntax in syntaxes) { cancellationToken.ThrowIfCancellationRequested(); textCursor.RightToLeftParsing = syntax.RightToLeftParsing; textCursor.Reset(); Expression expression; if (SyntaxParser.TryParse(textCursor, syntax, context, out expression)) { var commandParsedQuery = new ParsedInput(expression, commandProcessor); parsedInputs.Add(commandParsedQuery); break; } } } return(parsedInputs); } finally { _synchronizationToken.Decrement(); } }
private async Task<List<ParsedInput>> ParseInput(string inputText, IRequestContext context, CancellationToken cancellationToken) { _synchronizationToken.Increment(); try { var parsedInputs = new List<ParsedInput>(); var processedInputText = inputText; var textPreprocessors = _textPreprocessors.OrderBy(p => p.Priority); foreach (var preprocessor in textPreprocessors) { cancellationToken.ThrowIfCancellationRequested(); processedInputText = await preprocessor.ProcessTextAsync(processedInputText, context, cancellationToken) .ConfigureAwait(false); } var textCursor = new TextCursor(processedInputText, context); foreach (var commandProcessor in _commandProcessors) { // Gets all the syntaxes that are of the same culture of the context or are culture invariant var syntaxes = commandProcessor.Syntaxes.Where( s => s.Culture.Equals(context.Culture) || s.Culture.Equals(CultureInfo.InvariantCulture)); foreach (var syntax in syntaxes) { cancellationToken.ThrowIfCancellationRequested(); textCursor.RightToLeftParsing = syntax.RightToLeftParsing; textCursor.Reset(); Expression expression; if (SyntaxParser.TryParse(textCursor, syntax, context, out expression)) { var commandParsedQuery = new ParsedInput(expression, commandProcessor); parsedInputs.Add(commandParsedQuery); break; } } } return parsedInputs; } finally { _synchronizationToken.Decrement(); } }