-
Notifications
You must be signed in to change notification settings - Fork 5
/
selector_parser.go
65 lines (59 loc) · 1.36 KB
/
selector_parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package css
import (
"github.com/gorilla/css/scanner"
)
func parseSelector(s *scanner.Scanner) []*scanner.Token {
/*
selector : any+;
any : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
| DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
| DASHMATCH | ':' | FUNCTION S* [any|unused]* ')'
| '(' S* [any|unused]* ')' | '[' S* [any|unused]* ']'
] S*;
*/
result := make([]*scanner.Token, 0)
Loop:
for {
token := s.Next()
switch token.Type {
case scanner.TokenError, scanner.TokenEOF:
break Loop
case scanner.TokenChar:
if token.Value == "{" {
break Loop
}
fallthrough
case scanner.TokenIdent:
fallthrough
case scanner.TokenS:
fallthrough
case scanner.TokenNumber:
fallthrough
case scanner.TokenPercentage:
fallthrough
case scanner.TokenDimension:
fallthrough
case scanner.TokenString:
fallthrough
case scanner.TokenURI:
fallthrough
case scanner.TokenHash:
fallthrough
case scanner.TokenUnicodeRange:
fallthrough
case scanner.TokenIncludes:
fallthrough
case scanner.TokenDashMatch:
fallthrough
case scanner.TokenFunction:
fallthrough
case scanner.TokenSuffixMatch:
fallthrough
case scanner.TokenPrefixMatch:
fallthrough
case scanner.TokenSubstringMatch:
result = append(result, token)
}
}
return result
}