/// <summary>
 /// Initializes a new element declaration instance.
 /// </summary>
 /// <param name="name">The name of the element.</param>
 /// <param name="startTagOptional">Whether the start tag is optional.</param>
 /// <param name="endTagOptiona">Whether the end tag is optional.</param>
 /// <param name="model">The <see cref="ContentModel"/> of the element.</param>
 /// <param name="inclusions"></param>
 /// <param name="exclusions"></param>
 public ElementDeclaration(string name, bool startTagOptional, 
     bool endTagOptional, ContentModel model, 
     string[] inclusions, string[] exclusions)
 {
     _name = name;
     _startTagOptional = startTagOptional;
     _endTagOptional = endTagOptional;
     _contentModel = model;
     _inclusions = inclusions;
     _exclusions = exclusions;
 }
示例#2
0
        private void ParseModel(char cmt, ContentModel cm)
        {
            int  depth = cm.CurrentDepth;
            char ch    = _current.LastChar;

            ch = _current.SkipWhitespace();

            while (ch != cmt || cm.CurrentDepth > depth)
            {
                if (ch == Entity.EOF)
                {
                    throw Error.ContentModelWasNotClosed();
                }

                if (ch == '%')
                {
                    Entity e = ParseParameterEntity(_contentModelTerm);

                    PushEntity(_current.ResolvedUri, e);
                    ParseModel(Entity.EOF, cm);
                    PopEntity();

                    ch = _current.SkipWhitespace();
                }
                else if (ch == '(')
                {
                    cm.PushGroup();

                    _current.ReadChar();
                    ch = _current.SkipWhitespace();
                }
                else if (ch == ')')
                {
                    ch = _current.ReadChar();

                    if (ch == '*' || ch == '+' || ch == '?')
                    {
                        cm.AddOccurrence(ch);
                        ch = _current.ReadChar();
                    }

                    if (cm.PopGroup() < depth)
                    {
                        throw Error.ParameterEntityClosedOutsideTheScope();
                    }

                    ch = _current.SkipWhitespace();
                }
                else if (ch == ',' || ch == '|' || ch == '&')
                {
                    cm.AddConnector(ch);
                    _current.ReadChar(); // skip connector
                    ch = _current.SkipWhitespace();
                }
                else
                {
                    string token;
                    if (ch == '#')
                    {
                        ch    = _current.ReadChar();
                        token = "#" + _current.ScanToken(_builder, _contentModelTerm, true);
                    }
                    else
                    {
                        token = _current.ScanToken(_builder, SgmlDtd._contentModelTerm, true);
                    }

                    token = token.ToUpper(CultureInfo.InvariantCulture);
                    ch    = _current.LastChar;
                    if (ch == '?' || ch == '+' || ch == '*')
                    {
                        cm.PushGroup();
                        cm.AddSymbol(token);
                        cm.AddOccurrence(ch);
                        cm.PopGroup();

                        _current.ReadChar(); // skip connector
                        ch = _current.SkipWhitespace();
                    }
                    else
                    {
                        cm.AddSymbol(token);
                        ch = _current.SkipWhitespace();
                    }
                }
            }
        }
示例#3
0
        private void ParseModel(char cmt, ContentModel cm)
        {
            int depth = cm.CurrentDepth;
            char ch = _current.LastChar;
            ch = _current.SkipWhitespace();

            while (ch != cmt || cm.CurrentDepth > depth) 
            {
                if (ch == Entity.EOF)
                    throw Error.ContentModelWasNotClosed();
                
                if (ch == '%')
                {
                    Entity e = ParseParameterEntity(_contentModelTerm);

                    PushEntity(_current.ResolvedUri, e);
                    ParseModel(Entity.EOF, cm);
                    PopEntity();
                    
                    ch = _current.SkipWhitespace();
                }
                else if (ch == '(')
                {
                    cm.PushGroup();

                    _current.ReadChar();
                    ch = _current.SkipWhitespace();
                }
                else if (ch == ')')
                {
                    ch = _current.ReadChar();
                    
                    if (ch == '*' || ch == '+' || ch == '?')
                    {
                        cm.AddOccurrence(ch);
                        ch = _current.ReadChar();
                    }

                    if (cm.PopGroup() < depth)
                        throw Error.ParameterEntityClosedOutsideTheScope();
                    
                    ch = _current.SkipWhitespace();
                }
                else if (ch == ',' || ch == '|' || ch == '&')
                {
                    cm.AddConnector(ch);
                    _current.ReadChar(); // skip connector
                    ch = _current.SkipWhitespace();
                }
                else
                {
                    string token;
                    if (ch == '#')
                    {
                        ch = _current.ReadChar();
                        token = "#" + _current.ScanToken(_builder, _contentModelTerm, true);
                    }
                    else
                    {
                        token = _current.ScanToken(_builder, SgmlDtd._contentModelTerm, true);
                    }

                    token = token.ToUpper(CultureInfo.InvariantCulture);
                    ch = _current.LastChar;
                    if (ch == '?' || ch == '+' || ch == '*')
                    {
                        cm.PushGroup();
                        cm.AddSymbol(token);
                        cm.AddOccurrence(ch);
                        cm.PopGroup();

                        _current.ReadChar(); // skip connector
                        ch = _current.SkipWhitespace();
                    }
                    else
                    {
                        cm.AddSymbol(token);
                        ch = _current.SkipWhitespace();
                    }
                }
            }
        }
示例#4
0
        private void ParseElementDeclaration()
        {
            char ch = _current.SkipWhitespace();

            string[] names = ParseNameGroup(ch, true);
            ch = Char.ToUpper(_current.SkipWhitespace(), CultureInfo.InvariantCulture);

            bool sto = false;
            bool eto = false;

            if (ch == 'O' || ch == '-')
            {
                sto = (ch == 'O'); // start tag optional?
                _current.ReadChar();
                ch = Char.ToUpper(_current.SkipWhitespace(), CultureInfo.InvariantCulture);
                if (ch == 'O' || ch == '-')
                {
                    eto = (ch == 'O'); // end tag optional?
                    ch  = _current.ReadChar();
                }
            }
            ch = _current.SkipWhitespace();
            ContentModel cm = ParseContentModel(ch);

            ch = _current.SkipWhitespace();

            string[] exclusions = null;
            string[] inclusions = null;

            if (ch == '-')
            {
                ch = _current.ReadChar();
                if (ch == '(')
                {
                    exclusions = ParseNameGroup(ch, true);
                    ch         = _current.SkipWhitespace();
                }
                else if (ch == '-')
                {
                    ch = ParseDeclarationComment(false);
                }
                else
                {
                    throw Error.InvalidDeclarationSyntax(ch);
                }
            }

            if (ch == '-')
            {
                ch = ParseDeclarationComments();
            }

            if (ch == '+')
            {
                ch = _current.ReadChar();
                if (ch != '(')
                {
                    throw Error.ExpectingInclusionsNameGroup(ch);
                }

                inclusions = ParseNameGroup(ch, true);
                ch         = _current.SkipWhitespace();
            }

            if (ch == '-')
            {
                ch = ParseDeclarationComments();
            }

            if (ch != '>')
            {
                throw Error.ExpectingEndOfElementDeclaration(ch);
            }

            foreach (string name in names)
            {
                string atom = name.ToUpper(CultureInfo.InvariantCulture);
                _elements.Add(atom, new ElementDeclaration(atom, sto, eto, cm, inclusions, exclusions));
            }
        }
示例#5
0
        private ContentModel ParseContentModel(char ch)
        {
            ContentModel cm = new ContentModel();
            if (ch == '(')
            {
                _current.ReadChar();
                ParseModel(')', cm);

                ch = _current.ReadChar();
                if (ch == '?' || ch == '+' || ch == '*')
                {
                    cm.AddOccurrence(ch);
                    _current.ReadChar();
                }
            }
            else if (ch == '%')
            {
                Entity e = ParseParameterEntity(_declaredContentTerm);
                
                PushEntity(_current.ResolvedUri, e);
                cm = ParseContentModel(_current.LastChar);
                PopEntity(); 
            }
            else
            {
                string dc = ScanName(_declaredContentTerm);
                cm.SetDeclaredContent(dc);
            }
            return cm;
        }