예제 #1
0
        protected override IEnumerable <RuleMatch> OnMatch(ExplorerContext context)
        {
            foreach (var rule in _rules)
            {
                var potentials = context.InvokeRule(rule.Rule);

                foreach (var m in potentials)
                {
                    if (_rules.DoAllHaveNames)
                    {
                        yield return(new RuleMatch(
                                         this,
                                         m.Text,
                                         () => RuleOutput.ComputeOutput(
                                             m.Text,
                                             new Lazy <object?>(() => MakeMap(rule.Tag, m.ComputeOutput())))));
                    }
                    else
                    {
                        yield return(new RuleMatch(
                                         this,
                                         m.Text,
                                         () => RuleOutput.ComputeOutput(
                                             m.Text,
                                             new Lazy <object?>(() => m.ComputeOutput()))));
                    }
                }
            }
        }
예제 #2
0
        protected override IEnumerable <RuleMatch> OnMatch(ExplorerContext context)
        {
            var primaryMatches = context.InvokeRule(_primary);

            foreach (var primaryMatch in primaryMatches)
            {
                var primaryText         = primaryMatch.Text;
                var excludingContext    = context.SubContext(primaryText.Length);
                var excludedMatches     = excludingContext.InvokeRule(_excluded);
                var excludedExactLength = from ex in excludedMatches
                                          where ex.Text.Length == primaryText.Length
                                          select ex;

                if (!excludedExactLength.Any())
                {
                    var match = new RuleMatch(
                        this,
                        primaryText,
                        () => RuleOutput.ComputeOutput(
                            primaryText,
                            new Lazy <object?>(() => primaryMatch.ComputeOutput())));

                    yield return(match);
                }
            }
        }
예제 #3
0
        protected override IEnumerable <RuleMatch> OnMatch(ExplorerContext context)
        {
            var matches = RecurseMatch(
                context.ContextID,
                context,
                context.Text,
                0,
                1,
                ImmutableList <RuleMatch> .Empty);

            foreach (var m in matches)
            {
                yield return(m);
            }
            //  We are returning the matches in decreasing order of text length, so the empty one goes last
            if (!_min.HasValue || _min.Value == 0)
            {
                var matchText = context.Text.Take(0);

                yield return(new RuleMatch(
                                 this,
                                 matchText,
                                 () => RuleOutput.ComputeOutput(
                                     matchText,
                                     new Lazy <object?>(ImmutableArray <object> .Empty))));
            }
        }
예제 #4
0
        protected override IEnumerable <RuleMatch> OnMatch(ExplorerContext context)
        {
            var text = context.Text;

            if (text.HasContent)
            {
                var peekRaw = text.First();
                var peek    = IsCaseSensitive == false?char.ToUpperInvariant(peekRaw) : peekRaw;

                var first = IsCaseSensitive == false?char.ToUpperInvariant(First) : First;

                var last = IsCaseSensitive == false?char.ToUpperInvariant(Last) : Last;

                if (peek >= first && peek <= last)
                {
                    var matchText = text.Take(1);
                    var match     = new RuleMatch(
                        this,
                        matchText,
                        () => RuleOutput.ComputeOutput(matchText, new Lazy <object?>(matchText)));

                    return(new[] { match });
                }
            }

            return(RuleMatch.EmptyMatch);
        }
예제 #5
0
        private object?ComputeOutput(
            SubString matchText,
            ImmutableList <RuleMatch> newChildrenMatches)
        {
            Func <object> outputFactory = () => newChildrenMatches
                                          .Select(m => m.ComputeOutput())
                                          .ToImmutableArray();

            return(RuleOutput.ComputeOutput(matchText, new Lazy <object?>(outputFactory)));
        }
예제 #6
0
        protected override IEnumerable <RuleMatch> OnMatch(ExplorerContext context)
        {
            var matches     = _referencedRule.Match(context);
            var wrapMatches = from m in matches
                              select new RuleMatch(
                this,
                m.Text,
                () => RuleOutput.ComputeOutput(
                    m.Text,
                    new Lazy <object?>(() => m.ComputeOutput())));

            return(wrapMatches);
        }
예제 #7
0
        protected override IEnumerable <RuleMatch> OnMatch(ExplorerContext context)
        {
            var text = context.Text;

            if (text.Length == 0)
            {
                return(RuleMatch.EmptyMatch);
            }
            else
            {
                var matchText = text.Take(1);
                var match     = new RuleMatch(
                    this,
                    matchText,
                    () => RuleOutput.ComputeOutput(matchText, new Lazy <object?>(matchText)));

                return(new[] { match });
            }
        }
예제 #8
0
        protected override IEnumerable <RuleMatch> OnMatch(ExplorerContext context)
        {
            var text = context.Text;

            if (text.HasContent &&
                text.Length >= _literal.Length &&
                text.Take(_literal.Length).SequenceEqual(_literal, GetCharComparer()))
            {
                var matchText = text.Take(_literal.Length);
                var match     = new RuleMatch(
                    this,
                    matchText,
                    () => RuleOutput.ComputeOutput(
                        matchText,
                        new Lazy <object?>(() => matchText)));

                return(new[] { match });
            }
            else
            {
                return(RuleMatch.EmptyMatch);
            }
        }