Parse identifier or quoted identifier (ISO GQL compliant) Accepts regular identifiers, backtick-delimited identifiers, and keywords as identifiers Examples: myId, `My-Id`, `Property Name`, type, value
(tokens: &[Token])
| 2475 | /// Accepts regular identifiers, backtick-delimited identifiers, and keywords as identifiers |
| 2476 | /// Examples: myId, `My-Id`, `Property Name`, type, value |
| 2477 | fn identifier_or_quoted(tokens: &[Token]) -> IResult<&[Token], String> { |
| 2478 | if let Some(token) = tokens.first() { |
| 2479 | let identifier_str = match token { |
| 2480 | Token::Identifier(s) => Some(s.clone()), |
| 2481 | Token::BacktickString(s) => Some(s.clone()), // ISO GQL delimited identifier: `identifier` |
| 2482 | Token::String(s) => Some(s.clone()), // Allow string literals as fallback (for backwards compatibility) |
| 2483 | // Allow certain keywords to be used as identifiers in contexts like aliases |
| 2484 | Token::Value => Some("value".to_string()), |
| 2485 | Token::Type => Some("type".to_string()), |
| 2486 | Token::User => Some("user".to_string()), |
| 2487 | Token::Role => Some("role".to_string()), |
| 2488 | Token::Schema => Some("schema".to_string()), |
| 2489 | Token::Data => Some("data".to_string()), |
| 2490 | Token::Graph => Some("graph".to_string()), |
| 2491 | Token::Node => Some("node".to_string()), |
| 2492 | Token::Edge => Some("edge".to_string()), |
| 2493 | Token::Path => Some("path".to_string()), |
| 2494 | Token::Table => Some("table".to_string()), |
| 2495 | Token::Property => Some("property".to_string()), |
| 2496 | Token::Source => Some("source".to_string()), |
| 2497 | Token::Destination => Some("destination".to_string()), |
| 2498 | Token::Zone => Some("zone".to_string()), |
| 2499 | Token::Time => Some("time".to_string()), |
| 2500 | Token::Parameter => Some("parameter".to_string()), |
| 2501 | Token::Order => Some("order".to_string()), |
| 2502 | Token::Contains => Some("contains".to_string()), |
| 2503 | Token::Next => Some("next".to_string()), |
| 2504 | Token::Start => Some("start".to_string()), |
| 2505 | Token::End => Some("end".to_string()), |
| 2506 | _ => None, |
| 2507 | }; |
| 2508 | |
| 2509 | if let Some(s) = identifier_str { |
| 2510 | // Reject empty identifiers |
| 2511 | if s.is_empty() { |
| 2512 | return Err(nom::Err::Error(nom::error::Error::new( |
| 2513 | tokens, |
| 2514 | nom::error::ErrorKind::Verify, |
| 2515 | ))); |
| 2516 | } |
| 2517 | Ok((&tokens[1..], s)) |
| 2518 | } else { |
| 2519 | Err(nom::Err::Error(nom::error::Error::new( |
| 2520 | tokens, |
| 2521 | nom::error::ErrorKind::Tag, |
| 2522 | ))) |
| 2523 | } |
| 2524 | } else { |
| 2525 | Err(nom::Err::Error(nom::error::Error::new( |
| 2526 | tokens, |
| 2527 | nom::error::ErrorKind::Tag, |
| 2528 | ))) |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | /// Parse string literal |
| 2533 | fn string_literal(tokens: &[Token]) -> IResult<&[Token], String> { |