Debian Codegraph @

src/graph/regex.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#;
2
3 use regex_syntaxrust-analyzer cargo regex-syntax 0.8.5 crate/::utf8rust-analyzer cargo regex-syntax 0.8.5 utf8/::Utf8Sequencesrust-analyzer cargo regex-syntax 0.8.5 utf8/Utf8Sequences#;
4
5 use craterust-analyzer cargo logos-codegen 0.15.1 crate/::graphrust-analyzer cargo logos-codegen 0.15.1 graph/::{Disambiguaterust-analyzer cargo logos-codegen 0.15.1 graph/Disambiguate#, Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#, Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#, Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#, NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#, Rangerust-analyzer cargo logos-codegen 0.15.1 graph/range/Range#, ReservedIdrust-analyzer cargo logos-codegen 0.15.1 graph/ReservedId#, Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#};
6 use craterust-analyzer cargo logos-codegen 0.15.1 crate/::mirrust-analyzer cargo logos-codegen 0.15.1 mir/::{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#, Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#};
7
8 impl<Leaf: Disambiguaterust-analyzer cargo logos-codegen 0.15.1 graph/Disambiguate# + Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#<Leaf> {
9 pub fn regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(&mut self, mir: Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#, then: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#) -> NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId# {
10 self.parse_mirrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]parse_mir().(&mir, then, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, false)
11 }
12
13 fn parse_mirrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]parse_mir().(
14 &mut self,
15 mir: &Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#,
16 then: NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#,
17 miss: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#>,
18 reserved: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ReservedIdrust-analyzer cargo logos-codegen 0.15.1 graph/ReservedId#>,
19 repeated: bool,
20 ) -> NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId# {
21 match mir {
22 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Emptyrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Empty# => then,
23 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Looprust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Loop#(mir) => {
24 let reserved_first = reserved.unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| self.reserverust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]reserve().());
25
26 let (new_then, new_miss);
27 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(old_miss) = miss {
28 // We have to separate the first iteration from the other iterations,
29 // because the `old_miss` path must only be taken if we miss the first
30 // iteration.
31 let reserved_next = self.reserverust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]reserve().();
32 new_then = self.parse_mirrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]parse_mir().(
33 mir,
34 reserved_next.getrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[ReservedId]get().(),
35 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(then),
36 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reserved_next),
37 true,
38 );
39 new_miss = self.mergerust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]merge().(old_miss, then);
40 } else {
41 new_then = reserved_first.getrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[ReservedId]get().();
42 new_miss = then;
43 }
44
45 self.parse_mirrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]parse_mir().(mir, new_then, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new_miss), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reserved_first), true)
46 }
47 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Mayberust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Maybe#(mir) => {
48 let miss = match miss {
49 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) => self.mergerust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]merge().(id, then),
50 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => then,
51 };
52
53 self.parse_mirrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]parse_mir().(mir, then, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(miss), reserved, true)
54 }
55 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Alternationrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Alternation#(alternation) => {
56 let mut fork = Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#::newrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]new().().missrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]miss().(miss);
57
58 for mir in alternation {
59 let id = self.parse_mirrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]parse_mir().(mir, then, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, repeated);
60 let alt = self.fork_offrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]fork_off().(id);
61
62 fork.mergerust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]merge().(alt, self);
63 }
64
65 self.insert_or_pushrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]insert_or_push().(reserved, fork)
66 }
67 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Literalrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Literal#(literal) => {
68 let pattern = literal.0rust-analyzer cargo regex-syntax 0.8.5 hir/Literal#0..to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
69
70 self.insert_or_pushrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]insert_or_push().(reserved, Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#::newrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]new().(pattern, then).missrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]miss().(miss))
71 }
72 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Concatrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Concat#(concat) => {
73 // Take an initial guess at the capacity - estimates a little worse than an average case
74 // scenario by assuming every concat element is singular but has a full code-point unicode literal.
75 // The only way to get the actual size of the Vec is if every sub-concat node is added up.
76 let mut ropebuf: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Rangerust-analyzer cargo logos-codegen 0.15.1 graph/range/Range#> = 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().() 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().4);
77 let mut then = then;
78
79 let mut handle_bytes = |graph: &mut Selfrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`], mir: &Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#, then: &mut NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#| match mir {
80 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Literalrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Literal#(Literalrust-analyzer cargo regex-syntax 0.8.5 hir/Literal#(bytes)) => {
81 ropebuf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(bytes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::<Rangerust-analyzer cargo logos-codegen 0.15.1 graph/range/Range#>::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().));
82 true
83 }
84 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Classrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Class#(Classrust-analyzer cargo regex-syntax 0.8.5 hir/Class#::Unicoderust-analyzer cargo regex-syntax 0.8.5 hir/Class#Unicode#(class)) if is_one_asciirust-analyzer cargo logos-codegen 0.15.1 graph/regex/is_one_ascii().(class, repeated) => {
85 ropebuf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(class.rangesrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicode]ranges().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
86 true
87 }
88 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Classrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Class#(Classrust-analyzer cargo regex-syntax 0.8.5 hir/Class#::Bytesrust-analyzer cargo regex-syntax 0.8.5 hir/Class#Bytes#(class)) if class.rangesrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassBytes]ranges().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 => {
89 ropebuf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(class.rangesrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassBytes]ranges().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
90 true
91 }
92 _ => {
93 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ropebuf.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
94 let rope =
95 Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#::newrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]new().(ropebuf.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().then);
96
97 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().then = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(rope);
98 ropebuf = 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().() 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().4);
99 }
100 false
101 }
102 };
103
104 for mir in concat[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() {
105 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().handle_bytes(self, mir, &mut then) {
106 then = self.parse_mirrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]parse_mir().(mir, then, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, false);
107 }
108 }
109
110 let first_mir = &concat[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
111 if handle_bytes(self, first_mir, &mut then) {
112 let rope = Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#::newrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]new().(ropebuf.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), then)
113 .missrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]miss().(miss);
114 self.insert_or_pushrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]insert_or_push().(reserved, rope)
115 } else {
116 self.parse_mirrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]parse_mir().(first_mir, then, miss, reserved, false)
117 }
118 }
119 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Classrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Class#(Classrust-analyzer cargo regex-syntax 0.8.5 hir/Class#::Unicoderust-analyzer cargo regex-syntax 0.8.5 hir/Class#Unicode#(class)) if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_asciirust-analyzer cargo logos-codegen 0.15.1 graph/regex/is_ascii().(class, repeated) => {
120 let mut ropes = class
121 .iterrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicode]iter().()
122 .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|range| Utf8Sequencesrust-analyzer cargo regex-syntax 0.8.5 utf8/Utf8Sequences#::newrust-analyzer cargo regex-syntax 0.8.5 utf8/impl#[Utf8Sequences]new().(range.startrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicodeRange]start().(), range.endrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicodeRange]end().()))
123 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|sequence| Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#::newrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]new().(sequence.as_slicerust-analyzer cargo regex-syntax 0.8.5 utf8/impl#[Utf8Sequence]as_slice().(), then))
124 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
125
126 if ropes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 {
127 let rope = ropes.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(0);
128
129 return self.insert_or_pushrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]insert_or_push().(reserved, rope.missrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]miss().(miss));
130 }
131
132 let mut root = Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#::newrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]new().().missrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]miss().(miss);
133
134 for rope in ropes {
135 let fork = rope.into_forkrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]into_fork().(self);
136 root.mergerust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]merge().(fork, self);
137 }
138
139 self.insert_or_pushrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]insert_or_push().(reserved, root)
140 }
141 Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::Classrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#Class#(class) => {
142 let mut fork = Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#::newrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]new().().missrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]miss().(miss);
143
144 let class: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Rangerust-analyzer cargo logos-codegen 0.15.1 graph/range/Range#> = match class {
145 Classrust-analyzer cargo regex-syntax 0.8.5 hir/Class#::Unicoderust-analyzer cargo regex-syntax 0.8.5 hir/Class#Unicode#(u) => u.iterrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicode]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
146 Classrust-analyzer cargo regex-syntax 0.8.5 hir/Class#::Bytesrust-analyzer cargo regex-syntax 0.8.5 hir/Class#Bytes#(b) => b.iterrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassBytes]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
147 };
148
149 for range in class {
150 fork.add_branchrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]add_branch().(range, then, self);
151 }
152
153 self.insert_or_pushrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]insert_or_push().(reserved, fork)
154 }
155 }
156 }
157
158 fn insert_or_pushrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]insert_or_push().<N>(&mut self, id: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ReservedIdrust-analyzer cargo logos-codegen 0.15.1 graph/ReservedId#>, node: N) -> NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#
159 where
160 N: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#<Leaf>>,
161 {
162 match id {
163 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) => self.insertrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]insert().(id, node),
164 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => self.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(node),
165 }
166 }
167 }
168
169 /// Return whether current class unicode is ascii.
170 ///
171 /// Because unicode ranges are iterated in increasing order,
172 /// it is only necessary to check the last range.
173 ///
174 /// If the check is performed in a repetition,
175 /// a fast path is used by checking if end of range is 0x0010_FFFF.
176 fn is_asciirust-analyzer cargo logos-codegen 0.15.1 graph/regex/is_ascii().(class: &ClassUnicoderust-analyzer cargo regex-syntax 0.8.5 hir/ClassUnicode#, repeated: bool) -> bool {
177 class.iterrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicode]iter().().lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(true, |range| {
178 let start = range.startrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicodeRange]start().() as u32;
179 let end = range.endrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicodeRange]end().() as u32;
180 end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().128 || (repeated && start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().128 && end 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().0x0010_FFFF)
181 })
182 }
183
184 /// Return whether current class unicode is ascii and only contains
185 /// one range.
186 ///
187 /// See [`is_ascii`] function for more details.
188 fn is_one_asciirust-analyzer cargo logos-codegen 0.15.1 graph/regex/is_one_ascii().(class: &ClassUnicoderust-analyzer cargo regex-syntax 0.8.5 hir/ClassUnicode#, repeated: bool) -> bool {
189 if class.rangesrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicode]ranges().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 {
190 return false;
191 }
192
193 let range = &class.rangesrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicode]ranges().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
194 let start = range.startrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicodeRange]start().() as u32;
195 let end = range.endrust-analyzer cargo regex-syntax 0.8.5 hir/impl#[ClassUnicodeRange]end().() as u32;
196 end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().128 || (repeated && start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().128 && end 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().0x0010_FFFF)
197 }
198
199 #[cfg(test)]
200 mod testsrust-analyzer cargo logos-codegen 0.15.1 graph/regex/tests/ {
201 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::NonZeroU32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU32#;
202
203 use superrust-analyzer cargo logos-codegen 0.15.1 graph/regex/::*;
204 use craterust-analyzer cargo logos-codegen 0.15.1 crate/::graphrust-analyzer cargo logos-codegen 0.15.1 graph/::Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#;
205 use pretty_assertionsrust-analyzer cargo pretty_assertions 1.4.1 crate/::assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!;
206
207 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
208 fn roperust-analyzer cargo logos-codegen 0.15.1 graph/regex/tests/rope().() {
209 let mut graph = Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#::newrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]new().();
210
211 let mir = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().("foobar").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
212
213 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(), 12);
214
215 let leaf = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Leafrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Leaf#("LEAF"));
216 let id = graph.regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(mir, leaf);
217
218 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(graph[rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().id]rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index()., Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Roperust-analyzer cargo logos-codegen 0.15.1 graph/Node#Rope#(Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#::newrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]new().("foobar", leaf)),)
219 }
220
221 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
222 fn alternationrust-analyzer cargo logos-codegen 0.15.1 graph/regex/tests/alternation().() {
223 let mut graph = Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#::newrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]new().();
224
225 let mir = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().("a|b").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
226
227 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(), 2);
228
229 let leaf = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Leafrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Leaf#("LEAF"));
230 let id = graph.regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(mir, leaf);
231
232 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(
233 graph[rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().id]rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().,
234 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Forkrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Fork#(Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#::newrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]new().().branchrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]branch().(b'a', leaf).branchrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]branch().(b'b', leaf)),
235 );
236 }
237
238 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
239 fn repeatrust-analyzer cargo logos-codegen 0.15.1 graph/regex/tests/repeat().() {
240 let mut graph = Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#::newrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]new().();
241
242 let mir = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().("[a-z]*").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
243
244 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(), 0);
245
246 let leaf = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Leafrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Leaf#("LEAF"));
247 let id = graph.regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(mir, leaf);
248
249 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(
250 graph[rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().id]rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().,
251 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Forkrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Fork#(
252 Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#::newrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]new().()
253 .branchrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]branch().('a'..='z', id) // goto self == loop
254 .missrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]miss().(leaf)
255 ),
256 );
257 }
258
259 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
260 fn mayberust-analyzer cargo logos-codegen 0.15.1 graph/regex/tests/maybe().() {
261 let mut graph = Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#::newrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]new().();
262
263 let mir = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().("[a-z]?").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
264
265 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(), 0);
266
267 let leaf = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Leafrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Leaf#("LEAF"));
268 let id = graph.regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(mir, leaf);
269
270 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(
271 graph[rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().id]rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().,
272 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Forkrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Fork#(Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#::newrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]new().().branchrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]branch().('a'..='z', leaf).missrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]miss().(leaf)),
273 );
274 }
275
276 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
277 fn long_concat_389rust-analyzer cargo logos-codegen 0.15.1 graph/regex/tests/long_concat_389().() {
278 let mut graph = Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#::newrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]new().();
279
280 let mir = Mirrust-analyzer cargo logos-codegen 0.15.1 mir/Mir#::utf8rust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]utf8().("abcdefghijklmnopqrstuvwxyz*").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
281
282 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().(), 50);
283
284 let leaf = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Leafrust-analyzer cargo logos-codegen 0.15.1 graph/Node#Leaf#("LEAF"));
285 let id = graph.regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(mir, leaf);
286 let sub_id = NodeIdrust-analyzer cargo logos-codegen 0.15.1 graph/NodeId#(NonZeroU32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU32#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
287
288 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(
289 graph[rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().id]rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().,
290 Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Roperust-analyzer cargo logos-codegen 0.15.1 graph/Node#Rope#(Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#::newrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]new().("abcdefghijklmnopqrstuvwxy", sub_id))
291 );
292
293 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(graph[rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().sub_id]rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index()., Noderust-analyzer cargo logos-codegen 0.15.1 graph/Node#::Roperust-analyzer cargo logos-codegen 0.15.1 graph/Node#Rope#(Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#::newrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]new().("z", sub_id).missrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]miss().(leaf)))
294 }
295 }