Пример #1
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))));
            }
        }
Пример #2
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()))));
                    }
                }
            }
        }
Пример #3
0
 public SelectionRule(IssuanceStatement issuanceStatement, RuleOutput output)
 {
     this._conditions = new NonNullableCollection <SelectionCondition>();
     Utility.VerifyNonNullArgument("issuanceStatement", issuanceStatement);
     base.IssuanceStatement = issuanceStatement;
     base.Output            = output;
 }
Пример #4
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);
                }
            }
        }
Пример #5
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);
        }
Пример #6
0
		public SelectionRule(IssuanceStatement issuanceStatement, RuleOutput output)
		{
			this._conditions = new NonNullableCollection<SelectionCondition>();
			Utility.VerifyNonNullArgument("issuanceStatement", issuanceStatement);
			base.IssuanceStatement = issuanceStatement;
			base.Output = output;
		}
Пример #7
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)));
        }
Пример #8
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);
        }
Пример #9
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 });
            }
        }
Пример #10
0
        public static void Start(string s)
        {
            CounterEngine engine     = new CounterEngine(s);
            Array         AllRules   = Enum.GetValues(enumType: typeof(CounterRules));
            RuleOutput    ouptutFile = new RuleOutput();

            // string[] Rules = AllRules.Split('|');

            Console.WriteLine("You can skip rule by entering -1 for input.");
            foreach (var rule in AllRules)
            {
                List <string> listOfInputs = new List <string>();
                System.Diagnostics.Debug.Print(rule.ToString());

                var operation   = (CounterRules)Enum.Parse(typeof(CounterRules), Convert.ToString(rule));
                var description = engine.GetRuleDescription(operation);
                Console.WriteLine(description);
                var pattern = @"{(.*?)}";
                var matches = Regex.Matches(description, pattern);
                foreach (var input in matches)
                {
                    string regExInput = CheckInput(Console.ReadLine());
                    if (regExInput.Equals(string.Empty))
                    {
                        break;
                    }
                    listOfInputs.Add(regExInput);
                }
                if (listOfInputs.Count > 0)
                {
                    var    outputResult = engine.Process(operation, listOfInputs);
                    string fileName     = System.Environment.CurrentDirectory.ToString();
                    fileName = fileName + "\\" + ouptutFile.GetOutputFileName(operation);
                    fileName = string.Format(fileName, listOfInputs.FirstOrDefault().Replace("|", ""), (listOfInputs.Count > 1)? listOfInputs.Skip(1).First().Replace("|", ""):"");

                    OutputWriter.WriteToFile(outputResult, fileName);
                }
            }
        }
Пример #11
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);
            }
        }
Пример #12
0
		public UnconditionalRule(IssuanceStatement issuanceStatement, RuleOutput output)
		{
			Utility.VerifyNonNullArgument("issuanceStatement", issuanceStatement);
			base.IssuanceStatement = issuanceStatement;
			base.Output = output;
		}
Пример #13
0
 public UnconditionalRule(IssuanceStatement issuanceStatement, RuleOutput output)
 {
     Utility.VerifyNonNullArgument("issuanceStatement", issuanceStatement);
     base.IssuanceStatement = issuanceStatement;
     base.Output            = output;
 }