Exemple #1
0
        private static (IDictionary <string, Rule>, List <string>) Parse(List <string> lines)
        {
            var rules    = new Dictionary <string, Rule>();
            var messages = new List <string>();

            foreach (var line in lines)
            {
                if (OrRule.MatchesRuleDescription(line))
                {
                    var rule = OrRule.Parse(line);
                    rules.Add(rule.Id, rule);
                }
                else if (MatchRule.MatchesRuleDescription(line))
                {
                    MatchRule matchRule = MatchRule.Parse(line);
                    rules.Add(matchRule.Id, matchRule);
                }
                else if (SequenceRule.MatchesRuleDescription(line))
                {
                    SequenceRule sequenceRule = SequenceRule.Parse(line);
                    rules.Add(sequenceRule.Id, sequenceRule);
                }
                else if (!string.IsNullOrEmpty(line))
                {
                    messages.Add(line);
                }
            }
            return(rules, messages);
        }
Exemple #2
0
            public static OrRule Parse(string line)
            {
                var idIdx = line.IndexOf(":");
                var id    = line.Substring(0, idIdx);

                var operands = line.Substring(idIdx + 1).Split("|", StringSplitOptions.RemoveEmptyEntries).ToList();

                var left  = operands[0];
                var right = operands[1];

                return(new OrRule(id)
                {
                    Left = SequenceRule.Parse($"{id}: {left}"),
                    Right = SequenceRule.Parse($"{id}: {right}")
                });
            }