-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.ts
38 lines (34 loc) · 1.04 KB
/
index.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
import * as AST from "./ast"
import { RegExpParser } from "./parser"
import { RegExpValidator } from "./validator"
import { RegExpVisitor } from "./visitor"
export { AST, RegExpParser, RegExpValidator }
/**
* Parse a given regular expression literal then make AST object.
* @param source The source code to parse.
* @param options The options to parse.
* @returns The AST of the regular expression.
*/
export function parseRegExpLiteral(
source: string | RegExp,
options?: RegExpParser.Options,
): AST.RegExpLiteral {
return new RegExpParser(options).parseLiteral(String(source))
}
/**
* Validate a given regular expression literal.
* @param source The source code to validate.
* @param options The options to validate.
*/
export function validateRegExpLiteral(
source: string,
options?: RegExpValidator.Options,
): void {
return new RegExpValidator(options).validateLiteral(source)
}
export function visitRegExpAST(
node: AST.Node,
handlers: RegExpVisitor.Handlers,
): void {
new RegExpVisitor(handlers).visit(node)
}