pub enum Expr {
Show 19 variants
Empty,
Any {
newline: bool,
},
Assertion(Assertion),
Literal {
val: String,
casei: bool,
},
Concat(Vec<Expr>),
Alt(Vec<Expr>),
Group(Box<Expr>),
LookAround(Box<Expr>, LookAround),
Repeat {
child: Box<Expr>,
lo: usize,
hi: usize,
greedy: bool,
},
Delegate {
inner: String,
size: usize,
casei: bool,
},
Backref {
group: usize,
casei: bool,
},
BackrefWithRelativeRecursionLevel {
group: usize,
relative_level: isize,
casei: bool,
},
AtomicGroup(Box<Expr>),
KeepOut,
ContinueFromPreviousMatchEnd,
BackrefExistsCondition(usize),
Conditional {
condition: Box<Expr>,
true_branch: Box<Expr>,
false_branch: Box<Expr>,
},
SubroutineCall(usize),
UnresolvedNamedSubroutineCall {
name: String,
ix: usize,
},
}
Expand description
Regular expression AST. This is public for now but may change.
Variants§
Empty
An empty expression, e.g. the last branch in (a|b|)
Any
Any character, regex .
Assertion(Assertion)
An assertion
Literal
The string as a literal, e.g. a
Concat(Vec<Expr>)
Concatenation of multiple expressions, must match in order, e.g. a.
is a concatenation of
the literal a
and .
for any character
Alt(Vec<Expr>)
Alternative of multiple expressions, one of them must match, e.g. a|b
is an alternative
where either the literal a
or b
must match
Group(Box<Expr>)
Capturing group of expression, e.g. (a.)
matches a
and any character and “captures”
(remembers) the match
LookAround(Box<Expr>, LookAround)
Look-around (e.g. positive/negative look-ahead or look-behind) with an expression, e.g.
(?=a)
means the next character must be a
(but the match is not consumed)
Repeat
Repeat of an expression, e.g. a*
or a+
or a{1,3}
Fields
Delegate
Delegate a regex to the regex crate. This is used as a simplification so that we don’t have to represent all the expressions in the AST, e.g. character classes.
Fields
Backref
Back reference to a capture group, e.g. \1
in (abc|def)\1
references the captured group
and the whole regex matches either abcabc
or defdef
.
Fields
BackrefWithRelativeRecursionLevel
Back reference to a capture group at the given specified relative recursion level.
Fields
AtomicGroup(Box<Expr>)
Atomic non-capturing group, e.g. (?>ab|a)
in text that contains ab
will match ab
and
never backtrack and try a
, even if matching fails after the atomic group.
KeepOut
Keep matched text so far out of overall match
ContinueFromPreviousMatchEnd
Anchor to match at the position where the previous match ended
BackrefExistsCondition(usize)
Conditional expression based on whether the numbered capture group matched or not
Conditional
If/Then/Else Condition. If there is no Then/Else, these will just be empty expressions.
Fields
SubroutineCall(usize)
Subroutine call to the specified group number
UnresolvedNamedSubroutineCall
Unresolved subroutine call to the specified group name
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn parse_tree(re: &str) -> Result<ExprTree>
pub fn parse_tree(re: &str) -> Result<ExprTree>
Parse the regex and return an expression (AST) and a bit set with the indexes of groups that are referenced by backrefs.
Sourcepub fn parse_tree_with_flags(re: &str, flags: u32) -> Result<ExprTree>
pub fn parse_tree_with_flags(re: &str, flags: u32) -> Result<ExprTree>
Parse the regex and return an expression (AST) Flags should be bit based based on flags