Пример #1
0
 void ParseModel(char cmt, ContentModel cm)
 {
     int depth = cm.CurrentDepth;
     char ch = this.current.Lastchar;
     ch = this.current.SkipWhitespace();
     while (ch != cmt || cm.CurrentDepth > depth)
     {
         if (ch == Entity.EOF)
         {
             this.current.Error("Content Model was not closed");
         }
         if (ch == '%')
         {
             Entity e = ParseParameterEntity(SgmlDtd.cmterm);
             PushEntity(this.current.ResolvedUri, e);
             ParseModel(Entity.EOF, cm);
             PopEntity();
             ch = this.current.SkipWhitespace();
         }
         else if (ch == '(')
         {
             cm.PushGroup();
             this.current.ReadChar();
             ch = this.current.SkipWhitespace();
         }
         else if (ch == ')')
         {
             ch = this.current.ReadChar();
             if (ch == '*' || ch == '+' || ch == '?')
             {
                 cm.AddOccurrence(ch);
                 ch = this.current.ReadChar();
             }
             if (cm.PopGroup() < depth)
             {
                 this.current.Error("Parameter entity cannot close a paren outside it's own scope");
             }
             ch = this.current.SkipWhitespace();
         }
         else if (ch == ',' || ch == '|' || ch == '&')
         {
             cm.AddConnector(ch);
             this.current.ReadChar();
             ch = this.current.SkipWhitespace();
         }
         else
         {
             string token;
             if (ch == '#')
             {
                 ch = this.current.ReadChar();
                 token = "#" + this.current.ScanToken(this.sb, SgmlDtd.cmterm, true);
             }
             else
             {
                 token = this.current.ScanToken(this.sb, SgmlDtd.cmterm, true);
             }
             token = token.ToUpper();
             token = this.nameTable.Add(token);
             ch = this.current.Lastchar;
             if (ch == '?' || ch == '+' || ch == '*')
             {
                 cm.PushGroup();
                 cm.AddSymbol(token);
                 cm.AddOccurrence(ch);
                 cm.PopGroup();
                 this.current.ReadChar();
                 ch = this.current.SkipWhitespace();
             }
             else
             {
                 cm.AddSymbol(token);
                 ch = this.current.SkipWhitespace();
             }
         }
     }
 }
Пример #2
0
        void ParseModel(char cmt, ContentModel cm)
        {
            int  depth = cm.CurrentDepth;
            char ch    = this.current.Lastchar;

            ch = this.current.SkipWhitespace();
            while (ch != cmt || cm.CurrentDepth > depth)
            {
                if (ch == Entity.EOF)
                {
                    this.current.Error("Content Model was not closed");
                }
                if (ch == '%')
                {
                    Entity e = ParseParameterEntity(SgmlDtd.cmterm);
                    PushEntity(this.current.ResolvedUri, e);
                    ParseModel(Entity.EOF, cm);
                    PopEntity();
                    ch = this.current.SkipWhitespace();
                }
                else if (ch == '(')
                {
                    cm.PushGroup();
                    this.current.ReadChar();
                    ch = this.current.SkipWhitespace();
                }
                else if (ch == ')')
                {
                    ch = this.current.ReadChar();
                    if (ch == '*' || ch == '+' || ch == '?')
                    {
                        cm.AddOccurrence(ch);
                        ch = this.current.ReadChar();
                    }
                    if (cm.PopGroup() < depth)
                    {
                        this.current.Error("Parameter entity cannot close a paren outside it's own scope");
                    }
                    ch = this.current.SkipWhitespace();
                }
                else if (ch == ',' || ch == '|' || ch == '&')
                {
                    cm.AddConnector(ch);
                    this.current.ReadChar();
                    ch = this.current.SkipWhitespace();
                }
                else
                {
                    string token;
                    if (ch == '#')
                    {
                        ch    = this.current.ReadChar();
                        token = "#" + this.current.ScanToken(this.sb, SgmlDtd.cmterm, true);
                    }
                    else
                    {
                        token = this.current.ScanToken(this.sb, SgmlDtd.cmterm, true);
                    }
                    token = token.ToUpper();
                    token = this.nameTable.Add(token);
                    ch    = this.current.Lastchar;
                    if (ch == '?' || ch == '+' || ch == '*')
                    {
                        cm.PushGroup();
                        cm.AddSymbol(token);
                        cm.AddOccurrence(ch);
                        cm.PopGroup();
                        this.current.ReadChar();
                        ch = this.current.SkipWhitespace();
                    }
                    else
                    {
                        cm.AddSymbol(token);
                        ch = this.current.SkipWhitespace();
                    }
                }
            }
        }
Пример #3
0
 ContentModel ParseContentModel(char ch)
 {
     ContentModel cm = new ContentModel();
     if (ch == '(')
     {
         this.current.ReadChar();
         ParseModel(')', cm);
         ch = this.current.ReadChar();
         if (ch == '?' || ch == '+' || ch == '*')
         {
             cm.AddOccurrence(ch);
             this.current.ReadChar();
         }
     }
     else if (ch == '%')
     {
         Entity e = ParseParameterEntity(SgmlDtd.dcterm);
         PushEntity(this.current.ResolvedUri, e);
         cm = ParseContentModel(this.current.Lastchar);
         PopEntity();
     }
     else
     {
         string dc = ScanName(SgmlDtd.dcterm);
         cm.SetDeclaredContent(dc);
     }
     return cm;
 }
Пример #4
0
        void ParseElementDecl()
        {
            char ch = this.current.SkipWhitespace();

            string[] names = ParseNameGroup(ch, true);
            ch = Char.ToUpper(this.current.SkipWhitespace());
            bool sto = false;
            bool eto = false;

            if (ch == 'O' || ch == '-')
            {
                sto = (ch == 'O');
                this.current.ReadChar();
                ch = Char.ToUpper(this.current.SkipWhitespace());
                if (ch == 'O' || ch == '-')
                {
                    eto = (ch == 'O');
                    ch  = this.current.ReadChar();
                }
            }
            ch = this.current.SkipWhitespace();
            ContentModel cm = ParseContentModel(ch);

            ch = this.current.SkipWhitespace();

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

            if (ch == '-')
            {
                ch = this.current.ReadChar();
                if (ch == '(')
                {
                    exclusions = ParseNameGroup(ch, true);
                    ch         = this.current.SkipWhitespace();
                }
                else if (ch == '-')
                {
                    ch = ParseDeclComment(false);
                }
                else
                {
                    this.current.Error("Invalid syntax at '{0}'", ch);
                }
            }

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

            if (ch == '+')
            {
                ch = this.current.ReadChar();
                if (ch != '(')
                {
                    this.current.Error("Expecting inclusions name group", ch);
                }
                inclusions = ParseNameGroup(ch, true);
                ch         = this.current.SkipWhitespace();
            }

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


            if (ch != '>')
            {
                this.current.Error("Expecting end of ELEMENT declaration '>' but found '{0}'", ch);
            }

            foreach (string name in names)
            {
                string atom = name.ToUpper();
                atom = this.nameTable.Add(name);
                this.elements.Add(atom, new ElementDecl(atom, sto, eto, cm, inclusions, exclusions));
            }
        }