コード例 #1
0
        public override void ApplyRhs(Match <Word, ShapeNode> targetMatch, Range <ShapeNode> range,
                                      VariableBindings varBindings)
        {
            ShapeNode curNode = range.Start;

            foreach (PatternNode <Word, ShapeNode> node in _rhs.Children.GetNodes(targetMatch.Matcher.Direction))
            {
                if (targetMatch.Input.Shape.Count == 256)
                {
                    throw new InfiniteLoopException("An epenthesis rewrite rule is stuck in an infinite loop.");
                }
                var           constraint = (Constraint <Word, ShapeNode>)node;
                FeatureStruct fs         = constraint.FeatureStruct.Clone();
                if (varBindings != null)
                {
                    fs.ReplaceVariables(varBindings);
                }
                curNode = targetMatch.Input.Shape.AddAfter(curNode, fs);
                if (IsIterative)
                {
                    curNode.SetDirty(true);
                }
            }
            MarkSuccessfulApply(targetMatch.Input);
        }
コード例 #2
0
        public override void ApplyRhs(Match <Word, ShapeNode> targetMatch, Span <ShapeNode> span, VariableBindings varBindings)
        {
            ShapeNode curNode = span.End;

            foreach (PatternNode <Word, ShapeNode> node in _rhs.Children)
            {
                var           constraint = (Constraint <Word, ShapeNode>)node;
                FeatureStruct fs         = constraint.FeatureStruct.DeepClone();
                if (varBindings != null)
                {
                    fs.ReplaceVariables(varBindings);
                }
                curNode = targetMatch.Input.Shape.AddAfter(curNode, fs);
                if (IsIterative)
                {
                    curNode.SetDirty(true);
                }
            }

            ShapeNode[] nodes = targetMatch.Input.Shape.GetNodes(span).ToArray();
            for (int i = 0; i < _targetCount; i++)
            {
                nodes[i].SetDeleted(true);
            }

            MarkSuccessfulApply(targetMatch.Input);
        }
コード例 #3
0
        private void Unapply(Match <Word, ShapeNode> targetMatch, Range <ShapeNode> range, VariableBindings varBindings)
        {
            ShapeNode curNode = range.Start;

            for (int i = 0; i < _targetCount; i++)
            {
                curNode.Annotation.Optional = true;
                curNode.SetDirty(true);
                curNode = curNode.Next;
            }
        }
コード例 #4
0
        private void Unapply(Match <Word, ShapeNode> targetMatch, Span <ShapeNode> span, VariableBindings varBindings)
        {
            int i = 0;

            foreach (Constraint <Word, ShapeNode> constraint in _analysisRhs.Children.Cast <Constraint <Word, ShapeNode> >())
            {
                ShapeNode     node = targetMatch.GroupCaptures["target" + i].Span.GetStart(targetMatch.Matcher.Direction);
                FeatureStruct fs   = node.Annotation.FeatureStruct.DeepClone();
                fs.PriorityUnion(constraint.FeatureStruct);
                node.Annotation.FeatureStruct.Union(fs, varBindings);
                node.SetDirty(true);
                i++;
            }
        }