Combinator.js
1.5 KB
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
var TYPE = require('../../tokenizer').TYPE;
var IDENT = TYPE.Ident;
var PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
var SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
var GREATERTHANSIGN = 0x003E; // U+003E GREATER-THAN SIGN (>)
var TILDE = 0x007E; // U+007E TILDE (~)
// + | > | ~ | /deep/
module.exports = {
name: 'Combinator',
structure: {
name: String
},
parse: function() {
var start = this.scanner.tokenStart;
var code = this.scanner.source.charCodeAt(this.scanner.tokenStart);
switch (code) {
case GREATERTHANSIGN:
case PLUSSIGN:
case TILDE:
this.scanner.next();
break;
case SOLIDUS:
this.scanner.next();
if (this.scanner.tokenType !== IDENT || this.scanner.lookupValue(0, 'deep') === false) {
this.error('Identifier `deep` is expected');
}
this.scanner.next();
if (!this.scanner.isDelim(SOLIDUS)) {
this.error('Solidus is expected');
}
this.scanner.next();
break;
default:
this.error('Combinator is expected');
}
return {
type: 'Combinator',
loc: this.getLocation(start, this.scanner.tokenStart),
name: this.scanner.substrToCursor(start)
};
},
generate: function(node) {
this.chunk(node.name);
}
};