pub enum Node {
Empty,
Disjunction(Span, Vec<Node>),
Assertion(Span, AssertionKind),
Alternative(Span, Vec<Node>),
Literal(Span, char, String),
PerlClass(Span, ClassPerlKind, bool),
BackReference(Span, u32),
Dot(Span),
CharacterClass(Span, CharacterClass),
Group(Span, Group),
Quantifier(Span, Box<Node>, QuantifierKind, bool),
NamedBackReference(Span, String),
}
Expand description
The tree structure that is used to represent parsed RegEx patterns.
Variants§
Empty
An empty regex node.
Disjunction(Span, Vec<Node>)
An “either or”. (e.g. a|b
)
Assertion(Span, AssertionKind)
A single assertion.
Alternative(Span, Vec<Node>)
A concatenation of regex nodes. (e.g. ab
)
Literal(Span, char, String)
A single character literal. The String represents the raw string representing the literal which is used to turn the node back into a string without writing explicit newlines for example.
PerlClass(Span, ClassPerlKind, bool)
Matches a character class (e.g. \d
or \w
).
The bool argument indicates if this perl class is negated.
BackReference(Span, u32)
A back reference to a previous group (\1
, \2
, …).
Dot(Span)
A .
that matches everything.
CharacterClass(Span, CharacterClass)
A class of multiple characters such as [A-Z0-9]
Group(Span, Group)
A grouped pattern
Quantifier(Span, Box<Node>, QuantifierKind, bool)
A quantifier which optionally matches or matches multiple times.
bool
indicates whether a lazy quantifier (?
) is present after it.
NamedBackReference(Span, String)
A reference to a group using a name
Implementations§
Source§impl Node
impl Node
Sourcepub fn expanded_nodes(&mut self) -> Box<dyn Iterator<Item = &mut Node> + '_>
pub fn expanded_nodes(&mut self) -> Box<dyn Iterator<Item = &mut Node> + '_>
if this node is an alternative, yield an iterator over those nodes, otherwise yield the node itself.
Sourcepub fn span(&self) -> Option<Span>
pub fn span(&self) -> Option<Span>
get the span of this node, returns None
if the node is an empty node.
Sourcepub fn is(&self, src: impl AsRef<str>, text: impl AsRef<str>) -> bool
pub fn is(&self, src: impl AsRef<str>, text: impl AsRef<str>) -> bool
check if this node is equal to some text
pub fn text<'a>(&self, src: &'a str) -> &'a str
Sourcepub fn from_string(string: impl AsRef<str>) -> Option<Self>
pub fn from_string(string: impl AsRef<str>) -> Option<Self>
create a new node from a string. This method is mostly just used for making simple nodes for replacement.