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

Function create_graph_statement

graphlite/src/ast/parser.rs:2692–2743  ·  view source on GitHub ↗

Parse CREATE GRAPH statement

(tokens: &[Token])

Source from the content-addressed store, hash-verified

2690
2691/// Parse CREATE GRAPH statement
2692fn create_graph_statement(tokens: &[Token]) -> IResult<&[Token], CreateGraphStatement> {
2693 // Check if next token is Type - if so, fail early to let CREATE GRAPH TYPE parse it
2694 if !tokens.is_empty() {
2695 // Skip CREATE [OR REPLACE] [PROPERTY] GRAPH tokens
2696 let mut skip_count = 1; // CREATE
2697 if tokens.len() > skip_count && matches!(tokens[skip_count], Token::Or) {
2698 skip_count += 2; // OR REPLACE
2699 }
2700 if tokens.len() > skip_count && matches!(tokens[skip_count], Token::Property) {
2701 skip_count += 1; // PROPERTY
2702 }
2703 skip_count += 1; // GRAPH
2704
2705 if tokens.len() > skip_count && matches!(tokens[skip_count], Token::Type) {
2706 // This is CREATE GRAPH TYPE, not CREATE GRAPH
2707 return Err(nom::Err::Error(nom::error::Error::new(
2708 tokens,
2709 nom::error::ErrorKind::Alt,
2710 )));
2711 }
2712 }
2713
2714 map(
2715 tuple((
2716 expect_token(Token::Create),
2717 opt(tuple((
2718 expect_token(Token::Or),
2719 expect_token(Token::Replace),
2720 ))),
2721 opt(expect_token(Token::Property)),
2722 expect_token(Token::Graph),
2723 opt(tuple((
2724 expect_token(Token::If),
2725 expect_token(Token::Not),
2726 expect_token(Token::Exists),
2727 ))),
2728 catalog_path,
2729 opt(graph_type_spec),
2730 opt(tuple((expect_token(Token::As), query))),
2731 )),
2732 |(_, or_replace, _, _, if_not_exists, graph_path, graph_type_spec, as_query)| {
2733 CreateGraphStatement {
2734 graph_path,
2735 graph_type_spec,
2736 if_not_exists: if_not_exists.is_some(),
2737 or_replace: or_replace.is_some(),
2738 as_query: as_query.map(|(_, query)| Box::new(query)),
2739 location: Location::default(),
2740 }
2741 },
2742 )(tokens)
2743}
2744
2745/// Parse DROP GRAPH statement
2746fn drop_graph_statement(tokens: &[Token]) -> IResult<&[Token], DropGraphStatement> {

Callers

nothing calls this directly

Calls 4

ErrorEnum · 0.85
expect_tokenFunction · 0.85
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected