예제 #1
0
파일: parser.go 프로젝트: inkel/bosun
// Parse an At Rule
func (parser *Parser) parseAtRule() (*css.Rule, error) {
	// parse rule name (eg: "@import")
	token := parser.shiftToken()

	result := css.NewRule(css.AT_RULE)
	result.Name = token.Value

	for parser.tokenParsable() {
		if parser.tokenChar(";") {
			parser.shiftToken()

			// finished
			break
		} else if parser.tokenChar("{") {
			if result.EmbedsRules() {
				// parse rules block
				rules, err := parser.ParseRules()
				if err != nil {
					return result, err
				}

				result.Rules = rules
			} else {
				// parse declarations block
				declarations, err := parser.ParseDeclarations()
				if err != nil {
					return result, err
				}

				result.Declarations = declarations
			}

			// finished
			break
		} else {
			// parse prelude
			prelude, err := parser.parsePrelude()
			if err != nil {
				return result, err
			}

			result.Prelude = prelude
		}
	}

	// log.Printf("[parsed] Rule: %s", result.String())

	return result, parser.err()
}
예제 #2
0
파일: parser.go 프로젝트: inkel/bosun
// Parse a Qualified Rule
func (parser *Parser) parseQualifiedRule() (*css.Rule, error) {
	result := css.NewRule(css.QUALIFIED_RULE)

	for parser.tokenParsable() {
		if parser.tokenChar("{") {
			if result.Prelude == "" {
				errMsg := fmt.Sprintf("Unexpected { character: %s", parser.nextToken().String())
				return result, errors.New(errMsg)
			}

			// parse declarations block
			declarations, err := parser.ParseDeclarations()
			if err != nil {
				return result, err
			}

			result.Declarations = declarations

			// finished
			break
		} else {
			// parse prelude
			prelude, err := parser.parsePrelude()
			if err != nil {
				return result, err
			}

			result.Prelude = prelude
		}
	}

	result.Selectors = strings.Split(result.Prelude, ",")
	for i, sel := range result.Selectors {
		result.Selectors[i] = strings.TrimSpace(sel)
	}

	// log.Printf("[parsed] Rule: %s", result.String())

	return result, parser.err()
}