func (parser *Parser) ParseRule() (*css.Rule, error) {
	if parser.tokenAtKeyword() {
		return parser.parseAtRule()
	}
	return parser.parseQualifiedRule()
}
ParseRule parses a rule
package parser
import (
	"errors"
	"fmt"
	"regexp"
	"strings"
	"github.com/gorilla/css/scanner"
	"github.com/aymerick/douceur/css"
)
const (
	importantSuffixRegexp = `(?i)\s*!important\s*$`
)
var (
	importantRegexp *regexp.Regexp
)
type Parser struct {
	scan *scanner.Scanner  
	tokens []*scanner.Token
	embedLevel int
}
func init() {
	importantRegexp = regexp.MustCompile(importantSuffixRegexp)
}
func NewParser(txt string) *Parser {
	return &Parser{
		scan: scanner.New(txt),
	}
}
func Parse(text string) (*css.Stylesheet, error) {
	result, err := NewParser(text).ParseStylesheet()
	if err != nil {
		return nil, err
	}
	return result, nil
}
func ParseDeclarations(text string) ([]*css.Declaration, error) {
	result, err := NewParser(text).ParseDeclarations()
	if err != nil {
		return nil, err
	}
	return result, nil
}
func (parser *Parser) ParseStylesheet() (*css.Stylesheet, error) {
	result := css.NewStylesheet()
	if _, err := parser.parseBOM(); err != nil {
		return result, err
	}
	rules, err := parser.ParseRules()
	if err != nil {
		return result, err
	}
	result.Rules = rules
	return result, nil
}
func (parser *Parser) ParseRules() ([]*css.Rule, error) {
	result := []*css.Rule{}
	inBlock := false
	if parser.tokenChar("{") {
		inBlock = true
		parser.embedLevel++
		parser.shiftToken()
	}
	for parser.tokenParsable() {
		if parser.tokenIgnorable() {
			parser.shiftToken()
		} else if parser.tokenChar("}") {
			if !inBlock {
				errMsg := fmt.Sprintf("Unexpected } character: %s", parser.nextToken().String())
				return result, errors.New(errMsg)
			}
			parser.shiftToken()
			parser.embedLevel--
			break
		} else {
			rule, err := parser.ParseRule()
			if err != nil {
				return result, err
			}
			rule.EmbedLevel = parser.embedLevel
			result = append(result, rule)
		}
	}
	return result, parser.err()
}