MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / edge_pattern

Function edge_pattern

graphlite/src/ast/parser.rs:1267–1315  ·  view source on GitHub ↗

Parse edge pattern: -[:label {properties}]-

(tokens: &[Token])

Source from the content-addressed store, hash-verified

1265
1266/// Parse edge pattern: -[:label {properties}]-
1267fn edge_pattern(tokens: &[Token]) -> IResult<&[Token], Edge> {
1268 map(
1269 tuple((
1270 edge_direction,
1271 expect_token(Token::LeftBracket),
1272 // Parse identifier and optional label expression, or just label expression, or nothing
1273 alt((
1274 map(
1275 tuple((
1276 identifier,
1277 opt(preceded(expect_token(Token::Colon), label_expression)),
1278 )),
1279 |(identifier, label_expr)| {
1280 (
1281 Some(identifier),
1282 label_expr.map(label_expression_to_strings),
1283 )
1284 },
1285 ),
1286 map(
1287 preceded(expect_token(Token::Colon), label_expression),
1288 |label_expr| (None, Some(label_expression_to_strings(label_expr))),
1289 ),
1290 // Allow empty patterns like -[]->
1291 value((None, None), success(())),
1292 )),
1293 opt(property_map),
1294 expect_token(Token::RightBracket),
1295 opt(path_quantifier), // ISO GQL: quantifier after ] but before final direction
1296 edge_direction,
1297 )),
1298 |(left_dir, _, (identifier, labels), properties, _, quantifier, right_dir)| {
1299 let direction = match (left_dir, right_dir) {
1300 (EdgeDirection::Incoming, EdgeDirection::Outgoing) => EdgeDirection::Both,
1301 (EdgeDirection::Incoming, _) => EdgeDirection::Incoming,
1302 (_, EdgeDirection::Outgoing) => EdgeDirection::Outgoing,
1303 _ => EdgeDirection::Undirected,
1304 };
1305 Edge {
1306 identifier,
1307 labels: labels.unwrap_or_default(),
1308 properties,
1309 direction,
1310 quantifier, // ISO GQL: quantifier parsed after ] but before final direction
1311 location: Location::default(),
1312 }
1313 },
1314 )(tokens)
1315}
1316
1317/// Parse label list: :label (&label)* OR :label (:label)* (BNF-compliant + backward compatible)
1318/// Supports ISO GQL delimited identifiers: :`Special-Label`

Callers

nothing calls this directly

Calls 2

expect_tokenFunction · 0.85

Tested by

no test coverage detected