示例#1
0
        internal static Nfa Concat(IEnumerable <Nfa> coll)
        {
            Nfa nfa_result = coll.First();

            NfaNode[] end_nodes = nfa_result.Accepting().ToArray();

            foreach (Nfa nfa in coll.Skip(1))
            {
                NfaNode[] new_ends = nfa.Accepting().ToArray();
                nfa.StartNode.ConnectFrom(end_nodes, NfaEdge.CreateEmpty());
                end_nodes = new_ends;
            }

            return(nfa_result);
        }
示例#2
0
        internal void ConnectTo(NfaNode targetNode, NfaEdge edge)
        {
            // store current edges, to work with clear space between given nodes
            Connections this_connections       = this.Connections.Reset();
            Connections targetNode_connections = targetNode.Connections.Reset();

            // fibers in edge are sorted from the longest to the shortest
            foreach (IEnumerable <NfaEdge.Fiber> fiber_chain in edge.Fibers)
            {
                connectBetween(this, targetNode, fiber_chain.Reverse());
            }

            // merge previous edges with newly created
            this.Connections.Merge(this_connections);
            targetNode.Connections.Merge(targetNode_connections);
        }
示例#3
0
        internal int Add(bool priority, NaiveLanguageTools.MultiRegex.RegexParser.AltRegex pattern, StringCaseComparison stringComparison)
        {
            pattern = pattern.ToCaseComparison(stringComparison);
            Nfa pattern_nfa = pattern.BuildNfa();

            pattern_nfa.Accepting().ForEach(it => it.SetValue(rulesCount, priority));
            if (this.rulesCount == 0)
            {
                nfa = pattern_nfa;
            }
            else
            {
                nfa.StartNode.ConnectTo(pattern_nfa.StartNode, NfaEdge.CreateEmpty());
            }

            return(rulesCount++);
        }
示例#4
0
 internal void ConnectFrom(IEnumerable <NfaNode> sourceNodes, NfaEdge edge)
 {
     sourceNodes.ForEach(it => it.ConnectTo(this, edge.Clone()));
 }