-
Notifications
You must be signed in to change notification settings - Fork 0
/
sth.js
68 lines (52 loc) · 1.31 KB
/
sth.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
class RegeRexStringBuilder {
constructor(str) {
// TODO RegeRexStringBuilder constructor
}
insert(str) {
// TODO RegeRexStringBuilder insert
}
remove(index, length) {
// TODO RegeRexStringBuilder remove
}
charAt(index) {
// TODO RegeRexStringBuilder charAt
}
toString() {
// TODO RegeRexStringBuilder toString
}
get length() {
}
}
class Regex {
const refs = new Set();
let name;
let regex;
constructor() {
// TODO Regex constructor
}
static compile() {
// TODO Regex compile
}
}
class RegexGroup {
const regexes = new Map();
constructor(regexes) {
for (let regex of regexes) {
if (!(regex.prototype instanceof Regex)) {
throw new Error("Argument 'regexes' must be an iterable of Regex subclasses.");
}
regex.compile();
this.regexes.set(regex.name, regex);
}
for (let regex of this.regexes) {
for (let ref of regex.refs) {
if (!this.regexes.has(ref)) throw new Error("Regex " + regex.name
+ "references unknown regex " + ref + ".");
}
}
}
match(str, regex) {
if (typeof str != "string") throw new Error("Argument 'str' must be a string");
if (typeof str != "string") throw new Error("Argument 'str' must be a string");
}
}