index.d.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. export { AST, RegExpParser, RegExpValidator };
  7. export function parseRegExpLiteral(source: string, options?: RegExpParser.Options): AST.RegExpLiteral;
  8. export function validateRegExpLiteral(source: string, options?: RegExpValidator.Options): void;
  9. }
  10. declare module 'regexpp/ast' {
  11. export type Node = BranchNode | LeafNode;
  12. export type BranchNode = RegExpLiteral | Pattern | Disjunction | Group | CapturingGroup | Quantifier | CharacterClass | LookaroundAssertion | CharacterClassRange;
  13. export type LeafNode = BoundaryAssertion | CharacterSet | Character | Backreference | Flags;
  14. export type Element = Disjunction | Group | CapturingGroup | Quantifier | CharacterClass | Assertion | CharacterSet | Character | Backreference;
  15. export type CharacterClassElement = EscapeCharacterSet | UnicodePropertyCharacterSet | Character | CharacterClassRange;
  16. export type AlternativeElement = Group | CapturingGroup | Quantifier | CharacterClass | Assertion | CharacterSet | Character | Backreference;
  17. export type QuantifiableElement = Group | CapturingGroup | CharacterClass | LookaheadAssertion | CharacterSet | Character | Backreference;
  18. export interface NodeBase {
  19. type: Node["type"];
  20. parent: Node["parent"];
  21. start: number;
  22. end: number;
  23. raw: string;
  24. }
  25. export interface RegExpLiteral extends NodeBase {
  26. type: "RegExpLiteral";
  27. parent: null;
  28. pattern: Pattern;
  29. flags: Flags;
  30. }
  31. export interface Pattern extends NodeBase {
  32. type: "Pattern";
  33. parent: RegExpLiteral | null;
  34. elements: Element[];
  35. }
  36. export interface Disjunction extends NodeBase {
  37. type: "Disjunction";
  38. parent: Pattern | Group | CapturingGroup | LookaroundAssertion;
  39. alternatives: AlternativeElement[][];
  40. }
  41. export interface Group extends NodeBase {
  42. type: "Group";
  43. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion;
  44. elements: Element[];
  45. }
  46. export interface CapturingGroup extends NodeBase {
  47. type: "CapturingGroup";
  48. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion;
  49. name: string | null;
  50. elements: Element[];
  51. references: Backreference[];
  52. }
  53. export type LookaroundAssertion = LookaheadAssertion | LookbehindAssertion;
  54. export interface LookaheadAssertion extends NodeBase {
  55. type: "Assertion";
  56. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion;
  57. kind: "lookahead";
  58. negate: boolean;
  59. elements: Element[];
  60. }
  61. export interface LookbehindAssertion extends NodeBase {
  62. type: "Assertion";
  63. parent: Pattern | Disjunction | Group | CapturingGroup | LookaroundAssertion;
  64. kind: "lookbehind";
  65. negate: boolean;
  66. elements: Element[];
  67. }
  68. export interface Quantifier extends NodeBase {
  69. type: "Quantifier";
  70. parent: Pattern | Disjunction | Group | CapturingGroup | LookaroundAssertion;
  71. min: number;
  72. max: number;
  73. greedy: boolean;
  74. element: QuantifiableElement;
  75. }
  76. export interface CharacterClass extends NodeBase {
  77. type: "CharacterClass";
  78. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion;
  79. negate: boolean;
  80. elements: CharacterClassElement[];
  81. }
  82. export interface CharacterClassRange extends NodeBase {
  83. type: "CharacterClassRange";
  84. parent: CharacterClass;
  85. min: Character;
  86. max: Character;
  87. }
  88. export type Assertion = BoundaryAssertion | LookaroundAssertion;
  89. export type BoundaryAssertion = EdgeAssertion | WordBoundaryAssertion;
  90. export interface EdgeAssertion extends NodeBase {
  91. type: "Assertion";
  92. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion;
  93. kind: "start" | "end";
  94. }
  95. export interface WordBoundaryAssertion extends NodeBase {
  96. type: "Assertion";
  97. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion;
  98. kind: "word";
  99. negate: boolean;
  100. }
  101. export type CharacterSet = AnyCharacterSet | EscapeCharacterSet | UnicodePropertyCharacterSet;
  102. export interface AnyCharacterSet extends NodeBase {
  103. type: "CharacterSet";
  104. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion;
  105. kind: "any";
  106. }
  107. export interface EscapeCharacterSet extends NodeBase {
  108. type: "CharacterSet";
  109. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | CharacterClass | LookaroundAssertion;
  110. kind: "digit" | "space" | "word";
  111. negate: boolean;
  112. }
  113. export interface UnicodePropertyCharacterSet extends NodeBase {
  114. type: "CharacterSet";
  115. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | CharacterClass | LookaroundAssertion;
  116. kind: "property";
  117. key: string;
  118. value: string | null;
  119. negate: boolean;
  120. }
  121. export interface Character extends NodeBase {
  122. type: "Character";
  123. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | CharacterClass | LookaroundAssertion | CharacterClassRange;
  124. value: number;
  125. }
  126. export interface Backreference extends NodeBase {
  127. type: "Backreference";
  128. parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion;
  129. ref: number | string;
  130. resolved: CapturingGroup;
  131. }
  132. export interface Flags extends NodeBase {
  133. type: "Flags";
  134. parent: RegExpLiteral | null;
  135. dotAll: boolean;
  136. global: boolean;
  137. ignoreCase: boolean;
  138. multiline: boolean;
  139. sticky: boolean;
  140. unicode: boolean;
  141. }
  142. }
  143. declare module 'regexpp/parser' {
  144. import { Flags, RegExpLiteral, Pattern } from "regexpp/ast";
  145. export namespace RegExpParser {
  146. interface Options {
  147. strict?: boolean;
  148. ecmaVersion?: 5 | 2015 | 2016 | 2017 | 2018;
  149. }
  150. }
  151. export class RegExpParser {
  152. constructor(options?: RegExpParser.Options);
  153. parseLiteral(source: string, start?: number, end?: number): RegExpLiteral;
  154. parseFlags(source: string, start?: number, end?: number): Flags;
  155. parsePattern(source: string, start?: number, end?: number, uFlag?: boolean): Pattern;
  156. }
  157. }
  158. declare module 'regexpp/validator' {
  159. export namespace RegExpValidator {
  160. interface Options {
  161. strict?: boolean;
  162. ecmaVersion?: 5 | 2015 | 2016 | 2017 | 2018;
  163. onLiteralEnter?(start: number): void;
  164. onLiteralLeave?(start: number, end: number): void;
  165. onFlags?(start: number, end: number, global: boolean, ignoreCase: boolean, multiline: boolean, unicode: boolean, sticky: boolean, dotAll: boolean): void;
  166. onPatternEnter?(start: number): void;
  167. onPatternLeave?(start: number, end: number): void;
  168. onDisjunctionEnter?(start: number): void;
  169. onDisjunctionLeave?(start: number, end: number): void;
  170. onAlternativeEnter?(start: number, index: number): void;
  171. onAlternativeLeave?(start: number, end: number, index: number): void;
  172. onGroupEnter?(start: number): void;
  173. onGroupLeave?(start: number, end: number): void;
  174. onCapturingGroupEnter?(start: number, name: string | null): void;
  175. onCapturingGroupLeave?(start: number, end: number, name: string | null): void;
  176. onQuantifier?(start: number, end: number, min: number, max: number, greedy: boolean): void;
  177. onLookaroundAssertionEnter?(start: number, kind: "lookahead" | "lookbehind", negate: boolean): void;
  178. onLookaroundAssertionLeave?(start: number, end: number, kind: "lookahead" | "lookbehind", negate: boolean): void;
  179. onEdgeAssertion?(start: number, end: number, kind: "start" | "end"): void;
  180. onWordBoundaryAssertion?(start: number, end: number, kind: "word", negate: boolean): void;
  181. onAnyCharacterSet?(start: number, end: number, kind: "any"): void;
  182. onEscapeCharacterSet?(start: number, end: number, kind: "digit" | "space" | "word", negate: boolean): void;
  183. onUnicodePropertyCharacterSet?(start: number, end: number, kind: "property", key: string, value: string | null, negate: boolean): void;
  184. onCharacter?(start: number, end: number, value: number): void;
  185. onBackreference?(start: number, end: number, ref: number | string): void;
  186. onCharacterClassEnter?(start: number, negate: boolean): void;
  187. onCharacterClassLeave?(start: number, end: number, negate: boolean): void;
  188. onCharacterClassRange?(start: number, end: number, min: number, max: number): void;
  189. }
  190. }
  191. export class RegExpValidator {
  192. constructor(options?: RegExpValidator.Options);
  193. validateLiteral(source: string, start?: number, end?: number): void;
  194. validateFlags(source: string, start?: number, end?: number): void;
  195. validatePattern(source: string, start?: number, end?: number, uFlag?: boolean): void;
  196. }
  197. }