-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsass.g
76 lines (62 loc) · 1.43 KB
/
sass.g
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
66
67
68
69
70
71
72
73
74
75
76
grammar sass;
options {
output = AST;
}
tokens {
CHARSET;
RULE;
}
sass
: charset?
variabledeclaration*
rule*
;
// charset opcional
charset
: CHARSET_ID STRING SC
;
// declaração de variáveis
variabledeclaration
: VARIABLE^ CL! WORD SC! ; // $blue: #3bbfce;
// regras de css: seletores { propriedades }
rule
: rulehead BL rulebody BR -> ^(RULE ^(rulehead rulebody))
;
// cabeçalho da regra, pode ter vários seletores, inclusive separado por vírgula
rulehead
: SELECTOR (COMMA SELECTOR)*
;
// corpo da regra, pode possuir uma declaração de propriedade ou uma nova regra aninhada
rulebody
: (
propertydeclaration // declaração de propriedade
| rule // regra aninhada
)*;
// declaração de uma propriedade
propertydeclaration
: WORD^ CL!
(
(WORD | VARIABLE)+ SC! // propriedade ou variável
| BL! (propertydeclaration^)* BR! // propriedade aninhada
)
;
// tokens
DOT : '.';
COMMA : ',';
SHARP : '#';
CL : ':';
SC : ';';
BL : '{';
BR : '}';
DOLLAR : '$';
AMP : '&';
CHARSET_ID : '@charset ';
WORD : ('a'..'z'|'A'..'Z'|'0'..'9'|'-'|'%')+ ;
STRING : '\'' ( ~('\n'|'\r'|'\f'|'\'') )* '\'';
VARIABLE : DOLLAR WORD;
SELECTOR : AMP CL WORD // &:hover
| ((SHARP | DOT)? WORD)+ // table.h1 ou li#classe
;
NL : '\r'? '\n' {skip();} ;
WS : (' '|'\t')+ {skip();} ;
COMMENT : '/*' .* '*/' {skip();} ;