use std::rc::Rc;
#[derive(Clone, Debug)]
pub enum Ast {
Empty,
Literal(Literal),
Concat(Vec<Ast>),
Group(Rc<Group>),
CharacterClass(CharacterClass),
Alternation(Vec<Ast>),
Repetition(Repetition),
Assertion(AssertionType),
Flags(Flags),
}
#[derive(Copy, Clone, Debug)]
pub struct Literal {
pub c: char,
pub escaped: bool,
}
#[derive(Clone, Debug)]
pub enum Group {
Capturing(CaptureGroup),
NonCapturing(NonCapturingGroup),
NamedCapturing(NamedCapturingGroup),
}
#[derive(Clone, Debug)]
pub struct CaptureGroup {
pub inner: Ast,
}
#[derive(Clone, Debug)]
pub struct NonCapturingGroup {
pub flags: Flags,
pub inner: Ast,
}
#[derive(Clone, Debug)]
pub struct NamedCapturingGroup {
pub name: String,
pub inner: Ast,
}
#[derive(Clone, Debug)]
pub enum CharacterClass {
Bracket(BracketCharacterClass),
Perl(PerlCharacterClass),
Dot,
HorizontalWhitespace,
NotHorizontalWhitespace,
VerticalWhitespace,
NotVerticalWhitespace,
UnicodeProperty(UnicodePropertyClass),
}
#[derive(Clone, Debug)]
pub struct UnicodePropertyClass {
pub negate: bool,
pub name: String,
}
#[derive(Clone, Debug)]
pub enum QuantifierKind {
ZeroOrMore,
RangeExact(u32),
RangeMinMax(u32, u32),
RangeMin(u32),
ZeroOrOne,
OneOrMore,
}
#[derive(Clone, Debug)]
pub struct Quantifier {
pub lazy: bool,
pub kind: QuantifierKind,
}
#[derive(Clone, Debug)]
pub enum PerlCharacterClass {
Digit,
Space,
Word,
NonDigit,
NonSpace,
NonWord,
}
#[derive(Clone, Debug)]
pub struct BracketCharacterClass {
pub negated: bool,
pub items: Vec<BracketCharacterClassItem>,
}
#[derive(Clone, Debug)]
pub enum BracketCharacterClassItem {
Literal(char),
Range(char, char),
PerlCharacterClass(PerlCharacterClass),
UnicodeProperty(UnicodePropertyClass),
AsciiClass(AsciiClass),
HorizontalWhitespace,
NotHorizontalWhitespace,
VerticalWhitespace,
NotVerticalWhitespace,
}
#[derive(Clone, Debug)]
pub struct AsciiClass {
pub negated: bool,
pub kind: AsciiClassKind,
}
#[derive(Clone, Debug)]
pub enum AsciiClassKind {
Alnum,
Alpha,
Ascii,
Blank,
Cntrl,
Digit,
Graph,
Lower,
Print,
Punct,
Space,
Upper,
Word,
Xdigit,
}
#[derive(Clone, Debug)]
pub struct Repetition {
pub quantifier: Quantifier,
pub inner: Rc<Ast>,
}
#[derive(Clone, Debug)]
pub enum AssertionType {
WordBoundary,
NotWordBoundary,
StartLine,
EndLine,
StartText,
EndText,
EndTextOptionalNewline,
}
#[derive(Clone, Debug)]
pub struct Flags {
pub add: Vec<Flag>,
pub remove: Vec<Flag>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Flag {
CaseInsensitive,
MultiLine,
DotMatchesNewLine,
IgnoreWhitespace,
}