-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassShorthandParser.js
More file actions
51 lines (45 loc) · 1.01 KB
/
ClassShorthandParser.js
File metadata and controls
51 lines (45 loc) · 1.01 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
import Parser from "./Parser.js"
import RegExpParser from "./RegExpParser.js"
/**
* @readonly
* @enum {RegExp}
*/
export const ClassMetacharacter = {
d: /\d/,
D: /\D/,
s: /\s/,
S: /\S/,
w: /\w/,
W: /\W/,
}
/**
* @template {keyof typeof ClassMetacharacter} T
* @extends RegExpParser<0>
*/
export default class ClassShorthandParser extends RegExpParser {
#char
/** @param {T} char */
constructor(char) {
if (!ClassMetacharacter[char]) {
throw new Error("Unexpected metacharacter")
}
super(ClassMetacharacter[char], 0)
this.#char = char
}
/**
* @protected
* @param {Context} context
* @param {Parser<any>} other
* @param {Boolean} strict
*/
doEquals(context, other, strict) {
return other instanceof ClassShorthandParser && this.#char == other.#char
}
/**
* @protected
* @param {Context} context
*/
doToString(context, indent = 0) {
return "\\" + this.#char
}
}