ast

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ast defines types used by the regex parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidCharRangeElement

func IsValidCharRangeElement(node CharClassElementNode) bool

Types

type AbsoluteEndOfStringAnchorNode

type AbsoluteEndOfStringAnchorNode struct {
	NodeBase
}

Represents the absolute end of text anchor eg. `\z`

func NewAbsoluteEndOfStringAnchorNode

func NewAbsoluteEndOfStringAnchorNode(span *position.Span) *AbsoluteEndOfStringAnchorNode

Create a new absolute end of text anchor node.

type AbsoluteStartOfStringAnchorNode

type AbsoluteStartOfStringAnchorNode struct {
	NodeBase
}

Represents the absolute start of text anchor eg. `\A`

func NewAbsoluteStartOfStringAnchorNode

func NewAbsoluteStartOfStringAnchorNode(span *position.Span) *AbsoluteStartOfStringAnchorNode

Create a new absolute start of text anchor node.

type AnyCharClassNode

type AnyCharClassNode struct {
	NodeBase
}

Represents the any char class eg. `.`

func NewAnyCharClassNode

func NewAnyCharClassNode(span *position.Span) *AnyCharClassNode

Create a new any char class node.

type BellEscapeNode

type BellEscapeNode struct {
	NodeBase
}

Represents a bell escape eg. `\a`

func NewBellEscapeNode

func NewBellEscapeNode(span *position.Span) *BellEscapeNode

Create a new bell escape node.

type CaretEscapeNode

type CaretEscapeNode struct {
	NodeBase
	Value rune
}

Represents a hex escape eg. `\cK`

func NewCaretEscapeNode

func NewCaretEscapeNode(span *position.Span, value rune) *CaretEscapeNode

Create a new caret escape node.

type CarriageReturnEscapeNode

type CarriageReturnEscapeNode struct {
	NodeBase
}

Represents a carriage return escape eg. `\r`

func NewCarriageReturnEscapeNode

func NewCarriageReturnEscapeNode(span *position.Span) *CarriageReturnEscapeNode

Create a new carriage return escape node.

type CharClassElementNode

type CharClassElementNode interface {
	Node
	// contains filtered or unexported methods
}

Represents a char class element like a char, an escape etc

type CharClassNode

type CharClassNode struct {
	NodeBase
	Elements []CharClassElementNode
	Negated  bool
}

Represents a char class eg. `[foa]`, `[^+*.123]`

func NewCharClassNode

func NewCharClassNode(span *position.Span, elements []CharClassElementNode, negated bool) *CharClassNode

Create a new char class node.

type CharNode

type CharNode struct {
	NodeBase
	Value rune
}

Represents a char eg. `f`, `ę`

func NewCharNode

func NewCharNode(span *position.Span, char rune) *CharNode

Create a new char node.

type CharRangeNode

type CharRangeNode struct {
	NodeBase
	Left  CharClassElementNode
	Right CharClassElementNode
}

Represents a char range eg. `a-z`, `\x22-\x7f`

func NewCharRangeNode

func NewCharRangeNode(span *position.Span, left, right CharClassElementNode) *CharRangeNode

Create a new char range node.

type ConcatenationElementNode

type ConcatenationElementNode interface {
	Node
	// contains filtered or unexported methods
}

Represents a concatenation element like a quantifier, a char, a char class etc

type ConcatenationNode

type ConcatenationNode struct {
	NodeBase
	Elements []ConcatenationElementNode
}

Represents concatenated elements eg. `foo`, `\w-\d`

func NewConcatenationNode

func NewConcatenationNode(span *position.Span, elements []ConcatenationElementNode) *ConcatenationNode

Create a new concatenation node.

type DigitCharClassNode

type DigitCharClassNode struct {
	NodeBase
}

Represents a digit char class eg. `\d`

func NewDigitCharClassNode

func NewDigitCharClassNode(span *position.Span) *DigitCharClassNode

Create a new digit char class node.

type EndOfStringAnchorNode

type EndOfStringAnchorNode struct {
	NodeBase
}

Represents the end of string anchor eg. `$`

func NewEndOfStringAnchorNode

func NewEndOfStringAnchorNode(span *position.Span) *EndOfStringAnchorNode

Create a new end of string anchor node.

type FormFeedEscapeNode

type FormFeedEscapeNode struct {
	NodeBase
}

Represents a form feed escape eg. `\f`

func NewFormFeedEscapeNode

func NewFormFeedEscapeNode(span *position.Span) *FormFeedEscapeNode

Create a new form feed escape node.

type GroupNode

type GroupNode struct {
	NodeBase
	Regex        Node
	Name         string
	SetFlags     bitfield.BitField8
	UnsetFlags   bitfield.BitField8
	NonCapturing bool
}

Represents groups eg. `(foo)`, `(?:\w|\d)`, `(?<foo>\w|\d)`

func NewGroupNode

func NewGroupNode(span *position.Span, regex Node, name string, setFlags, unsetFlags bitfield.BitField8, nonCapturing bool) *GroupNode

Create a new group node.

func (*GroupNode) IsAnyFlagSet

func (g *GroupNode) IsAnyFlagSet() bool

type HexEscapeNode

type HexEscapeNode struct {
	NodeBase
	Value string
}

Represents a hex escape eg. `\x20`, `\x{357}`

func NewHexEscapeNode

func NewHexEscapeNode(span *position.Span, value string) *HexEscapeNode

Create a new hex escape node.

type HorizontalWhitespaceCharClassNode

type HorizontalWhitespaceCharClassNode struct {
	NodeBase
}

Represents a horizontal whitespace char class eg. `\h`

func NewHorizontalWhitespaceCharClassNode

func NewHorizontalWhitespaceCharClassNode(span *position.Span) *HorizontalWhitespaceCharClassNode

Create a new horizontal whitespace char class node.

type InvalidNode

type InvalidNode struct {
	NodeBase
	Token *token.Token
}

Represents a syntax error.

func NewInvalidNode

func NewInvalidNode(span *position.Span, tok *token.Token) *InvalidNode

Create a new invalid node.

type MetaCharEscapeNode

type MetaCharEscapeNode struct {
	NodeBase
	Value rune
}

Represents a meta-char escape eg. `\\`, `\.`, `\+`

func NewMetaCharEscapeNode

func NewMetaCharEscapeNode(span *position.Span, char rune) *MetaCharEscapeNode

Create a new meta-char escape node.

type NMQuantifierNode

type NMQuantifierNode struct {
	NodeBase
	Regex Node
	N     string
	M     string
	Alt   bool
}

Represents an NM quantifier eg. `f{5,}`, `\w{15, 6}?`

func NewNMQuantifierNode

func NewNMQuantifierNode(span *position.Span, regex Node, n, m string, alt bool) *NMQuantifierNode

Create a new NM quantifier node.

type NQuantifierNode

type NQuantifierNode struct {
	NodeBase
	Regex Node
	N     string
	Alt   bool
}

Represents an N quantifier eg. `f{5}`, `\w{15}?`

func NewNQuantifierNode

func NewNQuantifierNode(span *position.Span, regex Node, n string, alt bool) *NQuantifierNode

Create a new N quantifier node.

type NamedCharClassNode

type NamedCharClassNode struct {
	NodeBase
	Name    string
	Negated bool
}

Represents a named char class eg. `[:alpha:]`, `[:^digit:]`

func NewNamedCharClassNode

func NewNamedCharClassNode(span *position.Span, name string, negated bool) *NamedCharClassNode

Create a new named char class node.

type NewlineEscapeNode

type NewlineEscapeNode struct {
	NodeBase
}

Represents a newline escape eg. `\n`

func NewNewlineEscapeNode

func NewNewlineEscapeNode(span *position.Span) *NewlineEscapeNode

Create a new tab escape node.

type Node

type Node interface {
	position.SpanInterface
}

Every node type implements this interface.

type NodeBase

type NodeBase struct {
	// contains filtered or unexported fields
}

Base struct of every AST node.

func (*NodeBase) SetSpan

func (n *NodeBase) SetSpan(span *position.Span)

func (*NodeBase) Span

func (n *NodeBase) Span() *position.Span

type NotDigitCharClassNode

type NotDigitCharClassNode struct {
	NodeBase
}

Represents a not digit char class eg. `\D`

func NewNotDigitCharClassNode

func NewNotDigitCharClassNode(span *position.Span) *NotDigitCharClassNode

Create a new not digit char class node.

type NotHorizontalWhitespaceCharClassNode

type NotHorizontalWhitespaceCharClassNode struct {
	NodeBase
}

Represents a not horizontal whitespace char class eg. `\H`

func NewNotHorizontalWhitespaceCharClassNode

func NewNotHorizontalWhitespaceCharClassNode(span *position.Span) *NotHorizontalWhitespaceCharClassNode

Create a new horizontal whitespace char class node.

type NotVerticalWhitespaceCharClassNode

type NotVerticalWhitespaceCharClassNode struct {
	NodeBase
}

Represents a not vertical whitespace char class node eg. `\V`

func NewNotVerticalWhitespaceCharClassNode

func NewNotVerticalWhitespaceCharClassNode(span *position.Span) *NotVerticalWhitespaceCharClassNode

Create a new vertical whitespace char class node.

type NotWhitespaceCharClassNode

type NotWhitespaceCharClassNode struct {
	NodeBase
}

Represents a not whitespace char class eg. `\S`

func NewNotWhitespaceCharClassNode

func NewNotWhitespaceCharClassNode(span *position.Span) *NotWhitespaceCharClassNode

Create a new not whitespace char class node.

type NotWordBoundaryAnchorNode

type NotWordBoundaryAnchorNode struct {
	NodeBase
}

Represents a not word boundary anchor eg. `\B`

func NewNotWordBoundaryAnchorNode

func NewNotWordBoundaryAnchorNode(span *position.Span) *NotWordBoundaryAnchorNode

Create a new not word boundary anchor node.

type NotWordCharClassNode

type NotWordCharClassNode struct {
	NodeBase
}

Represents a not word char class eg. `\W`

func NewNotWordCharClassNode

func NewNotWordCharClassNode(span *position.Span) *NotWordCharClassNode

Create a new not word char class node.

type OctalEscapeNode

type OctalEscapeNode struct {
	NodeBase
	Value string
}

Represents an octal escape eg. `\20`, `\123`

func NewOctalEscapeNode

func NewOctalEscapeNode(span *position.Span, value string) *OctalEscapeNode

Create a new octal escape node.

type OneOrMoreQuantifierNode

type OneOrMoreQuantifierNode struct {
	NodeBase
	Regex Node
	Alt   bool
}

Represents a one or more quantifier eg. `f+`, `f+?`

func NewOneOrMoreQuantifierNode

func NewOneOrMoreQuantifierNode(span *position.Span, regex Node, alt bool) *OneOrMoreQuantifierNode

Create a new one or more quantifier node.

type PrimaryRegexNode

type PrimaryRegexNode interface {
	Node
	ConcatenationElementNode
	// contains filtered or unexported methods
}

Represents a primary regex element like a char, an escape, a char class, a group etc

type QuotedTextNode

type QuotedTextNode struct {
	NodeBase
	Value string
}

Represents a quoted text eg. `\Qfoo.+-bar?\E`, `\Q192.168.0.1\E`

func NewQuotedTextNode

func NewQuotedTextNode(span *position.Span, value string) *QuotedTextNode

Create a new union node.

type StartOfStringAnchorNode

type StartOfStringAnchorNode struct {
	NodeBase
}

Represents the start of string anchor eg. `^`

func NewStartOfStringAnchorNode

func NewStartOfStringAnchorNode(span *position.Span) *StartOfStringAnchorNode

Create a new start of string anchor node.

type TabEscapeNode

type TabEscapeNode struct {
	NodeBase
}

Represents a tab escape eg. `\t`

func NewTabEscapeNode

func NewTabEscapeNode(span *position.Span) *TabEscapeNode

Create a new tab escape node.

type UnicodeCharClassNode

type UnicodeCharClassNode struct {
	NodeBase
	Value   string
	Negated bool
}

Represents a unicode char class eg. `\pL`, `\p{Latin}`, `\P{Latin}`

func NewUnicodeCharClassNode

func NewUnicodeCharClassNode(span *position.Span, value string, negated bool) *UnicodeCharClassNode

Create a new unicode char class node.

type UnicodeEscapeNode

type UnicodeEscapeNode struct {
	NodeBase
	Value string
}

Represents a unicode escape eg. `\u0020`, `\u{357}`

func NewUnicodeEscapeNode

func NewUnicodeEscapeNode(span *position.Span, value string) *UnicodeEscapeNode

Create a new unicode escape node.

type UnionNode

type UnionNode struct {
	NodeBase
	Left  Node
	Right Node
}

Represents union eg. `foo|bar`, `\w|\d`

func NewUnionNode

func NewUnionNode(span *position.Span, left, right Node) *UnionNode

Create a new union node.

type VerticalWhitespaceCharClassNode

type VerticalWhitespaceCharClassNode struct {
	NodeBase
}

Represents a vertical whitespace char class node eg. `\v`

func NewVerticalWhitespaceCharClassNode

func NewVerticalWhitespaceCharClassNode(span *position.Span) *VerticalWhitespaceCharClassNode

Create a new vertical whitespace char class node.

type WhitespaceCharClassNode

type WhitespaceCharClassNode struct {
	NodeBase
}

Represents a whitespace char class eg. `\s`

func NewWhitespaceCharClassNode

func NewWhitespaceCharClassNode(span *position.Span) *WhitespaceCharClassNode

Create a new whitespace char class node.

type WordBoundaryAnchorNode

type WordBoundaryAnchorNode struct {
	NodeBase
}

Represents a word boundary anchor eg. `\b`

func NewWordBoundaryAnchorNode

func NewWordBoundaryAnchorNode(span *position.Span) *WordBoundaryAnchorNode

Create a new word boundary anchor node.

type WordCharClassNode

type WordCharClassNode struct {
	NodeBase
}

Represents a word char class eg. `\w`

func NewWordCharClassNode

func NewWordCharClassNode(span *position.Span) *WordCharClassNode

Create a new word char class node.

type ZeroOrMoreQuantifierNode

type ZeroOrMoreQuantifierNode struct {
	NodeBase
	Regex Node
	Alt   bool
}

Represents a one or more quantifier eg. `f*`, `f*?`

func NewZeroOrMoreQuantifierNode

func NewZeroOrMoreQuantifierNode(span *position.Span, regex Node, alt bool) *ZeroOrMoreQuantifierNode

Create a new zero or more quantifier node.

type ZeroOrOneQuantifierNode

type ZeroOrOneQuantifierNode struct {
	NodeBase
	Regex Node
	Alt   bool
}

Represents a zero or one quantifier eg. `f?`, `f??`

func NewZeroOrOneQuantifierNode

func NewZeroOrOneQuantifierNode(span *position.Span, regex Node, alt bool) *ZeroOrOneQuantifierNode

Create a new zero or one quantifier node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL