/
parser.ometajs
51 lines (30 loc) · 1.73 KB
/
parser.ometajs
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
var CSSParser = require('../css/parser').CSSParser;
ometa BOSSParser <: CSSParser {
statement = definition | ruleset | atrule | assignment,
definition = ident:x '(' functionBody:y ')' sc* block:z -> [#definition, x, y, z],
string = m_string:x -> [#string, x.slice(1, -1), x[0]],
variable = '$' ident:x -> [#variable, x],
combinator = ('+' | '>' | '~' | '&'):x -> [#combinator, x],
property = (ident | variable):x sc* -> [#property, x],
assignment = property:p '=' value:v decldelim? sc* -> [#assignment, p, v],
important = '!' sc* seq('important') -> [#important],
primary = percentage | dimension | number,
unary = ('-' | '+'):op primary:x -> [#unary, [#operator, op], x]
| primary,
multiplicative = multiplicative:x sc+ ('*' | '/' | '%'):op sc+ unary:y -> [#binary, [#operator, op], x, y]
| unary,
additive = additive:x sc+ ('+' | '-'):op sc+ multiplicative:y -> [#binary, [#operator, op], x, y]
| multiplicative,
expression = additive,
nthselector = nthf:x '(' (sc | ('+' | '-'):op -> [#operator, op] | nth)*:y ')' -> [#nthselector, [#ident, x]].concat(y),
blockdecl = sc* (filter | declaration):x decldelim? sc* -> [x]
| sc* ruleset:x sc* -> [x]
| sc* decldelim sc* -> []
| sc+:s0 -> [],
uri = seq('url(') sc* string:x sc* ')' -> CSSParser.concat([#uri], [x])
| seq('url(') sc* (~')' ~m_w char)*:x sc* ')' -> CSSParser.concat([#uri], [[#raw, x.join('')]]),
pseudoc = ':' (pseudof | ident):x -> [#pseudoc, x],
pseudof = ident:x '(' pseudofBody:y ')' -> [#funktion, x, y],
pseudofBody = (simpleselector)*:x -> [#functionBody].concat(x),
any = braces | string | expression | uri | functionExpression | funktion | ident | variable
}