-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
74 lines (63 loc) · 2.06 KB
/
index.js
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
'use strict';
import args from './arguments';
import atKeyword from './at-keyword';
import attribute from './attribute';
import backtick from './backtick';
import className from './class';
import combinator from './combinator';
import comment from './comment';
import hash from './hash';
import id from './id';
import ident from './ident';
import important from './important';
import interpolation from './interpolation';
import number from './number';
import operator from './operator';
import pseudo from './pseudo';
import separator from './separator';
import string from './string';
import url from './url';
import variable from './variable';
import whitespace from './whitespace';
import Token from './token';
/**
* Group tokens by commonly used context
*/
export default function consumeToken(stream) {
const _token = any(stream) || args(stream, consumeToken);
if (_token && _token.type === 'ident') {
const _args = args(stream, consumeToken);
if (_args) {
// An identifier followed by arguments – function call
return new Token(stream, 'function', _token.start, _args.end).add(_token).add(_args);
}
}
return _token || unknown(stream);
}
export function any(stream) {
return formatting(stream) || url(stream) || selector(stream) || value(stream)
|| separator(stream);
}
export function selector(stream) {
return interpolation(stream) || backtick(stream) || ident(stream) || atKeyword(stream)
|| className(stream) || id(stream) || pseudo(stream) || attribute(stream)
|| combinator(stream);
}
export function value(stream) {
return url(stream) || string(stream) || interpolation(stream) || backtick(stream)
|| number(stream) || hash(stream) || keyword(stream) || important(stream)
|| operator(stream);
}
export function keyword(stream) {
return backtick(stream) || variable(stream) || atKeyword(stream) || ident(stream);
}
export function formatting(stream) {
return comment(stream) || whitespace(stream);
}
export function unknown(stream) {
stream.start = stream.pos;
const ch = stream.next();
if (ch != null) {
return new Token(stream, 'unknown');
}
}