| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#; |
| 2 | |
| 3 | use lazy_staticrust-analyzer cargo lazy_static 1.5.0 crate/::lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!; |
| 4 | use regex_syntaxrust-analyzer cargo regex-syntax 0.8.5 crate/::hirrust-analyzer cargo regex-syntax 0.8.5 hir/::{Dotrust-analyzer cargo regex-syntax 0.8.5 hir/Dot#, Hirrust-analyzer cargo regex-syntax 0.8.5 hir/Hir#, HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#}; |
| 5 | use regex_syntaxrust-analyzer cargo regex-syntax 0.8.5 crate/::ParserBuilderrust-analyzer cargo regex-syntax 0.8.5 parser/ParserBuilder#; |
| 6 | |
| 7 | pub use regex_syntaxrust-analyzer cargo regex-syntax 0.8.5 crate/::hirrust-analyzer cargo regex-syntax 0.8.5 hir/::{Classrust-analyzer cargo regex-syntax 0.8.5 hir/Class#, ClassUnicoderust-analyzer cargo regex-syntax 0.8.5 hir/ClassUnicode#, Literalrust-analyzer cargo regex-syntax 0.8.5 hir/Literal#}; |
| 8 | |
| 9 | use craterust-analyzer cargo logos-codegen 0.15.1 crate/::errorrust-analyzer cargo logos-codegen 0.15.1 error/::{Errorrust-analyzer cargo logos-codegen 0.15.1 error/Error#, Resultrust-analyzer cargo logos-codegen 0.15.1 error/Result#}; |
| 10 | |
| 11 | lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!! { |
| 12 | static ref DOT_UTF8rust-analyzer cargo logos-codegen 0.15.1 mir/DOT_UTF8#: Hirrust-analyzer cargo regex-syntax 0.8.5 hir/Hir# = Hirrust-analyzer cargo regex-syntax 0.8.5 hir/Hir#::dotrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir]dot().(Dotrust-analyzer cargo regex-syntax 0.8.5 hir/Dot#::AnyCharrust-analyzer cargo regex-syntax 0.8.5 hir/Dot#AnyChar#); |
| 13 | static ref DOT_BYTESrust-analyzer cargo logos-codegen 0.15.1 mir/DOT_BYTES#: Hirrust-analyzer cargo regex-syntax 0.8.5 hir/Hir# = Hirrust-analyzer cargo regex-syntax 0.8.5 hir/Hir#::dotrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir]dot().(Dotrust-analyzer cargo regex-syntax 0.8.5 hir/Dot#::AnyByterust-analyzer cargo regex-syntax 0.8.5 hir/Dot#AnyByte#); |
| 14 | } |
| 15 | |
| 16 | /// Middle Intermediate Representation of the regex, built from |
| 17 | /// `regex_syntax`'s `Hir`. The goal here is to strip and canonicalize |
| 18 | /// the tree, so that we don't have to do transformations later on the |
| 19 | /// graph, with the potential of running into looping references. |
| 20 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 21 | pub enum Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir# { |
| 22 | Emptyrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Empty#, |
| 23 | Looprust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Loop#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#>), |
| 24 | Mayberust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Maybe#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#>), |
| 25 | Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#>), |
| 26 | Alternationrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Alternation#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#>), |
| 27 | Classrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Class#(Classrust-analyzer cargo regex-syntax 0.8.5 hir/Class#), |
| 28 | Literalrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Literal#(Literalrust-analyzer cargo regex-syntax 0.8.5 hir/Literal#), |
| 29 | } |
| 30 | |
| 31 | impl Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir# { |
| 32 | pub fn utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().(source: &str) -> Resultrust-analyzer cargo logos-codegen 0.15.1 error/Result#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#> { |
| 33 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().(ParserBuilderrust-analyzer cargo regex-syntax 0.8.5 parser/ParserBuilder#::newrust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]new().().buildrust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]build().().parserust-analyzer cargo regex-syntax 0.8.5 parser/impl#[Parser]parse().(source)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 34 | } |
| 35 | |
| 36 | pub fn utf8_ignore_caserust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8_ignore_case().(source: &str) -> Resultrust-analyzer cargo logos-codegen 0.15.1 error/Result#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#> { |
| 37 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().( |
| 38 | ParserBuilderrust-analyzer cargo regex-syntax 0.8.5 parser/ParserBuilder#::newrust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]new().() |
| 39 | .case_insensitiverust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]case_insensitive().(true) |
| 40 | .buildrust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]build().() |
| 41 | .parserust-analyzer cargo regex-syntax 0.8.5 parser/impl#[Parser]parse().(source)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 42 | ) |
| 43 | } |
| 44 | |
| 45 | pub fn binaryrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]binary().(source: &str) -> Resultrust-analyzer cargo logos-codegen 0.15.1 error/Result#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#> { |
| 46 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().( |
| 47 | ParserBuilderrust-analyzer cargo regex-syntax 0.8.5 parser/ParserBuilder#::newrust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]new().() |
| 48 | .utf8rust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]utf8().(false) |
| 49 | .unicoderust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]unicode().(false) |
| 50 | .buildrust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]build().() |
| 51 | .parserust-analyzer cargo regex-syntax 0.8.5 parser/impl#[Parser]parse().(source)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | pub fn binary_ignore_caserust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]binary_ignore_case().(source: &str) -> Resultrust-analyzer cargo logos-codegen 0.15.1 error/Result#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#> { |
| 56 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().( |
| 57 | ParserBuilderrust-analyzer cargo regex-syntax 0.8.5 parser/ParserBuilder#::newrust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]new().() |
| 58 | .utf8rust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]utf8().(false) |
| 59 | .unicoderust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]unicode().(false) |
| 60 | .case_insensitiverust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]case_insensitive().(true) |
| 61 | .buildrust-analyzer cargo regex-syntax 0.8.5 parser/impl#[ParserBuilder]build().() |
| 62 | .parserust-analyzer cargo regex-syntax 0.8.5 parser/impl#[Parser]parse().(source)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 63 | ) |
| 64 | } |
| 65 | |
| 66 | pub fn priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(&self) -> usize { |
| 67 | match self { |
| 68 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Emptyrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Empty# | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Looprust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Loop#(_) | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Mayberust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Maybe#(_) => 0, |
| 69 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(concat) => concat.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().(), |
| 70 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Alternationrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Alternation#(alt) => alt.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().).minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#min().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0), |
| 71 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Classrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Class#(_) => 2, |
| 72 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Literalrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Literal#(lit) => match stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&lit.0rust-analyzer cargo regex-syntax 0.8.5 hir/Literal#0.) { |
| 73 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().s.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]count().(), |
| 74 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().lit.0rust-analyzer cargo regex-syntax 0.8.5 hir/Literal#0..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 75 | }, |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<Hirrust-analyzer cargo regex-syntax 0.8.5 hir/Hir#> for Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir# { |
| 81 | type Errorrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]Error# = Errorrust-analyzer cargo logos-codegen 0.15.1 error/Error#; |
| 82 | |
| 83 | fn try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().(hir: Hirrust-analyzer cargo regex-syntax 0.8.5 hir/Hir#) -> Resultrust-analyzer cargo logos-codegen 0.15.1 error/Result#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#> { |
| 84 | match hir.into_kindrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir]into_kind().() { |
| 85 | HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#::Emptyrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#Empty# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Emptyrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Empty#), |
| 86 | HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#::Concatrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#Concat#(concat) => { |
| 87 | let mut out = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(concat.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 88 | |
| 89 | fn extendrust-analyzer cargo logos-codegen 0.15.1 mir/extend().(mir: Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#, out: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#>) { |
| 90 | match mir { |
| 91 | Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(nested) => { |
| 92 | for child in nested { |
| 93 | extendrust-analyzer cargo logos-codegen 0.15.1 mir/extend().(child, out); |
| 94 | } |
| 95 | } |
| 96 | mir => out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(mir), |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | for hir in concat { |
| 101 | extendrust-analyzer cargo logos-codegen 0.15.1 mir/extend().(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().(hir)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., &mut out); |
| 102 | } |
| 103 | |
| 104 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(out)) |
| 105 | } |
| 106 | HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#::Alternationrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#Alternation#(alternation) => { |
| 107 | let alternation = alternation |
| 108 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 109 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().) |
| 110 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo logos-codegen 0.15.1 error/Result#<_>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 111 | |
| 112 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Alternationrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Alternation#(alternation)) |
| 113 | } |
| 114 | HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#::Literalrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#Literal#(literal) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Literalrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Literal#(literal)), |
| 115 | HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#::Classrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#Class#(class) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Classrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Class#(class)), |
| 116 | HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#::Repetitionrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#Repetition#(repetition) => { |
| 117 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repetition.greedyrust-analyzer cargo regex-syntax 0.8.5 hir/Repetition#greedy. { |
| 118 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("#[regex]: non-greedy parsing is currently unsupported.".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 119 | } |
| 120 | |
| 121 | let is_dot = if repetition.subrust-analyzer cargo regex-syntax 0.8.5 hir/Repetition#sub..propertiesrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir]properties().().is_utf8rust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Properties]is_utf8().() { |
| 122 | *rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().repetition.subrust-analyzer cargo regex-syntax 0.8.5 hir/Repetition#sub. rust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir][`PartialEq<Self>`]eq().==rust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir][`PartialEq<Self>`]eq(). rust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir][`PartialEq<Self>`]eq().*rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[DOT_UTF8][Deref]deref().DOT_UTF8rust-analyzer cargo logos-codegen 0.15.1 mir/DOT_UTF8. |
| 123 | } else { |
| 124 | *rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().repetition.subrust-analyzer cargo regex-syntax 0.8.5 hir/Repetition#sub. rust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir][`PartialEq<Self>`]eq().==rust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir][`PartialEq<Self>`]eq(). rust-analyzer cargo regex-syntax 0.8.5 hir/impl#[Hir][`PartialEq<Self>`]eq().*rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[DOT_BYTES][Deref]deref().DOT_BYTESrust-analyzer cargo logos-codegen 0.15.1 mir/DOT_BYTES. |
| 125 | }; |
| 126 | let mir = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().(*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().repetition.subrust-analyzer cargo regex-syntax 0.8.5 hir/Repetition#sub.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 127 | |
| 128 | match (repetition.minrust-analyzer cargo regex-syntax 0.8.5 hir/Repetition#min., repetition.maxrust-analyzer cargo regex-syntax 0.8.5 hir/Repetition#max.) { |
| 129 | (0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#1, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) if is_dot => { |
| 130 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#( |
| 131 | "#[regex]: \".+\" and \".*\" patterns will greedily consume \ |
| 132 | the entire source till the end as Logos does not allow \ |
| 133 | backtracking. If you are looking to match everything until \ |
| 134 | a specific character, you should use a negative character \ |
| 135 | class. E.g., use regex r\"'[^']*'\" to match anything in \ |
| 136 | between two quotes. Read more about that here: \ |
| 137 | https://github.com/maciejhirsz/logos/issues/302#issuecomment-1521342541." |
| 138 | .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 139 | ) |
| 140 | } |
| 141 | // 0 or 1 |
| 142 | (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Mayberust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Maybe#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(mir))), |
| 143 | // 0 or more |
| 144 | (0, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Looprust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Loop#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(mir))), |
| 145 | // 1 or more |
| 146 | (1, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => { |
| 147 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![mir.clonerust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][Clone]clone().(), Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Looprust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Loop#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(mir))])) |
| 148 | } |
| 149 | // Exact {n} |
| 150 | (n, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(m)) if m rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().n => { |
| 151 | let mut out = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(n as usize); |
| 152 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n { |
| 153 | out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(mir.clonerust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][Clone]clone().()); |
| 154 | } |
| 155 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(out)) |
| 156 | } |
| 157 | // At least {n,} |
| 158 | (n, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => { |
| 159 | let mut out = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(n as usize); |
| 160 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n { |
| 161 | out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(mir.clonerust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][Clone]clone().()); |
| 162 | } |
| 163 | out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Looprust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Loop#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(mir))); |
| 164 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(out)) |
| 165 | } |
| 166 | // Bounded {n, m} |
| 167 | (n, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(m)) => { |
| 168 | let mut out = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(m as usize); |
| 169 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n { |
| 170 | out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(mir.clonerust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][Clone]clone().()); |
| 171 | } |
| 172 | for _ in n..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#m { |
| 173 | out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Mayberust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Maybe#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(mir.clonerust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][Clone]clone().()))); |
| 174 | } |
| 175 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(out)) |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#::Capturerust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#Capture#(capture) => Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::try_fromrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir][`TryFrom<Hir>`]try_from().(*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().capture.subrust-analyzer cargo regex-syntax 0.8.5 hir/Capture#sub.), |
| 180 | HirKindrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#::Lookrust-analyzer cargo regex-syntax 0.8.5 hir/HirKind#Look#(_) => { |
| 181 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("#[regex]: look-around assertions are currently unsupported.".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | #[cfg(test)] |
| 188 | mod testsrust-analyzer cargo logos-codegen 0.15.1 mir/tests/ { |
| 189 | use superrust-analyzer cargo logos-codegen 0.15.1 mir/::Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#; |
| 190 | |
| 191 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 192 | fn prioritiesrust-analyzer cargo logos-codegen 0.15.1 mir/tests/priorities().() { |
| 193 | let regexes = [ |
| 194 | ("a", 2), |
| 195 | ("à", 2), |
| 196 | ("京", 2), |
| 197 | ("Eté", 6), |
| 198 | ("Été", 6), |
| 199 | ("[a-z]+", 2), |
| 200 | ("a|b", 2), |
| 201 | ("a|[b-z]", 2), |
| 202 | ("(foo)+", 6), |
| 203 | ("foobar", 12), |
| 204 | ("(fooz|bar)+qux", 12), |
| 205 | ]; |
| 206 | |
| 207 | for (regex, expected) in regexes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 208 | let mir = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().(regex).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 209 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(), *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().expected, "Failed for regex \"{}\"", regex); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 214 | fn equivalent_patternsrust-analyzer cargo logos-codegen 0.15.1 mir/tests/equivalent_patterns().() { |
| 215 | let regexes = [ |
| 216 | ("a|b", "[a-b]"), |
| 217 | ("1|2|3", "[1-3]"), |
| 218 | ("1+", "[1]+"), |
| 219 | ("c*", "[c]*"), |
| 220 | ("aaa", "a{3}"), |
| 221 | ("a[a]{2}", "a{3}"), |
| 222 | ]; |
| 223 | |
| 224 | for (regex_left, regex_right) in regexes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 225 | let mir_left = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().(regex_left).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 226 | let mir_right = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().(regex_right).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 227 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 228 | mir_left.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(), |
| 229 | mir_right.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(), |
| 230 | "Regexes \"{regex_left}\" and \"{regex_right}\" \ |
| 231 | are equivalent but have different priorities" |
| 232 | ); |
| 233 | } |
| 234 | } |
| 235 | } |