Example #1
0
 private void RuleSpecsChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.OldStartingIndex > -1)
     {
         PatternNode <TData, TOffset> startNode = _pattern.Children.ElementAt(e.OldStartingIndex);
         foreach (Pattern <TData, TOffset> node in startNode.GetNodes().Take(e.OldItems.Count).Cast <Pattern <TData, TOffset> >().ToArray())
         {
             _ruleIds.Remove(node.Name);
             node.Remove();
         }
     }
     if (e.NewStartingIndex > -1)
     {
         PatternNode <TData, TOffset> startNode = e.NewStartingIndex == 0 ? _pattern.Children.Begin : _pattern.Children.ElementAt(e.NewStartingIndex - 1);
         foreach (IPatternRuleSpec <TData, TOffset> rs in e.NewItems)
         {
             IPatternRuleSpec <TData, TOffset> ruleSpec = rs;
             string id = "rule" + _curRuleId++;
             _ruleIds[id] = ruleSpec;
             var subpattern = new Pattern <TData, TOffset>(id, ruleSpec.Pattern.Children.DeepClone())
             {
                 Acceptable = match => ruleSpec.IsApplicable(match.Input) && ruleSpec.Pattern.Acceptable(match)
             };
             startNode.AddAfter(subpattern);
             startNode = subpattern;
         }
     }
 }
Example #2
0
        public IEnumerable <TData> Apply(TData input, TOffset start)
        {
            if (!_ruleSpec.IsApplicable(input) || input.Annotations.Count == 0)
            {
                return(Enumerable.Empty <TData>());
            }

            return(ApplyImpl(input, start));
        }