-
Notifications
You must be signed in to change notification settings - Fork 5
/
at_parser.go
56 lines (45 loc) · 1.04 KB
/
at_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
package css
import (
"github.com/gorilla/css/scanner"
)
func parseAtNoBody(s *scanner.Scanner, ruleType RuleType) *CSSRule {
/*
Syntax:
@charset charset;
Example:
@charset "UTF-8";
Syntax:
@import url; or
@import url list-of-media-queries;
Example:
@import url("fineprint.css") print;
@import url("bluish.css") projection, tv;
@import 'custom.css';
@import url("chrome://communicator/skin/");
@import "common.css" screen, projection;
@import url('landscape.css') screen and (orientation:landscape);
*/
parsed := make([]*scanner.Token, 0)
Loop:
for {
token := s.Next()
if token.Type == scanner.TokenEOF || token.Type == scanner.TokenError {
return nil
}
// take everything for now
switch token.Type {
case scanner.TokenEOF, scanner.TokenError:
break Loop
case scanner.TokenChar:
if token.Value == ";" {
break Loop
}
fallthrough
default:
parsed = append(parsed, token)
}
}
rule := NewRule(ruleType)
rule.Style.Selector = &CSSValue{Tokens: parsed}
return rule
}