mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
766 B
34 lines
766 B
import {
|
|
Alternative,
|
|
Assertion,
|
|
Atom,
|
|
Disjunction,
|
|
RegExpParser,
|
|
RegExpPattern,
|
|
} from "@chevrotain/regexp-to-ast";
|
|
|
|
let regExpAstCache: { [regex: string]: RegExpPattern } = {};
|
|
const regExpParser = new RegExpParser();
|
|
|
|
// this should be moved to regexp-to-ast
|
|
export type ASTNode =
|
|
| RegExpPattern
|
|
| Disjunction
|
|
| Alternative
|
|
| Assertion
|
|
| Atom;
|
|
|
|
export function getRegExpAst(regExp: RegExp): RegExpPattern {
|
|
const regExpStr = regExp.toString();
|
|
if (regExpAstCache.hasOwnProperty(regExpStr)) {
|
|
return regExpAstCache[regExpStr];
|
|
} else {
|
|
const regExpAst = regExpParser.pattern(regExpStr);
|
|
regExpAstCache[regExpStr] = regExpAst;
|
|
return regExpAst;
|
|
}
|
|
}
|
|
|
|
export function clearRegExpParserCache() {
|
|
regExpAstCache = {};
|
|
}
|
|
|