-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ast.js
38 lines (33 loc) · 740 Bytes
/
ast.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
class Node {
constructor(type, range) {
this.type = type
if (range) this.range = range
}
}
class Pair extends Node {
constructor(key, value, range) {
super('PAIR', range)
this.key = key
this.value = value
}
separator(src) {
if (Array.isArray(this.range) && this.range.length >= 3) {
// eslint-disable-next-line no-unused-vars
const [_, start, end] = this.range
return src.slice(start, end)
}
return null
}
}
class Comment extends Node {
constructor(comment, range) {
super('COMMENT', range)
this.comment = comment
}
}
class EmptyLine extends Node {
constructor(range) {
super('EMPTY_LINE', range)
}
}
module.exports = { Node, Pair, Comment, EmptyLine }