Parse a single pattern chain: `(a:Person)-[:KNOWS]->(b:Person)-[:KNOWS]->(c)`.
(text: &str)
| 172 | |
| 173 | /// Parse a single pattern chain: `(a:Person)-[:KNOWS]->(b:Person)-[:KNOWS]->(c)`. |
| 174 | fn parse_single_chain(text: &str) -> crate::Result<PatternChain> { |
| 175 | let mut triples = Vec::new(); |
| 176 | let mut pos = 0; |
| 177 | |
| 178 | let (first_node, consumed) = bindings::parse_node_binding(&text[pos..])?; |
| 179 | pos += consumed; |
| 180 | let mut prev_node = first_node; |
| 181 | |
| 182 | while pos < text.len() { |
| 183 | let remaining = text[pos..].trim_start(); |
| 184 | if remaining.is_empty() { |
| 185 | break; |
| 186 | } |
| 187 | pos = text.len() - remaining.len(); |
| 188 | |
| 189 | let (edge, edge_consumed) = bindings::parse_edge_binding(&text[pos..])?; |
| 190 | pos += edge_consumed; |
| 191 | |
| 192 | let remaining = text[pos..].trim_start(); |
| 193 | pos = text.len() - remaining.len(); |
| 194 | let (next_node, node_consumed) = bindings::parse_node_binding(&text[pos..])?; |
| 195 | pos += node_consumed; |
| 196 | |
| 197 | triples.push(PatternTriple { |
| 198 | src: prev_node, |
| 199 | edge, |
| 200 | dst: next_node.clone(), |
| 201 | }); |
| 202 | prev_node = next_node; |
| 203 | } |
| 204 | |
| 205 | if triples.is_empty() { |
| 206 | return Err(crate::Error::BadRequest { |
| 207 | detail: format!("empty pattern chain: '{text}'"), |
| 208 | }); |
| 209 | } |
| 210 | |
| 211 | Ok(PatternChain { triples }) |
| 212 | } |
| 213 | |
| 214 | #[cfg(test)] |
| 215 | mod tests { |
no test coverage detected