コード例 #1
0
ファイル: IcuRulesParser.cs プロジェクト: vkarthim/libpalaso
        // The extended element is the trickiest one becuase the operator gets nested in an extended tag, and
        // can be preceded by another element as well.  Here's a simple rule:
        // &a < b  => <reset>a</reset><p>b</p>
        // And the extended one for comparison:
        // &a < b | c / d => <reset>a</reset><x><context>b</context><p>c</p><extend>d</extend></x>
        // The operator tag is inserted inside the "x" tag, and comes after the "context" tag (represented by '|')
        private void OnExtendedDifference(object sender, ActionEventArgs args)
        {
            // There should always at least be 2 nodes by this point - reset and either prefix or expansion
            Debug.Assert(_currentNodes.Count >= 2);
            IcuDataObject differenceNode = IcuDataObject.CreateElement("x");
            IcuDataObject dataNode       = IcuDataObject.CreateElement(_currentOperators.Pop());

            dataNode.AppendChild(_currentDataObjects.Pop());
            IcuDataObject prefixNode    = _currentNodes[_currentNodes.Count - 2];
            IcuDataObject expansionNode = _currentNodes[_currentNodes.Count - 1];
            int           deleteCount   = 0;

            if (expansionNode.Name != "extend")
            {
                prefixNode    = expansionNode;
                expansionNode = null;
            }
            if (prefixNode.Name == "context")
            {
                differenceNode.AppendChild(prefixNode);
                deleteCount++;
            }
            differenceNode.AppendChild(dataNode);
            if (expansionNode != null)
            {
                differenceNode.AppendChild(expansionNode);
                deleteCount++;
            }
            _currentNodes.RemoveRange(_currentNodes.Count - deleteCount, deleteCount);
            _currentNodes.Add(differenceNode);
        }
コード例 #2
0
ファイル: IcuRulesParser.cs プロジェクト: vkarthim/libpalaso
        private void OnReset(object sender, ActionEventArgs args)
        {
            IcuDataObject ido = IcuDataObject.CreateElement(((Spart.Parsers.NonTerminal.Rule)sender).ID);

            foreach (IcuDataObject attr in _attributesForReset)
            {
                ido.AppendChild(attr);
            }
            ido.AppendChild(_currentDataObjects.Pop());
            _currentNodes.Add(ido);
            _attributesForReset = new Queue <IcuDataObject>();
        }
コード例 #3
0
ファイル: IcuRulesParser.cs プロジェクト: vkarthim/libpalaso
        private void AddXmlNodeWithData(string name)
        {
            IcuDataObject ido = IcuDataObject.CreateElement(name);

            ido.AppendChild(_currentDataObjects.Pop());
            _currentNodes.Add(ido);
        }
コード例 #4
0
ファイル: IcuRulesParser.cs プロジェクト: vkarthim/libpalaso
        private IcuDataObject CreateOptimizedNode(List <IcuDataObject> nodeGroup)
        {
            Debug.Assert(nodeGroup != null);
            Debug.Assert(nodeGroup.Count > 0);
            // one node is already optimized
            if (nodeGroup.Count == 1)
            {
                return(nodeGroup[0]);
            }
            // luckily the optimized names are the same as the unoptimized with 'c' appended
            // so <p> becomes <pc>, <s> to <sc>, et al.
            IcuDataObject optimizedNode = IcuDataObject.CreateElement(nodeGroup[0].Name + "c");

            foreach (IcuDataObject node in nodeGroup)
            {
                optimizedNode.AppendChild(IcuDataObject.CreateText(node.InnerText));
            }
            return(optimizedNode);
        }