-
Notifications
You must be signed in to change notification settings - Fork 10
/
scope.js
55 lines (44 loc) · 1.17 KB
/
scope.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
'use strict';
var Path = require('./path');
module.exports = class Scope {
static tie(ends, name) {
for (var i = 0; i < ends.length; i++) {
var end = ends[i];
if (end.type === 'branch') {
end.node.branch = name;
} else {
end.next = name;
}
}
}
constructor(story, path, base) {
this.story = story;
this.path = path;
this.base = base;
Object.seal(this);
}
name() {
return Path.toName(this.path);
}
create(type, arg, position) {
return this.story.create(this.path, type, arg, position);
}
next() {
return new Scope(this.story, Path.next(this.path), this.base);
}
zerothChild() {
return new Scope(this.story, Path.zerothChild(this.path), this.base);
}
firstChild() {
return new Scope(this.story, Path.firstChild(this.path), this.base);
}
label(label) {
return new Scope(this.story, this.base.concat([label, 0]), this.base);
}
tie(nodes) {
Scope.tie(nodes, this.name());
}
error(message) {
this.story.error(message);
}
}