private GherkinFileEditorInfo DoScan(string fileContent, ITextSnapshot textSnapshot, int lineOffset, I18n languageService, GherkinFileEditorParserListener gherkinListener, int errorRertyCount, out ScenarioEditorInfo firstUnchangedScenario) { const int MAX_ERROR_RETRY = 5; const int NO_ERROR_RETRY_FOR_LINES = 5; firstUnchangedScenario = null; try { Lexer lexer = languageService.lexer(gherkinListener); lexer.scan(fileContent, null, 0); } catch (PartialListeningDoneException partialListeningDoneException) { firstUnchangedScenario = partialListeningDoneException.FirstUnchangedScenario; } catch(LexingError lexingError) { int? errorLine = GetErrorLine(lexingError, lineOffset); if (errorLine != null && errorLine.Value < textSnapshot.LineCount - NO_ERROR_RETRY_FOR_LINES && errorRertyCount < MAX_ERROR_RETRY) { //add error classification & continue var restartLineNumber = errorLine.Value + 1; int restartPosition = textSnapshot.GetLineFromLineNumber(restartLineNumber).Start; string restartFileContent = textSnapshot.GetText(restartPosition, textSnapshot.Length - restartPosition); gherkinListener.LineOffset = restartLineNumber; return DoScan(restartFileContent, textSnapshot, restartLineNumber, languageService, gherkinListener, errorRertyCount + 1, out firstUnchangedScenario); } } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { // unknown error } return gherkinListener.GetResult(); }
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(); }