-
Notifications
You must be signed in to change notification settings - Fork 3
/
declaration.ts
70 lines (63 loc) · 2.64 KB
/
declaration.ts
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
import { EL } from "../";
import * as std from "../../../law/std";
import { SentenceTextRange } from "../../container/sentenceEnv";
export interface DeclarationOptions {
declarationID: string,
type: string,
name: string,
children: (std.Ruby | std.Sup | std.Sub | std.__EL | string)[],
value: string | null,
scope: SentenceTextRange[],
nameSentenceTextRange: SentenceTextRange,
range: [start: number, end: number] | null,
}
export class ____Declaration extends EL {
public override tag = "____Declaration" as const;
public override get isControl(): true { return true; }
public override attr: {
declarationID: string,
type: string,
name: string,
value?: string,
scope: string,
nameSentenceTextRange: string,
};
public override children: (std.Ruby | std.Sup | std.Sub | std.__EL | string)[];
private scopeCache: [str: string, value: SentenceTextRange[]] | null = null;
public get scope(): SentenceTextRange[] {
if (this.scopeCache !== null && this.scopeCache[0] === this.attr.scope) {
return this.scopeCache[1];
} else {
const scope = JSON.parse(this.attr.scope) as SentenceTextRange[];
this.scopeCache = [this.attr.scope, scope];
return scope;
}
}
private nameSentenceTextRangeCache: [str: string, value: SentenceTextRange] | null = null;
public get nameSentenceTextRange(): SentenceTextRange {
if (this.nameSentenceTextRangeCache !== null && this.nameSentenceTextRangeCache[0] === this.attr.nameSentenceTextRange) {
return this.nameSentenceTextRangeCache[1];
} else {
const nameSentenceTextRange = JSON.parse(this.attr.nameSentenceTextRange) as SentenceTextRange;
this.nameSentenceTextRangeCache = [this.attr.nameSentenceTextRange, nameSentenceTextRange];
return nameSentenceTextRange;
}
}
public set nameSentenceTextRange(value: SentenceTextRange) {
this.attr.nameSentenceTextRange = JSON.stringify(value);
this.nameSentenceTextRangeCache = [this.attr.nameSentenceTextRange, value];
}
constructor(options: DeclarationOptions) {
super("____Declaration", {}, [], options.range);
const { declarationID: id, type, name, value, scope, nameSentenceTextRange, children } = options;
this.attr = {
declarationID: id,
type,
name,
scope: JSON.stringify(scope),
nameSentenceTextRange: JSON.stringify(nameSentenceTextRange),
};
if (value !== null) this.attr.value = value;
this.children = children;
}
}