private GherkinFileScopeChange FullParse(ITextSnapshot textSnapshot, GherkinDialect gherkinDialect) { visualStudioTracer.Trace("Start full parsing", ParserTraceCategory); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); partialParseCount = 0; var gherkinListener = new GherkinTextBufferParserListener(gherkinDialect, textSnapshot, projectScope.Classifications); var scanner = new GherkinScanner(gherkinDialect, textSnapshot.GetText(), 0); scanner.Scan(gherkinListener); var gherkinFileScope = gherkinListener.GetResult(); var result = new GherkinFileScopeChange( gherkinFileScope, true, true, gherkinFileScope.GetAllBlocks(), Enumerable.Empty<IGherkinFileBlock>()); stopwatch.Stop(); TraceFinishParse(stopwatch, "full", result); return result; }
public Feature Parse(TextReader featureFileReader, string sourceFilePath) { var fileContent = featureFileReader.ReadToEnd(); var language = languageServices.GetLanguage(fileContent); I18n languageService = languageServices.GetLanguageService(language); var gherkinListener = new GherkinParserListener(sourceFilePath); GherkinScanner scanner = new GherkinScanner(languageService, fileContent); scanner.Scan(gherkinListener); Feature feature = gherkinListener.GetResult(); if (gherkinListener.Errors.Count > 0) throw new SpecFlowParserException(gherkinListener.Errors); Debug.Assert(feature != null, "If there were no errors, the feature cannot be null"); feature.Language = language.LanguageForConversions.Name; return feature; }
private GherkinFileScopeChange PartialParse(GherkinTextBufferChange change, IGherkinFileScope previousScope) { visualStudioTracer.Trace("Start incremental parsing", ParserTraceCategory); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); partialParseCount++; var textSnapshot = change.ResultTextSnapshot; IScenarioBlock firstAffectedScenario = GetFirstAffectedScenario(change, previousScope); Debug.Assert(firstAffectedScenario != null); int parseStartPosition = textSnapshot.GetLineFromLineNumber(firstAffectedScenario.GetStartLine()).Start; string fileContent = textSnapshot.GetText(parseStartPosition, textSnapshot.Length - parseStartPosition); var gherkinListener = new GherkinTextBufferPartialParserListener( previousScope.GherkinDialect, textSnapshot, projectScope.Classifications, previousScope, change.EndLine, change.LineCountDelta); var scanner = new GherkinScanner(previousScope.GherkinDialect, fileContent, firstAffectedScenario.GetStartLine()); IScenarioBlock firstUnchangedScenario = null; try { scanner.Scan(gherkinListener); } catch (PartialListeningDoneException partialListeningDoneException) { firstUnchangedScenario = partialListeningDoneException.FirstUnchangedScenario; } var partialResult = gherkinListener.GetResult(); var result = MergePartialResult(previousScope, partialResult, firstAffectedScenario, firstUnchangedScenario, change.LineCountDelta); stopwatch.Stop(); TraceFinishParse(stopwatch, "incremental", result); return result; }
private GherkinFileEditorInfo DoParsePartial(string fileContent, I18n languageService, int lineOffset, out ScenarioEditorInfo firstUnchangedScenario, ITextSnapshot textSnapshot, GherkinFileEditorInfo previousGherkinFileEditorInfo, int changeLastLine, int changeLineDelta) { GherkinScanner scanner = new GherkinScanner(languageService, fileContent, lineOffset); var gherkinListener = new GherkinFileEditorParserListener(textSnapshot, classifications, previousGherkinFileEditorInfo, changeLastLine, changeLineDelta); firstUnchangedScenario = null; try { scanner.Scan(gherkinListener); } catch (PartialListeningDoneException partialListeningDoneException) { firstUnchangedScenario = partialListeningDoneException.FirstUnchangedScenario; } return gherkinListener.GetResult(); }