onigleam/ast

Types

Kind of absence function

pub type AbsenceKind {
  Repeater
}

Constructors

  • Repeater

    (?~…) - absence repeater

An alternative (branch) in the pattern - alternatives are separated by |

pub type Alternative {
  Alternative(body: List(Node))
}

Constructors

  • Alternative(body: List(Node))

Kind of assertion

pub type AssertionKind {
  LineStart
  LineEnd
  StringStart
  StringEnd
  StringEndNewline
  WordBoundary
  TextSegmentBoundary
  SearchStart
}

Constructors

  • LineStart

    ^ - start of line

  • LineEnd

    $ - end of line

  • StringStart

    \A - start of string

  • StringEnd

    \z - end of string (absolute)

  • StringEndNewline

    \Z - end of string (allows trailing newline)

  • WordBoundary

    \b or \B - word boundary

  • TextSegmentBoundary

    \y or \Y - grapheme cluster boundary

  • SearchStart

    \G - search start (not supported)

Backreference reference type

pub type BackreferenceRef {
  BackrefNumber(Int)
  BackrefName(String)
}

Constructors

  • BackrefNumber(Int)

    Numbered backreference \1, \2, etc.

  • BackrefName(String)

    Named backreference \k

Callout argument

pub type CalloutArg {
  CalloutArgInt(Int)
  CalloutArgString(String)
}

Constructors

  • CalloutArgInt(Int)
  • CalloutArgString(String)

Element that can appear in a character class

pub type CharacterClassElement {
  CCCharacter(value: Int)
  CCRange(min: Int, max: Int)
  CCNested(
    kind: CharacterClassKind,
    negate: Bool,
    body: List(CharacterClassElement),
  )
  CCSet(
    kind: CharacterSetKind,
    value: option.Option(String),
    negate: Bool,
  )
}

Constructors

Kind of character class

pub type CharacterClassKind {
  Union
  Intersection
}

Constructors

  • Union

    Normal union character class [abc]

  • Intersection

    Intersection character class [a&&b]

Kind of character set

pub type CharacterSetKind {
  Dot
  Digit
  WordChar
  Space
  Hex
  Newline
  NotNewline
  Any
  TextSegment
  Property
  Posix
}

Constructors

  • Dot

    . - any character

  • Digit

    \d, \D - digit

  • WordChar

    \w, \W - word character

  • Space

    \s, \S - whitespace

  • Hex

    \h, \H - hex digit

  • Newline

    \R - newline sequence

  • NotNewline

    \N - not newline

  • Any

    \O - any (true any including newlines)

  • TextSegment

    \X - extended grapheme cluster

  • Property

    \p{…} or \P{…} - Unicode property

  • Posix

    [:alpha:] etc - POSIX class

Kind of directive

pub type DirectiveKind {
  Keep
  FlagDirective
}

Constructors

  • Keep

    \K - keep (reset match start)

  • FlagDirective

    (?imx) - flag modifier

Flag modifiers for groups

pub type FlagModifiers {
  FlagModifiers(
    enable: option.Option(FlagSet),
    disable: option.Option(FlagSet),
  )
}

Constructors

Set of flags that can be enabled/disabled

pub type FlagSet {
  FlagSet(ignore_case: Bool, dot_all: Bool, extended: Bool)
}

Constructors

  • FlagSet(ignore_case: Bool, dot_all: Bool, extended: Bool)

Flags extracted from the pattern

pub type Flags {
  Flags(
    ignore_case: Bool,
    dot_all: Bool,
    extended: Bool,
    digit_is_ascii: Bool,
    posix_is_ascii: Bool,
    space_is_ascii: Bool,
    word_is_ascii: Bool,
    text_segment_mode: option.Option(TextSegmentMode),
  )
}

Constructors

  • Flags(
      ignore_case: Bool,
      dot_all: Bool,
      extended: Bool,
      digit_is_ascii: Bool,
      posix_is_ascii: Bool,
      space_is_ascii: Bool,
      word_is_ascii: Bool,
      text_segment_mode: option.Option(TextSegmentMode),
    )

Kind of lookaround assertion

pub type LookaroundKind {
  Lookahead
  Lookbehind
}

Constructors

  • Lookahead

    (?=…) or (?!…)

  • Lookbehind

    (?<=…) or (?<!…)

Named callout kinds

pub type NamedCalloutKind {
  CalloutFail
  CalloutMismatch
  CalloutSkip
  CalloutError
  CalloutMax
  CalloutCount
  CalloutTotalCount
  CalloutCmp
  CalloutCustom(String)
}

Constructors

  • CalloutFail
  • CalloutMismatch
  • CalloutSkip
  • CalloutError
  • CalloutMax
  • CalloutCount
  • CalloutTotalCount
  • CalloutCmp
  • CalloutCustom(String)

AST node representing any element in a pattern

pub type Node {
  AssertionNode(kind: AssertionKind, negate: Bool)
  BackreferenceNode(ref: BackreferenceRef, orphan: Bool)
  CapturingGroupNode(
    number: Int,
    name: option.Option(String),
    is_subroutined: Bool,
    body: List(Alternative),
  )
  CharacterNode(value: Int)
  CharacterClassNode(
    kind: CharacterClassKind,
    negate: Bool,
    body: List(CharacterClassElement),
  )
  CharacterSetNode(
    kind: CharacterSetKind,
    value: option.Option(String),
    negate: Bool,
  )
  DirectiveNode(
    kind: DirectiveKind,
    flags: option.Option(FlagModifiers),
  )
  GroupNode(
    atomic: Bool,
    flags: option.Option(FlagModifiers),
    body: List(Alternative),
  )
  LookaroundNode(
    kind: LookaroundKind,
    negate: Bool,
    body: List(Alternative),
  )
  AbsenceNode(kind: AbsenceKind, body: List(Alternative))
  QuantifierNode(
    kind: QuantifierKind,
    min: Int,
    max: option.Option(Int),
    body: Node,
  )
  SubroutineNode(ref: SubroutineRef)
  NamedCalloutNode(
    kind: NamedCalloutKind,
    tag: option.Option(String),
    arguments: option.Option(List(CalloutArg)),
  )
}

Constructors

Kind of quantifier

pub type QuantifierKind {
  Greedy
  Lazy
  Possessive
}

Constructors

  • Greedy

    Greedy quantifier (default)

  • Lazy

    Lazy quantifier (?)

  • Possessive

    Possessive quantifier (+) - not supported in gleam_regexp

The root AST node representing a complete regex pattern

pub type Regex {
  Regex(body: List(Alternative), flags: Flags)
}

Constructors

Subroutine reference type

pub type SubroutineRef {
  Recursion
  SubroutineNumber(Int)
  SubroutineName(String)
}

Constructors

  • Recursion

    \g<0> - recursion (whole pattern)

  • SubroutineNumber(Int)

    \g - call to numbered group

  • SubroutineName(String)

    \g - call to named group

Text segment matching mode

pub type TextSegmentMode {
  Grapheme
  Word
}

Constructors

  • Grapheme
  • Word

Values

pub fn default_flags() -> Flags

Create default flags (all off)

pub fn empty_alternative() -> Alternative

Create an empty alternative

pub fn empty_flag_set() -> FlagSet

Create an empty flag set

Search Document