// ------------------------------------------------------------------------- // // findNodes() Locate all the nodes of the specified type, starting // at the specified root. // // ------------------------------------------------------------------------- internal void FindNodes(IList dest, int kind) { if (fType == kind) { ILOG.J2CsMapping.Collections.Generics.Collections.Add(dest, this); } if (fLeftChild != null) { fLeftChild.FindNodes(dest, kind); } if (fRightChild != null) { fRightChild.FindNodes(dest, kind); } }
// ----------------------------------------------------------------------------- // // calcChainedFollowPos. Modify the previously calculated followPos sets // to implement rule chaining. NOT described by Aho // // ----------------------------------------------------------------------------- internal void CalcChainedFollowPos(RBBINode tree) { IList endMarkerNodes = new ArrayList(); IList leafNodes = new ArrayList(); // get a list of all endmarker nodes. tree.FindNodes(endMarkerNodes, IBM.ICU.Text.RBBINode.endMark); // get a list all leaf nodes tree.FindNodes(leafNodes, IBM.ICU.Text.RBBINode.leafChar); // Get all nodes that can be the start a match, which is FirstPosition() // of the portion of the tree corresponding to user-written rules. // See the tree description in bofFixup(). RBBINode userRuleRoot = tree; if (fRB.fSetBuilder.SawBOF()) { userRuleRoot = tree.fLeftChild.fRightChild; } IBM.ICU.Impl.Assert.Assrt(userRuleRoot != null); ILOG.J2CsMapping.Collections.ISet matchStartNodes = userRuleRoot.fFirstPosSet; // Iteratate over all leaf nodes, // IIterator endNodeIx = new ILOG.J2CsMapping.Collections.IteratorAdapter(leafNodes.GetEnumerator()); while (endNodeIx.HasNext()) { RBBINode tNode = (RBBINode)endNodeIx.Next(); RBBINode endNode = null; // Identify leaf nodes that correspond to overall rule match // positions. // These include an endMarkerNode in their followPos sets. IIterator i = new ILOG.J2CsMapping.Collections.IteratorAdapter(endMarkerNodes.GetEnumerator()); while (i.HasNext()) { RBBINode endMarkerNode = (RBBINode)i.Next(); if (ILOG.J2CsMapping.Collections.Collections.Contains(endMarkerNode, tNode.fFollowPos)) { endNode = tNode; break; } } if (endNode == null) { // node wasn't an end node. Try again with the next. continue; } // We've got a node that can end a match. // Line Break Specific hack: If this node's val correspond to the // $CM char class, // don't chain from it. // TODO: Add rule syntax for this behavior, get specifics out of // here and // into the rule file. if (fRB.fLBCMNoChain) { int c = this.fRB.fSetBuilder.GetFirstChar(endNode.fVal); if (c != -1) { // c == -1 occurs with sets containing only the {eof} marker // string. int cLBProp = IBM.ICU.Lang.UCharacter.GetIntPropertyValue(c, IBM.ICU.Lang.UProperty_Constants.LINE_BREAK); if (cLBProp == IBM.ICU.Lang.UCharacter.LineBreak.COMBINING_MARK) { continue; } } } // Now iterate over the nodes that can start a match, looking for // ones // with the same char class as our ending node. RBBINode startNode; IIterator startNodeIx = new ILOG.J2CsMapping.Collections.IteratorAdapter(matchStartNodes.GetEnumerator()); while (startNodeIx.HasNext()) { startNode = (RBBINode)startNodeIx.Next(); if (startNode.fType != IBM.ICU.Text.RBBINode.leafChar) { continue; } if (endNode.fVal == startNode.fVal) { // The end val (character class) of one possible match is // the // same as the start of another. // Add all nodes from the followPos of the start node to the // followPos set of the end node, which will have the effect // of // letting matches transition from a match state at endNode // to the second char of a match starting with startNode. ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(startNode.fFollowPos, endNode.fFollowPos); } } } }