示例#1
0
        private Parser CreateParser()
        {
            var referenceService  = new ReferenceService(_parsingData.ReferencedMatchers, _parsingData.StatMatchers);
            var regexGroupService = new RegexGroupService(_builderFactories.ValueBuilders);

            // The parsing pipeline using one IStatMatchers instance to parse a part of the stat.
            IStringParser <IIntermediateModifier> CreateInnerParser(IStatMatchers statMatchers) =>
            new CachingStringParser <IIntermediateModifier>(
                new StatNormalizingParser <IIntermediateModifier>(
                    new ResolvingParser(
                        MatcherDataParser.Create(
                            statMatchers.Data,
                            new StatMatcherRegexExpander(
                                referenceService, regexGroupService, statMatchers.MatchesWholeLineOnly).Expand),
                        referenceService,
                        new IntermediateModifierResolver(ModifierBuilder.Empty),
                        regexGroupService
                        )
                    )
                );

            Parallel.ForEach(_parsingData.StatMatchers, s => { _ = s.Data; });
            var innerParserCache = _parsingData.StatMatchers.ToDictionary(Funcs.Identity, CreateInnerParser);

            // The steps define the order in which the inner parsers, and by extent the IStatMatchers, are executed.
            IStringParser <IIntermediateModifier> StepToParser(TStep step)
            => innerParserCache[_parsingData.SelectStatMatcher(step)];

            // The full parsing pipeline.
            IStringParser <IReadOnlyList <IReadOnlyList <IIntermediateModifier> > > parser =
                new ValidatingParser <IReadOnlyList <IReadOnlyList <IIntermediateModifier> > >(
                    new StatNormalizingParser <IReadOnlyList <IReadOnlyList <IIntermediateModifier> > >(
                        new StatReplacingParser <IReadOnlyList <IIntermediateModifier> >(
                            new CompositeParser <IIntermediateModifier, TStep>(_parsingData.Stepper, StepToParser),
                            _parsingData.StatReplacers
                            )
                        )
                    );

            return(ps => AggregateAndBuild(ps, parser.Parse(ps.ModifierLine)));
        }
 private static MatcherDataParser CreateSut()
 => MatcherDataParser.Create(DefaultMatcherData, Funcs.Identity);