/** * The type which includes all nodes. */ import { EnumKindAssertion, EnumKindCharacterSet, EnumKindEdgeAssertion, EnumKindEscapeCharacterSet, EnumTypeNode } from './const'; export type Node = BranchNode | LeafNode; /** * The type which includes all branch nodes. */ export type BranchNode = RegExpLiteral | Pattern | Disjunction | Group | CapturingGroup | Quantifier | CharacterClass | LookaroundAssertion | CharacterClassRange; /** * The type which includes all leaf nodes. */ export type LeafNode = BoundaryAssertion | CharacterSet | Character | Backreference | Flags; /** * The type which includes all atom nodes. */ export type Element = Disjunction | Group | CapturingGroup | Quantifier | CharacterClass | Assertion | CharacterSet | Character | Backreference; /** * The type which includes all character class atom nodes. */ export type CharacterClassElement = EscapeCharacterSet | UnicodePropertyCharacterSet | Character | CharacterClassRange; /** * The type which includes all atom nodes that Alternative node can have as children. */ export type AlternativeElement = Group | CapturingGroup | Quantifier | CharacterClass | Assertion | CharacterSet | Character | Backreference; /** * The type which includes all atom nodes that Quantifier node can have as children. */ export type QuantifiableElement = Group | CapturingGroup | CharacterClass | LookaheadAssertion | CharacterSet | Character | Backreference; /** * The type which defines common properties for all node types. */ export interface NodeBase { /** The node type. */ type: Node["type"]; /** The parent node. */ parent: Node["parent"]; /** The 0-based index that this node starts. */ start: number; /** The 0-based index that this node ends. */ end: number; /** The raw text of this node. */ raw: string; } /** * The root node. */ export interface RegExpLiteral extends NodeBase { type: EnumTypeNode.RegExpLiteral; parent: null; pattern: Pattern; flags: Flags; } /** * The pattern. */ export interface Pattern extends NodeBase { type: EnumTypeNode.Pattern; parent: RegExpLiteral | null; elements: Element[]; } /** * The disjunction. * E.g. `a|b` */ export interface Disjunction extends NodeBase { type: EnumTypeNode.Disjunction; parent: Pattern | Group | CapturingGroup | LookaroundAssertion; alternatives: AlternativeElement[][]; } /** * The uncapturing group. * E.g. `(?:ab)` */ export interface Group extends NodeBase { type: EnumTypeNode.Group; parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion; elements: Element[]; } /** * The capturing group. * E.g. `(ab)`, `(?ab)` */ export interface CapturingGroup extends NodeBase { type: EnumTypeNode.CapturingGroup; parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion; name: string | null; elements: Element[]; references: Backreference[]; } /** * The lookaround assertion. */ export type LookaroundAssertion = LookaheadAssertion | LookbehindAssertion; /** * The lookahead assertion. * E.g. `(?=ab)`, `(?!ab)` */ export interface LookaheadAssertion extends NodeBase { type: EnumTypeNode.LookaheadAssertion; parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion; kind: EnumKindAssertion.LookaheadAssertion; negate: boolean; elements: Element[]; } /** * The lookbehind assertion. * E.g. `(?<=ab)`, `(?` */ export interface Backreference extends NodeBase { type: EnumTypeNode.Backreference; parent: Pattern | Disjunction | Group | CapturingGroup | Quantifier | LookaroundAssertion; ref: number | string; resolved: CapturingGroup; } /** * The flags. */ export interface Flags extends NodeBase { type: EnumTypeNode.Flags; parent: RegExpLiteral | null; dotAll: boolean; global: boolean; ignoreCase: boolean; multiline: boolean; sticky: boolean; unicode: boolean; } declare const _default: typeof import("./ast"); export default _default;