Parse pattern expression for WHERE clauses: (node)-[edge]->(node)
(tokens: &[Token])
| 4696 | |
| 4697 | /// Parse pattern expression for WHERE clauses: (node)-[edge]->(node) |
| 4698 | fn pattern_expression(tokens: &[Token]) -> IResult<&[Token], PatternExpression> { |
| 4699 | // Look ahead to see if this starts with a node pattern (open paren followed by identifier or label) |
| 4700 | // This helps distinguish patterns from regular parenthesized expressions |
| 4701 | if let Some(&Token::LeftParen) = tokens.first() { |
| 4702 | // Look at the second token to see if this could be a node pattern |
| 4703 | if let Some(second_token) = tokens.get(1) { |
| 4704 | match second_token { |
| 4705 | // (identifier... |
| 4706 | Token::Identifier(_) => { |
| 4707 | // Check if there's a colon (label) or close paren after identifier |
| 4708 | if let Some(third_token) = tokens.get(2) { |
| 4709 | match third_token { |
| 4710 | Token::Colon | Token::RightParen | Token::LeftBrace => { |
| 4711 | // This looks like a node pattern, try to parse it |
| 4712 | return map(path_pattern, |pattern| PatternExpression { |
| 4713 | pattern, |
| 4714 | location: Location::default(), |
| 4715 | })(tokens); |
| 4716 | } |
| 4717 | _ => {} |
| 4718 | } |
| 4719 | } |
| 4720 | } |
| 4721 | // (:Label... |
| 4722 | Token::Colon => { |
| 4723 | // This looks like a label-only node pattern |
| 4724 | return map(path_pattern, |pattern| PatternExpression { |
| 4725 | pattern, |
| 4726 | location: Location::default(), |
| 4727 | })(tokens); |
| 4728 | } |
| 4729 | // ()... empty node pattern |
| 4730 | Token::RightParen => { |
| 4731 | // Check if there's an edge pattern after the node |
| 4732 | if tokens.len() > 3 { |
| 4733 | if let Some(fourth_token) = tokens.get(3) { |
| 4734 | match fourth_token { |
| 4735 | Token::Dash | Token::LessThan => { |
| 4736 | // This looks like a pattern starting with empty node |
| 4737 | return map(path_pattern, |pattern| PatternExpression { |
| 4738 | pattern, |
| 4739 | location: Location::default(), |
| 4740 | })(tokens); |
| 4741 | } |
| 4742 | _ => {} |
| 4743 | } |
| 4744 | } |
| 4745 | } |
| 4746 | } |
| 4747 | _ => {} |
| 4748 | } |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | // If we get here, this doesn't look like a pattern, so fail |
| 4753 | Err(nom::Err::Error(nom::error::Error::new( |
| 4754 | tokens, |
| 4755 | nom::error::ErrorKind::Tag, |