Example #1
0
        /// <summary>
        /// (BNF) ruleset : selector? '{' S* declaration? [ ';' S* declaration? ]* '}' S*;
        /// </summary>
        /// <returns></returns>
        private CssRuleSet ParseRuleSet()
        {
            char       ch;
            CssRuleSet ruleSet = new CssRuleSet();

ParseSelectors:
            while (true)
            {
                try
                {
                    CssSelector selector = this.ParseSelector();
                    if (selector == null)
                    {
                        break;
                    }
                    ruleSet.Selectors.Add(selector);
                }
                catch (ParseException ex)
                {
                    this.errors.Add(ex);

                    while (this.Read(out ch))
                    {
                        // restabalize on next rulset
                        switch (ch)
                        {
                        case ',':
                        {
                            // continue parsing rest of Selectors
                            goto ParseSelectors;
                        }

                        case '{':
                        {
                            goto ParseDeclarations;
                        }

                        //case ':':// keep going
                        case ';':
                        case '}':
                        {
                            throw new SyntaxError("Invalid selector list", this.reader.FilePath, this.reader.Line, this.reader.Column);
                        }
                        }
                    }
                }
            }

ParseDeclarations:
            while (true)
            {
                try
                {
                    CssDeclaration declaration = this.ParseDeclaration();
                    if (declaration == null)
                    {
                        break;
                    }
                    ruleSet.Declarations.Add(declaration);
                }
                catch (ParseException ex)
                {
                    this.errors.Add(ex);

                    while (this.Read(out ch))
                    {
                        // restabalize on next declaration
                        switch (ch)
                        {
                        case '{':
                        {
                            throw new SyntaxError("Invalid ruleset", this.reader.FilePath, this.reader.Line, this.reader.Column);
                        }

                        //case ':':// keep going
                        case ';':
                        {
                            // continue parsing rest of delcarations
                            goto ParseDeclarations;
                        }

                        case '}':
                        {
                            // no more declarations
                            return(ruleSet);
                        }
                        }
                    }
                }
            }

            return(ruleSet);
        }
Example #2
0
        /// <summary>
        /// (BNF) ruleset : selector? '{' S* declaration? [ ';' S* declaration? ]* '}' S*;
        /// </summary>
        /// <returns></returns>
        private CssRuleSet ParseRuleSet()
        {
            char ch;
            CssRuleSet ruleSet = new CssRuleSet();

        ParseSelectors:
            while (true)
            {
                try
                {
                    CssSelector selector = this.ParseSelector();
                    if (selector == null)
                    {
                        break;
                    }
                    ruleSet.Selectors.Add(selector);
                }
                catch (ParseException ex)
                {
                    this.errors.Add(ex);

                    while (this.Read(out ch))
                    {
                        // restabalize on next rulset
                        switch (ch)
                        {
                            case ',':
                                {
                                    // continue parsing rest of Selectors
                                    goto ParseSelectors;
                                }
                            case '{':
                                {
                                    goto ParseDeclarations;
                                }
                            //case ':':// keep going
                            case ';':
                            case '}':
                                {
                                    throw new SyntaxError("Invalid selector list", this.reader.FilePath, this.reader.Line, this.reader.Column);
                                }
                        }
                    }
                }
            }

        ParseDeclarations:
            while (true)
            {
                try
                {
                    CssDeclaration declaration = this.ParseDeclaration();
                    if (declaration == null)
                    {
                        break;
                    }
                    ruleSet.Declarations.Add(declaration);
                }
                catch (ParseException ex)
                {
                    this.errors.Add(ex);

                    while (this.Read(out ch))
                    {
                        // restabalize on next declaration
                        switch (ch)
                        {
                            case '{':
                                {
                                    throw new SyntaxError("Invalid ruleset", this.reader.FilePath, this.reader.Line, this.reader.Column);
                                }
                            //case ':':// keep going
                            case ';':
                                {
                                    // continue parsing rest of delcarations
                                    goto ParseDeclarations;
                                }
                            case '}':
                                {
                                    // no more declarations
                                    return ruleSet;
                                }
                        }
                    }
                }
            }

            return ruleSet;
        }