Пример #1
0
        /// <summary>
        /// Calls the appropriate Parsing function based on the element type
        /// </summary>
        private void ProcessChildNodes(SrgsElement srgsElement, IElement parent, IRule rule)
        {
            Type     elementType = srgsElement.GetType();
            IElement child       = null;
            IRule    parentRule  = parent as IRule;
            IItem    parentItem  = parent as IItem;

            if (elementType == typeof(SrgsRuleRef))
            {
                child = ParseRuleRef((SrgsRuleRef)srgsElement, parent);
            }
            else if (elementType == typeof(SrgsOneOf))
            {
                child = ParseOneOf((SrgsOneOf)srgsElement, parent, rule);
            }
            else if (elementType == typeof(SrgsItem))
            {
                child = ParseItem((SrgsItem)srgsElement, parent, rule);
            }
            else if (elementType == typeof(SrgsToken))
            {
                child = ParseToken((SrgsToken)srgsElement, parent);
            }
            else if (elementType == typeof(SrgsNameValueTag))
            {
                child = ParseNameValueTag((SrgsNameValueTag)srgsElement, parent);
            }
            else if (elementType == typeof(SrgsSemanticInterpretationTag))
            {
                child = ParseSemanticTag((SrgsSemanticInterpretationTag)srgsElement, parent);
            }
            else if (elementType == typeof(SrgsSubset))
            {
                child = ParseSubset((SrgsSubset)srgsElement, parent);
            }
            else if (elementType == typeof(SrgsText))
            {
                SrgsText srgsText = (SrgsText)srgsElement;
                string   content  = srgsText.Text;

                // Create the SrgsElement for the text
                IElementText textChild = _parser.CreateText(parent, content);

                // Split it in pieces
                ParseText(parent, content, null, null, -1f);

                if (parentRule != null)
                {
                    _parser.AddElement(parentRule, textChild);
                }
                else
                {
                    if (parentItem != null)
                    {
                        _parser.AddElement(parentItem, textChild);
                    }
                    else
                    {
                        XmlParser.ThrowSrgsException(SRID.InvalidElement);
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "Unsupported Srgs element");
                XmlParser.ThrowSrgsException(SRID.InvalidElement);
            }

            // if the parent is a one of, then the children must be an Item
            IOneOf parentOneOf = parent as IOneOf;

            if (parentOneOf != null)
            {
                IItem childItem = child as IItem;
                if (childItem != null)
                {
                    _parser.AddItem(parentOneOf, childItem);
                }
                else
                {
                    XmlParser.ThrowSrgsException(SRID.InvalidElement);
                }
            }
            else
            {
                if (parentRule != null)
                {
                    _parser.AddElement(parentRule, child);
                }
                else
                {
                    if (parentItem != null)
                    {
                        _parser.AddElement(parentItem, child);
                    }
                    else
                    {
                        XmlParser.ThrowSrgsException(SRID.InvalidElement);
                    }
                }
            }
        }
Пример #2
0
        private void ProcessChildNodes(SrgsElement srgsElement, IElement parent, IRule rule)
        {
            Type     type    = srgsElement.GetType();
            IElement element = null;
            IRule    rule2   = parent as IRule;
            IItem    item    = parent as IItem;

            if (type == typeof(SrgsRuleRef))
            {
                element = ParseRuleRef((SrgsRuleRef)srgsElement, parent);
            }
            else if (type == typeof(SrgsOneOf))
            {
                element = ParseOneOf((SrgsOneOf)srgsElement, parent, rule);
            }
            else if (type == typeof(SrgsItem))
            {
                element = ParseItem((SrgsItem)srgsElement, parent, rule);
            }
            else if (type == typeof(SrgsToken))
            {
                element = ParseToken((SrgsToken)srgsElement, parent);
            }
            else if (type == typeof(SrgsNameValueTag))
            {
                element = ParseNameValueTag((SrgsNameValueTag)srgsElement, parent);
            }
            else if (type == typeof(SrgsSemanticInterpretationTag))
            {
                element = ParseSemanticTag((SrgsSemanticInterpretationTag)srgsElement, parent);
            }
            else if (type == typeof(SrgsSubset))
            {
                element = ParseSubset((SrgsSubset)srgsElement, parent);
            }
            else if (type == typeof(SrgsText))
            {
                SrgsText     srgsText = (SrgsText)srgsElement;
                string       text     = srgsText.Text;
                IElementText value    = _parser.CreateText(parent, text);
                ParseText(parent, text, null, null, -1f);
                if (rule2 != null)
                {
                    _parser.AddElement(rule2, value);
                }
                else if (item != null)
                {
                    _parser.AddElement(item, value);
                }
                else
                {
                    XmlParser.ThrowSrgsException(SRID.InvalidElement);
                }
            }
            else
            {
                XmlParser.ThrowSrgsException(SRID.InvalidElement);
            }
            IOneOf oneOf = parent as IOneOf;

            if (oneOf != null)
            {
                IItem item2 = element as IItem;
                if (item2 != null)
                {
                    _parser.AddItem(oneOf, item2);
                }
                else
                {
                    XmlParser.ThrowSrgsException(SRID.InvalidElement);
                }
            }
            else if (rule2 != null)
            {
                _parser.AddElement(rule2, element);
            }
            else if (item != null)
            {
                _parser.AddElement(item, element);
            }
            else
            {
                XmlParser.ThrowSrgsException(SRID.InvalidElement);
            }
        }