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
| // A string of length `1`.
| //
| // Example: "3".
| //
| export type character = string;
|
| // Matches any character.
| //
| // Example:
| //
| // String pattern "123" compiles into 3 characters:
| //
| // ["1", "2", "3"]
| //
| type Character = character;
|
| // Matches one of characters.
| //
| // Example:
| //
| // String pattern "[5-9]" compiles into:
| //
| // { op: "[]", args: ["5", "6", "7", "8", "9"] }
| //
| interface OneOfCharacters {
| op: '[]';
| args: character[];
| }
|
| // Matches any of the subtrees.
| //
| // Example:
| //
| // String pattern "123|[5-9]0" compiles into:
| //
| // {
| // op: "|",
| // args: [
| // // First subtree:
| // ["1", "2", "3"],
| // // Second subtree:
| // [
| // { op: "[]", args: ["5", "6", "7", "8", "9"] },
| // "0"
| // ]
| // ]
| // }
| //
| interface OrCondition<MatchTree> {
| op: '|';
| args: MatchTree[];
| }
|
| export type MatchTree = Character | OneOfCharacters | MatchTree[] | OrCondition<MatchTree>;
|
| export default class PatternParser {
| parse(pattern: string): MatchTree;
| }
|
|