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);

            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 = dialectServices.GetLanguage(fileContent);

            var gherkinDialect  = dialectServices.GetGherkinDialect(language);
            var gherkinListener = new GherkinParserListener(sourceFilePath);

            GherkinScanner scanner = new GherkinScanner(gherkinDialect, 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);

            VisualStudioTracer.Assert(firstAffectedScenario != null, "first affected scenario is null");
            int parseStartPosition = textSnapshot.GetLineFromLineNumber(firstAffectedScenario.GetStartLine()).Start;

            string fileContent = textSnapshot.GetText(parseStartPosition, textSnapshot.Length - parseStartPosition);

            var gherkinListener = new GherkinTextBufferPartialParserListener(
                previousScope.GherkinDialect,
                textSnapshot, projectScope,
                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);
        }