moonbit-community/treesitter/regex_syntax/ast does not have a README file

    Visitor

    pub(open) trait Visitor {
    fn start(Self) -> Unit = _
    fn visit_pre(Self, Ast) -> Unit raise = _
    fn visit_post(Self, Ast) -> Unit raise = _
    fn visit_alternation_in(Self) -> Unit raise = _
    fn visit_concat_in(Self) -> Unit raise = _
    fn visit_class_set_item_pre(Self, ClassSetItem) -> Unit raise = _
    fn visit_class_set_item_post(Self, ClassSetItem) -> Unit raise = _
    fn visit_class_set_binary_op_pre(Self, ClassSetBinaryOp) -> Unit raise = _
    fn visit_class_set_binary_op_post(Self, ClassSetBinaryOp) -> Unit raise = _
    fn visit_class_set_binary_op_in(Self, ClassSetBinaryOp) -> Unit raise = _
    }

    A trait for visiting an abstract syntax tree (AST) in depth first order.

    Typical usage of this trait involves providing an implementation and then running it using the [visit] function. Upstream's finish (which yields the visitor's output) is left to the caller after visit returns.

    AstError

    pub(all) suberror AstError {
    AstError(kind~ : ErrorKind, pattern~ : String, span~ : Span)
    } derive(Eq,
    Debug
    )

    An error that occurred while parsing a regular expression into an abstract syntax tree (upstream ast::Error).

    Note that not all ASTs represents a valid regular expression. For example, an AST is constructed without error for \p{Quux}, but Quux is not a valid Unicode property name. That particular error is reported when translating an AST to the high-level intermediate representation (HIR).

    AstError::auxiliary_span

    fn AstError::auxiliary_span(self : AstError) -> Span?

    Return an auxiliary span. This span exists only for some errors that benefit from being able to point to two locations in the original regular expression. For example, "duplicate" errors will have the main error position set to the duplicate occurrence while its auxiliary span will be set to the initial occurrence.

    AstError::kind

    fn AstError::kind(self : AstError) -> ErrorKind

    Return the type of this error.

    AstError::pattern

    fn AstError::pattern(self : AstError) -> String

    The original pattern string in which this error occurred.

    AstError::span

    fn AstError::span(self : AstError) -> Span

    Return the span at which this error occurred.

    Alternation

    pub(all) struct Alternation {
    span : Span
    asts : Array[Ast]
    } derive(Eq,
    Debug
    )

    An alternation of regular expressions.

    Alternation::into_ast

    fn Alternation::into_ast(self : Alternation) -> Ast

    Return this alternation as an AST.

    If this alternation contains zero ASTs, then Ast::empty is returned. If this alternation contains exactly 1 AST, then the corresponding AST is returned. Otherwise, Ast::alternation is returned.

    Assertion

    pub(all) struct Assertion {
    span : Span
    kind : AssertionKind
    } derive(Eq,
    Debug
    )

    A single zero-width assertion.

    AssertionKind

    pub(all) enum AssertionKind {
    StartLine
    EndLine
    StartText
    EndText
    WordBoundary
    NotWordBoundary
    WordBoundaryStart
    WordBoundaryEnd
    WordBoundaryStartAngle
    WordBoundaryEndAngle
    WordBoundaryStartHalf
    WordBoundaryEndHalf
    } derive(Eq,
    Debug
    )

    An assertion kind.

    Ast

    pub(all) enum Ast {
    Empty(Span)
    Flags(SetFlags)
    Literal(Literal)
    Dot(Span)
    Assertion(Assertion)
    ClassUnicode(ClassUnicode)
    ClassPerl(ClassPerl)
    ClassBracketed(ClassBracketed)
    Repetition(Repetition)
    Group(Group)
    Alternation(Alternation)
    Concat(Concat)
    } derive(Eq,
    Debug
    )

    An abstract syntax tree for a single regular expression.

    Ast::is_empty

    fn Ast::is_empty(self : Ast) -> Bool

    Return true if and only if this Ast is empty.

    Ast::span

    fn Ast::span(self : Ast) -> Span

    Return the span of this abstract syntax tree.

    CaptureName

    pub(all) struct CaptureName {
    span : Span
    name : String
    index : UInt
    } derive(Eq,
    Debug
    )

    A capture name.

    ClassAscii

    pub(all) struct ClassAscii {
    span : Span
    kind : ClassAsciiKind
    negated : Bool
    } derive(Eq,
    Debug
    )

    An ASCII character class.

    ClassAsciiKind

    pub(all) enum ClassAsciiKind {
    Alnum
    Alpha
    Ascii
    Blank
    Cntrl
    Digit
    Graph
    Lower
    Print
    Punct
    Space
    Upper
    Word
    Xdigit
    } derive(Eq,
    Debug
    )

    The available ASCII character classes.

    ClassAsciiKind::from_name

    fn ClassAsciiKind::from_name(name : String) -> ClassAsciiKind?

    Return the corresponding ClassAsciiKind variant for the given name.

    ClassBracketed

    pub(all) struct ClassBracketed {
    span : Span
    negated : Bool
    kind : ClassSet
    } derive(Eq,
    Debug
    )

    A bracketed character class, e.g., [a-z0-9].

    ClassPerl

    pub(all) struct ClassPerl {
    span : Span
    kind : ClassPerlKind
    negated : Bool
    } derive(Eq,
    Debug
    )

    A Perl character class.

    ClassPerlKind

    pub(all) enum ClassPerlKind {
    Digit
    Space
    Word
    } derive(Eq,
    Debug
    )

    The available Perl character classes.

    ClassSet

    pub(all) enum ClassSet {
    Item(ClassSetItem)
    BinaryOp(ClassSetBinaryOp)
    } derive(Eq,
    Debug
    )

    A character class set.

    ClassSet::span

    fn ClassSet::span(self : ClassSet) -> Span

    Return the span of this character class set.

    ClassSet::union

    fn ClassSet::union(ast : ClassSetUnion) -> ClassSet

    Build a set from a union.

    ClassSetBinaryOp

    pub(all) struct ClassSetBinaryOp {
    span : Span
    kind : ClassSetBinaryOpKind
    lhs : ClassSet
    rhs : ClassSet
    } derive(Eq,
    Debug
    )

    A Unicode character class set operation.

    ClassSetBinaryOpKind

    pub(all) enum ClassSetBinaryOpKind {
    Intersection
    Difference
    SymmetricDifference
    } derive(Eq,
    Debug
    )

    The type of a Unicode character class set operation.

    ClassSetItem

    pub(all) enum ClassSetItem {
    Empty(Span)
    Literal(Literal)
    Range(ClassSetRange)
    Ascii(ClassAscii)
    Unicode(ClassUnicode)
    Perl(ClassPerl)
    Bracketed(ClassBracketed)
    Union(ClassSetUnion)
    } derive(Eq,
    Debug
    )

    A single component of a character class set.

    ClassSetItem::span

    fn ClassSetItem::span(self : ClassSetItem) -> Span

    Return the span of this character class set item.

    ClassSetRange

    pub(all) struct ClassSetRange {
    span : Span
    start : Literal
    end : Literal
    } derive(Eq,
    Debug
    )

    A single character class range in a set.

    ClassSetRange::is_valid

    fn ClassSetRange::is_valid(self : ClassSetRange) -> Bool

    Returns true if and only if this character class range is valid.

    ClassSetUnion

    pub(all) struct ClassSetUnion {
    span : Span
    items : Array[ClassSetItem]
    } derive(Eq,
    Debug
    )

    A union of items inside a character class set.

    ClassSetUnion::into_item

    fn ClassSetUnion::into_item(self : ClassSetUnion) -> ClassSetItem

    Return this union as a character class set item.

    ClassSetUnion::push

    fn ClassSetUnion::push(self : ClassSetUnion, item : ClassSetItem) -> Unit

    Push a new item in this union.

    The ending position of this union's span is updated to the ending position of the span of the item given. If the union is empty, then the starting position of this union is set to the starting position of this item.

    ClassUnicode

    pub(all) struct ClassUnicode {
    span : Span
    negated : Bool
    kind : ClassUnicodeKind
    } derive(Eq,
    Debug
    )

    A Unicode character class.

    ClassUnicode::is_negated

    fn ClassUnicode::is_negated(self : ClassUnicode) -> Bool

    Returns true if this class has been negated.

    Note that this takes the Unicode op into account, if it's present. e.g., is_negated for \P{scx!=Katakana} will return false.

    ClassUnicodeKind

    pub(all) enum ClassUnicodeKind {
    OneLetter(Char)
    Named(String)
    NamedValue(op~ : ClassUnicodeOpKind, name~ : String, value~ : String)
    } derive(Eq,
    Debug
    )

    The available forms of Unicode character classes.

    ClassUnicodeOpKind

    pub(all) enum ClassUnicodeOpKind {
    Equal
    Colon
    NotEqual
    } derive(Eq,
    Debug
    )

    The type of op used in a Unicode character class.

    ClassUnicodeOpKind::is_equal

    fn ClassUnicodeOpKind::is_equal(self : ClassUnicodeOpKind) -> Bool

    Whether the op is an equality op or not.

    Comment

    pub(all) struct Comment {
    span : Span
    comment : String
    } derive(Eq,
    Debug
    )

    A comment from a regular expression with an associated span.

    Concat

    pub(all) struct Concat {
    span : Span
    asts : Array[Ast]
    } derive(Eq,
    Debug
    )

    A concatenation of regular expressions.

    Concat::into_ast

    fn Concat::into_ast(self : Concat) -> Ast

    Return this concatenation as an AST.

    ErrorKind

    pub(all) enum ErrorKind {
    CaptureLimitExceeded
    ClassEscapeInvalid
    ClassRangeInvalid
    ClassRangeLiteral
    ClassUnclosed
    DecimalEmpty
    DecimalInvalid
    EscapeHexEmpty
    EscapeHexInvalid
    EscapeHexInvalidDigit
    EscapeUnexpectedEof
    EscapeUnrecognized
    FlagDanglingNegation
    FlagDuplicate(original~ : Span)
    FlagRepeatedNegation(original~ : Span)
    FlagUnexpectedEof
    FlagUnrecognized
    GroupNameDuplicate(original~ : Span)
    GroupNameEmpty
    GroupNameInvalid
    GroupNameUnexpectedEof
    GroupUnclosed
    GroupUnopened
    NestLimitExceeded(UInt)
    RepetitionCountInvalid
    RepetitionCountDecimalEmpty
    RepetitionCountUnclosed
    RepetitionMissing
    SpecialWordBoundaryUnclosed
    SpecialWordBoundaryUnrecognized
    SpecialWordOrRepetitionUnexpectedEof
    UnicodeClassInvalid
    UnsupportedBackreference
    UnsupportedLookAround
    } derive(Eq,
    Debug
    )

    The type of an error that occurred while building an AST.
    impl Show for ErrorKind

    Flag

    pub(all) enum Flag {
    CaseInsensitive
    MultiLine
    DotMatchesNewLine
    SwapGreed
    Unicode
    CRLF
    IgnoreWhitespace
    } derive(Eq,
    Debug
    )

    A single flag.

    Flags

    pub(all) struct Flags {
    span : Span
    items : Array[FlagsItem]
    } derive(Eq,
    Debug
    )

    A group of flags.

    Flags::add_item

    fn Flags::add_item(self : Flags, item : FlagsItem) -> Int?

    Add the given item to this sequence of flags.

    If the item was added successfully, then None is returned. If the given item is a duplicate, then Some(i) is returned, where items[i].kind == item.kind.

    Flags::flag_state

    fn Flags::flag_state(self : Flags, flag : Flag) -> Bool?

    Returns the state of the given flag in this set.

    FlagsItem

    pub(all) struct FlagsItem {
    span : Span
    kind : FlagsItemKind
    } derive(Eq,
    Debug
    )

    A single item in a group of flags.

    FlagsItemKind

    pub(all) enum FlagsItemKind {
    Negation
    Flag(Flag)
    } derive(Eq,
    Debug
    )

    The kind of an item in a group of flags.

    FlagsItemKind::is_negation

    fn FlagsItemKind::is_negation(self : FlagsItemKind) -> Bool

    Returns true if and only if this item is a negation operator.

    Group

    pub(all) struct Group {
    span : Span
    kind : GroupKind
    ast : Ast
    } derive(Eq,
    Debug
    )

    A grouped regular expression.

    Group::capture_index

    fn Group::capture_index(self : Group) -> UInt?

    Returns the capture index of this group, if this is a capturing group.

    Group::flags

    fn Group::flags(self : Group) -> Flags?

    If this group is non-capturing, then this returns the (possibly empty) set of flags. Otherwise, None is returned.

    Group::is_capturing

    fn Group::is_capturing(self : Group) -> Bool

    Returns true if and only if this group is capturing.

    GroupKind

    pub(all) enum GroupKind {
    CaptureIndex(UInt)
    CaptureName(starts_with_p~ : Bool, name~ : CaptureName)
    NonCapturing(Flags)
    } derive(Eq,
    Debug
    )

    The kind of a group.

    HexLiteralKind

    pub(all) enum HexLiteralKind {
    X
    UnicodeShort
    UnicodeLong
    } derive(Eq,
    Debug
    )

    The type of a Unicode hex literal.

    HexLiteralKind::digits

    fn HexLiteralKind::digits(self : HexLiteralKind) -> Int

    The number of digits that must be used with this literal form when used without brackets.

    Literal

    pub(all) struct Literal {
    span : Span
    kind : LiteralKind
    c : Char
    } derive(Eq,
    Debug
    )

    A single literal expression.

    Literal::byte

    fn Literal::byte(self : Literal) -> Byte?

    If this literal was written as a \x hex escape, then this returns the corresponding byte value. Otherwise, this returns None.

    LiteralKind

    pub(all) enum LiteralKind {
    Verbatim
    Meta
    Superfluous
    Octal
    HexFixed(HexLiteralKind)
    HexBrace(HexLiteralKind)
    Special(SpecialLiteralKind)
    } derive(Eq,
    Debug
    )

    The kind of a single literal expression.

    Parser

    pub struct Parser {
    // private fields
    }

    A regular expression parser.

    This parses a string representation of a regular expression into an abstract syntax tree. The size of the tree is proportional to the length of the regular expression pattern.

    Parser::new

    fn Parser::new() -> Parser

    Create a new parser with a default configuration.

    Parser::parse

    fn Parser::parse(self : Parser, pattern : String) -> Ast raise AstError

    Parse the regular expression into an abstract syntax tree.

    Parser::parse_with_comments

    fn Parser::parse_with_comments(self : Parser, pattern : String) -> WithComments raise AstError

    Parse the regular expression and return an abstract syntax tree with all of the comments found in the pattern.

    ParserBuilder

    pub struct ParserBuilder {
    // private fields
    }

    A builder for a regular expression parser.

    This builder permits modifying configuration options for the parser.

    ParserBuilder::build

    fn ParserBuilder::build(self : ParserBuilder) -> Parser

    Build a parser from this configuration with the given pattern.

    ParserBuilder::empty_min_range

    fn ParserBuilder::empty_min_range(self : ParserBuilder, yes : Bool) -> ParserBuilder

    Allow using {,n} as an equivalent to {0,n}.

    ParserBuilder::ignore_whitespace

    fn ParserBuilder::ignore_whitespace(self : ParserBuilder, yes : Bool) -> ParserBuilder

    Enable verbose mode in the regular expression.

    ParserBuilder::nest_limit

    fn ParserBuilder::nest_limit(self : ParserBuilder, limit : UInt) -> ParserBuilder

    Set the nesting limit for this parser.

    ParserBuilder::new

    Create a new parser builder with a default configuration.

    ParserBuilder::octal

    fn ParserBuilder::octal(self : ParserBuilder, yes : Bool) -> ParserBuilder

    Whether to support octal syntax or not.

    Position

    pub(all) struct Position {
    offset : Int
    line : Int
    column : Int
    } derive(Eq,
    Debug
    )

    A single position in a regular expression.
    impl Compare for Position

    Position::new

    fn Position::new(offset : Int, line : Int, column : Int) -> Position

    Create a new position with the given information.

    Repetition

    pub(all) struct Repetition {
    span : Span
    op : RepetitionOp
    greedy : Bool
    ast : Ast
    } derive(Eq,
    Debug
    )

    A repetition operation applied to a regular expression.

    RepetitionKind

    pub(all) enum RepetitionKind {
    ZeroOrOne
    ZeroOrMore
    OneOrMore
    Range(RepetitionRange)
    } derive(Eq,
    Debug
    )

    The kind of a repetition operator.

    RepetitionOp

    pub(all) struct RepetitionOp {
    span : Span
    kind : RepetitionKind
    } derive(Eq,
    Debug
    )

    The repetition operator itself.

    RepetitionRange

    pub(all) enum RepetitionRange {
    Exactly(UInt)
    AtLeast(UInt)
    Bounded(UInt, UInt)
    } derive(Eq,
    Debug
    )

    A range repetition operator.

    RepetitionRange::is_valid

    fn RepetitionRange::is_valid(self : RepetitionRange) -> Bool

    Returns true if and only if this repetition range is valid.

    SetFlags

    pub(all) struct SetFlags {
    span : Span
    flags : Flags
    } derive(Eq,
    Debug
    )

    A group of flags that is not applied to a particular regular expression.

    Span

    pub(all) struct Span {
    start : Position
    end : Position
    } derive(Eq,
    Debug
    )

    Span represents the position information of a single AST item.

    All span positions are absolute byte offsets that can be used on the original regular expression that was parsed.
    impl Compare for Span

    Span::is_empty

    fn Span::is_empty(self : Span) -> Bool

    Returns true if and only if this span is empty.

    Span::is_one_line

    fn Span::is_one_line(self : Span) -> Bool

    Returns true if and only if this span occurs on a single line.

    Span::new

    fn Span::new(start : Position, end : Position) -> Span

    Create a new span with the given positions.

    Span::splat

    fn Span::splat(pos : Position) -> Span

    Create a new span using the given position as the start and end.

    Span::with_end

    fn Span::with_end(self : Span, pos : Position) -> Span

    Create a new span by replacing the ending the position with the one given.

    Span::with_start

    fn Span::with_start(self : Span, pos : Position) -> Span

    Create a new span by replacing the starting the position with the one given.

    SpecialLiteralKind

    pub(all) enum SpecialLiteralKind {
    Bell
    FormFeed
    Tab
    LineFeed
    CarriageReturn
    VerticalTab
    Space
    } derive(Eq,
    Debug
    )

    The type of a special literal.

    WithComments

    pub(all) struct WithComments {
    ast : Ast
    comments : Array[Comment]
    } derive(Eq,
    Debug
    )

    An abstract syntax tree for a singular expression along with comments found.

    is_escapeable_character

    fn is_escapeable_character(c : Char) -> Bool

    Returns true if the given character can be escaped in a regex.

    This returns true in all cases that is_meta_character returns true, but also returns true in some cases where is_meta_character returns false. For example, % is not a meta character, but it is escapable. That is, % and \% both match a literal % in all contexts.

    is_meta_character

    fn is_meta_character(c : Char) -> Bool

    Returns true if the given character has significance in a regex.

    Generally speaking, these are the only characters which must be escaped in order to match their literal meaning.

    is_word_byte

    fn is_word_byte(c : Byte) -> Bool

    Returns true if and only if the given character is an ASCII word character.

    len_utf8

    fn len_utf8(c : Char) -> Int

    The number of bytes c needs in UTF-8 (Rust char::len_utf8).

    visit

    fn[V : Visitor] visit(ast : Ast, visitor : V) -> Unit raise

    Executes an implementation of Visitor in constant stack space.

    This function will visit every node in the given Ast while calling the appropriate methods provided by the [Visitor] trait.

    If the visitor returns an error at any point, then visiting is stopped and the error is returned.