public void ParseValuesIsCultureInvariant()
        {
            var groups = new Dictionary <string, string>
            {
                { ValueGroupPrefix + "0", "1.23" },
            };
            var valueBuildersMock = new Mock <IValueBuilders>();
            var parser            = new RegexGroupService(valueBuildersMock.Object);

            parser.ParseValues(groups);

            valueBuildersMock.Verify(b => b.Create(1.23));
        }
Exemple #2
0
        private IStringParser <IReadOnlyList <Modifier> > 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.
            return
                (new ValidatingParser <IReadOnlyList <Modifier> >(
                     new StatNormalizingParser <IReadOnlyList <Modifier> >(
                         new ResultMappingParser <IReadOnlyList <IReadOnlyList <Modifier> >, IReadOnlyList <Modifier> >(
                             new StatReplacingParser <IReadOnlyList <Modifier> >(
                                 new ResultMappingParser <IReadOnlyList <IIntermediateModifier>,
                                                          IReadOnlyList <Modifier> >(
                                     new CompositeParser <IIntermediateModifier, TStep>(_parsingData.Stepper,
                                                                                        StepToParser),
                                     AggregateAndBuild),
                                 _parsingData.StatReplacers
                                 ),
                             (_, ls) => ls.Flatten().ToList()
                             )
                         )
                     ));
        }
Exemple #3
0
        private IParser <IReadOnlyList <Modifier> > 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.
            IParser <IIntermediateModifier> CreateInnerParser(IStatMatchers statMatchers) =>
            new CachingParser <IIntermediateModifier>(
                new StatNormalizingParser <IIntermediateModifier>(
                    new ResolvingParser(
                        new MatcherDataParser(
                            new StatMatcherRegexExpander(statMatchers, referenceService, regexGroupService)),
                        referenceService,
                        new IntermediateModifierResolver(new ModifierBuilder()),
                        regexGroupService
                        )
                    )
                );

            var innerParserCache = new Dictionary <IStatMatchers, IParser <IIntermediateModifier> >();

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

            // The full parsing pipeline.
            return
                (new ValidatingParser <IReadOnlyList <Modifier> >(
                     new StatNormalizingParser <IReadOnlyList <Modifier> >(
                         new ResultMappingParser <IReadOnlyList <IReadOnlyList <Modifier> >, IReadOnlyList <Modifier> >(
                             new StatReplacingParser <IReadOnlyList <Modifier> >(
                                 new ResultMappingParser <IReadOnlyList <IIntermediateModifier>,
                                                          IReadOnlyList <Modifier> >(
                                     new CompositeParser <IIntermediateModifier, TStep>(_parsingData.Stepper,
                                                                                        StepToParser),
                                     AggregateAndBuild),
                                 _parsingData.StatReplacers
                                 ),
                             ls => ls.Flatten().ToList()
                             )
                         )
                     ));
        }