Пример #1
0
        internal void AddRuleFromString(string line)
        {
            var tokens = line.Split(':');
            var id     = int.Parse(tokens[0]);

            if (tokens[1].Contains('\"'))
            {
                Rules[id] = new CharacterRule()
                {
                    Id    = id,
                    Value = tokens[1].Trim().Substring(1, 1)
                };
            }
            else
            {
                var subrules    = tokens[1].Split('|');
                var concatRules = subrules.Select(x => ParseIds(id, x)).ToArray();
                if (concatRules.Length == 1)
                {
                    Rules[id] = concatRules[0];
                }
                else
                {
                    var rule = new OrRule()
                    {
                        Id = id,
                    };
                    rule.SubRules.AddRange(concatRules);
                    Rules[id] = rule;
                }
            }
        }
Пример #2
0
        public override CharacterRule Reduce(RuleSet ruleset)
        {
            CharacterRule newRule = null;

            if (SubRuleIds.All(id => (ruleset.Rules[id] is CharacterRule)))
            {
                StringBuilder builder = new StringBuilder();
                foreach (var id in SubRuleIds)
                {
                    if (ruleset.Rules[id] is CharacterRule charRule)
                    {
                        builder.Append(charRule.Value);
                    }
                }
                newRule = new CharacterRule()
                {
                    Id    = Id,
                    Value = builder.ToString()
                };
            }
            return(newRule);
        }