1 |
|
2 |
|
3 | declare module 'regexpp' {
|
4 | import * as AST from "regexpp/ast";
|
5 | import { RegExpParser } from "regexpp/parser";
|
6 | import { RegExpValidator } from "regexpp/validator";
|
7 | import { RegExpVisitor } from "regexpp/visitor";
|
8 | export { AST, RegExpParser, RegExpValidator };
|
9 | export function parseRegExpLiteral(source: string | RegExp, options?: RegExpParser.Options): AST.RegExpLiteral;
|
10 | export function validateRegExpLiteral(source: string, options?: RegExpValidator.Options): void;
|
11 | export function visitRegExpAST(node: AST.Node, handlers: RegExpVisitor.Handlers): void;
|
12 | }
|
13 |
|
14 | declare module 'regexpp/ast' {
|
15 | export type Node = BranchNode | LeafNode;
|
16 | export type BranchNode = RegExpLiteral | Pattern | Alternative | Group | CapturingGroup | Quantifier | CharacterClass | LookaroundAssertion | CharacterClassRange;
|
17 | export type LeafNode = BoundaryAssertion | CharacterSet | Character | Backreference | Flags;
|
18 | export type Element = Assertion | Quantifier | QuantifiableElement;
|
19 | export type QuantifiableElement = Group | CapturingGroup | CharacterClass | CharacterSet | Character | Backreference | LookaheadAssertion;
|
20 | export type CharacterClassElement = EscapeCharacterSet | UnicodePropertyCharacterSet | Character | CharacterClassRange;
|
21 | export interface NodeBase {
|
22 | type: Node["type"];
|
23 | parent: Node["parent"];
|
24 | start: number;
|
25 | end: number;
|
26 | raw: string;
|
27 | }
|
28 | export interface RegExpLiteral extends NodeBase {
|
29 | type: "RegExpLiteral";
|
30 | parent: null;
|
31 | pattern: Pattern;
|
32 | flags: Flags;
|
33 | }
|
34 | export interface Pattern extends NodeBase {
|
35 | type: "Pattern";
|
36 | parent: RegExpLiteral | null;
|
37 | alternatives: Alternative[];
|
38 | }
|
39 | export interface Alternative extends NodeBase {
|
40 | type: "Alternative";
|
41 | parent: Pattern | Group | CapturingGroup | LookaroundAssertion;
|
42 | elements: Element[];
|
43 | }
|
44 | export interface Group extends NodeBase {
|
45 | type: "Group";
|
46 | parent: Alternative | Quantifier;
|
47 | alternatives: Alternative[];
|
48 | }
|
49 | export interface CapturingGroup extends NodeBase {
|
50 | type: "CapturingGroup";
|
51 | parent: Alternative | Quantifier;
|
52 | name: string | null;
|
53 | alternatives: Alternative[];
|
54 | references: Backreference[];
|
55 | }
|
56 | export type LookaroundAssertion = LookaheadAssertion | LookbehindAssertion;
|
57 | export interface LookaheadAssertion extends NodeBase {
|
58 | type: "Assertion";
|
59 | parent: Alternative | Quantifier;
|
60 | kind: "lookahead";
|
61 | negate: boolean;
|
62 | alternatives: Alternative[];
|
63 | }
|
64 | export interface LookbehindAssertion extends NodeBase {
|
65 | type: "Assertion";
|
66 | parent: Alternative;
|
67 | kind: "lookbehind";
|
68 | negate: boolean;
|
69 | alternatives: Alternative[];
|
70 | }
|
71 | export interface Quantifier extends NodeBase {
|
72 | type: "Quantifier";
|
73 | parent: Alternative;
|
74 | min: number;
|
75 | max: number;
|
76 | greedy: boolean;
|
77 | element: QuantifiableElement;
|
78 | }
|
79 | export interface CharacterClass extends NodeBase {
|
80 | type: "CharacterClass";
|
81 | parent: Alternative | Quantifier;
|
82 | negate: boolean;
|
83 | elements: CharacterClassElement[];
|
84 | }
|
85 | export interface CharacterClassRange extends NodeBase {
|
86 | type: "CharacterClassRange";
|
87 | parent: CharacterClass;
|
88 | min: Character;
|
89 | max: Character;
|
90 | }
|
91 | export type Assertion = BoundaryAssertion | LookaroundAssertion;
|
92 | export type BoundaryAssertion = EdgeAssertion | WordBoundaryAssertion;
|
93 | export interface EdgeAssertion extends NodeBase {
|
94 | type: "Assertion";
|
95 | parent: Alternative | Quantifier;
|
96 | kind: "start" | "end";
|
97 | }
|
98 | export interface WordBoundaryAssertion extends NodeBase {
|
99 | type: "Assertion";
|
100 | parent: Alternative | Quantifier;
|
101 | kind: "word";
|
102 | negate: boolean;
|
103 | }
|
104 | export type CharacterSet = AnyCharacterSet | EscapeCharacterSet | UnicodePropertyCharacterSet;
|
105 | export interface AnyCharacterSet extends NodeBase {
|
106 | type: "CharacterSet";
|
107 | parent: Alternative | Quantifier;
|
108 | kind: "any";
|
109 | }
|
110 | export interface EscapeCharacterSet extends NodeBase {
|
111 | type: "CharacterSet";
|
112 | parent: Alternative | Quantifier | CharacterClass;
|
113 | kind: "digit" | "space" | "word";
|
114 | negate: boolean;
|
115 | }
|
116 | export interface UnicodePropertyCharacterSet extends NodeBase {
|
117 | type: "CharacterSet";
|
118 | parent: Alternative | Quantifier | CharacterClass;
|
119 | kind: "property";
|
120 | key: string;
|
121 | value: string | null;
|
122 | negate: boolean;
|
123 | }
|
124 | export interface Character extends NodeBase {
|
125 | type: "Character";
|
126 | parent: Alternative | Quantifier | CharacterClass | CharacterClassRange;
|
127 | value: number;
|
128 | }
|
129 | export interface Backreference extends NodeBase {
|
130 | type: "Backreference";
|
131 | parent: Alternative | Quantifier;
|
132 | ref: number | string;
|
133 | resolved: CapturingGroup;
|
134 | }
|
135 | export interface Flags extends NodeBase {
|
136 | type: "Flags";
|
137 | parent: RegExpLiteral | null;
|
138 | dotAll: boolean;
|
139 | global: boolean;
|
140 | ignoreCase: boolean;
|
141 | multiline: boolean;
|
142 | sticky: boolean;
|
143 | unicode: boolean;
|
144 | }
|
145 | }
|
146 |
|
147 | declare module 'regexpp/parser' {
|
148 | import { Flags, RegExpLiteral, Pattern } from "regexpp/ast";
|
149 | import { EcmaVersion } from "regexpp/ecma-versions";
|
150 | export namespace RegExpParser {
|
151 | interface Options {
|
152 | strict?: boolean;
|
153 | ecmaVersion?: EcmaVersion;
|
154 | }
|
155 | }
|
156 | export class RegExpParser {
|
157 | constructor(options?: RegExpParser.Options);
|
158 | parseLiteral(source: string, start?: number, end?: number): RegExpLiteral;
|
159 | parseFlags(source: string, start?: number, end?: number): Flags;
|
160 | parsePattern(source: string, start?: number, end?: number, uFlag?: boolean): Pattern;
|
161 | }
|
162 | }
|
163 |
|
164 | declare module 'regexpp/validator' {
|
165 | import { EcmaVersion } from "regexpp/ecma-versions";
|
166 | export namespace RegExpValidator {
|
167 | interface Options {
|
168 | strict?: boolean;
|
169 | ecmaVersion?: EcmaVersion;
|
170 | onLiteralEnter?(start: number): void;
|
171 | onLiteralLeave?(start: number, end: number): void;
|
172 | onFlags?(start: number, end: number, global: boolean, ignoreCase: boolean, multiline: boolean, unicode: boolean, sticky: boolean, dotAll: boolean): void;
|
173 | onPatternEnter?(start: number): void;
|
174 | onPatternLeave?(start: number, end: number): void;
|
175 | onDisjunctionEnter?(start: number): void;
|
176 | onDisjunctionLeave?(start: number, end: number): void;
|
177 | onAlternativeEnter?(start: number, index: number): void;
|
178 | onAlternativeLeave?(start: number, end: number, index: number): void;
|
179 | onGroupEnter?(start: number): void;
|
180 | onGroupLeave?(start: number, end: number): void;
|
181 | onCapturingGroupEnter?(start: number, name: string | null): void;
|
182 | onCapturingGroupLeave?(start: number, end: number, name: string | null): void;
|
183 | onQuantifier?(start: number, end: number, min: number, max: number, greedy: boolean): void;
|
184 | onLookaroundAssertionEnter?(start: number, kind: "lookahead" | "lookbehind", negate: boolean): void;
|
185 | onLookaroundAssertionLeave?(start: number, end: number, kind: "lookahead" | "lookbehind", negate: boolean): void;
|
186 | onEdgeAssertion?(start: number, end: number, kind: "start" | "end"): void;
|
187 | onWordBoundaryAssertion?(start: number, end: number, kind: "word", negate: boolean): void;
|
188 | onAnyCharacterSet?(start: number, end: number, kind: "any"): void;
|
189 | onEscapeCharacterSet?(start: number, end: number, kind: "digit" | "space" | "word", negate: boolean): void;
|
190 | onUnicodePropertyCharacterSet?(start: number, end: number, kind: "property", key: string, value: string | null, negate: boolean): void;
|
191 | onCharacter?(start: number, end: number, value: number): void;
|
192 | onBackreference?(start: number, end: number, ref: number | string): void;
|
193 | onCharacterClassEnter?(start: number, negate: boolean): void;
|
194 | onCharacterClassLeave?(start: number, end: number, negate: boolean): void;
|
195 | onCharacterClassRange?(start: number, end: number, min: number, max: number): void;
|
196 | }
|
197 | }
|
198 | export class RegExpValidator {
|
199 | constructor(options?: RegExpValidator.Options);
|
200 | validateLiteral(source: string, start?: number, end?: number): void;
|
201 | validateFlags(source: string, start?: number, end?: number): void;
|
202 | validatePattern(source: string, start?: number, end?: number, uFlag?: boolean): void;
|
203 | }
|
204 | }
|
205 |
|
206 | declare module 'regexpp/visitor' {
|
207 | import { Alternative, Assertion, Backreference, CapturingGroup, Character, CharacterClass, CharacterClassRange, CharacterSet, Flags, Group, Node, Pattern, Quantifier, RegExpLiteral } from "regexpp/ast";
|
208 | export class RegExpVisitor {
|
209 | constructor(handlers: RegExpVisitor.Handlers);
|
210 | visit(node: Node): void;
|
211 | }
|
212 | export namespace RegExpVisitor {
|
213 | interface Handlers {
|
214 | onAlternativeEnter?(node: Alternative): void;
|
215 | onAlternativeLeave?(node: Alternative): void;
|
216 | onAssertionEnter?(node: Assertion): void;
|
217 | onAssertionLeave?(node: Assertion): void;
|
218 | onBackreferenceEnter?(node: Backreference): void;
|
219 | onBackreferenceLeave?(node: Backreference): void;
|
220 | onCapturingGroupEnter?(node: CapturingGroup): void;
|
221 | onCapturingGroupLeave?(node: CapturingGroup): void;
|
222 | onCharacterEnter?(node: Character): void;
|
223 | onCharacterLeave?(node: Character): void;
|
224 | onCharacterClassEnter?(node: CharacterClass): void;
|
225 | onCharacterClassLeave?(node: CharacterClass): void;
|
226 | onCharacterClassRangeEnter?(node: CharacterClassRange): void;
|
227 | onCharacterClassRangeLeave?(node: CharacterClassRange): void;
|
228 | onCharacterSetEnter?(node: CharacterSet): void;
|
229 | onCharacterSetLeave?(node: CharacterSet): void;
|
230 | onFlagsEnter?(node: Flags): void;
|
231 | onFlagsLeave?(node: Flags): void;
|
232 | onGroupEnter?(node: Group): void;
|
233 | onGroupLeave?(node: Group): void;
|
234 | onPatternEnter?(node: Pattern): void;
|
235 | onPatternLeave?(node: Pattern): void;
|
236 | onQuantifierEnter?(node: Quantifier): void;
|
237 | onQuantifierLeave?(node: Quantifier): void;
|
238 | onRegExpLiteralEnter?(node: RegExpLiteral): void;
|
239 | onRegExpLiteralLeave?(node: RegExpLiteral): void;
|
240 | }
|
241 | }
|
242 | }
|
243 |
|
244 | declare module 'regexpp/ecma-versions' {
|
245 | export type EcmaVersion = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
|
246 | }
|
247 |
|