示例#1
0
func CssToMap(css string) map[string]string {
	res := map[string]string{}
	s := scanner.New(css)
	key := ""
	for {
		token := s.Next()
		if token.Type == scanner.TokenEOF || token.Type == scanner.TokenError {
			break
		}
		if len(key) == 0 {
			if token.Type == scanner.TokenIdent {
				key = token.Value
			}
		} else if token.Type != scanner.TokenS && token.Type != scanner.TokenChar && token.Type != scanner.TokenComment {
			res[key] = token.Value
		} else if token.Type == scanner.TokenChar && token.Value == ";" {
			key = ""
		}
	}
	return res
}
示例#2
0
// NewParser instanciates a new parser
func NewParser(txt string) *Parser {
	return &Parser{
		scan: scanner.New(txt),
	}
}