index.d.ts 11 KB

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