MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / parse_into_statement

Function parse_into_statement

crates/gitql-parser/src/parse_into.rs:7–208  ·  view source on GitHub ↗
(
    tokens: &[Token],
    position: &mut usize,
)

Source from the content-addressed store, hash-verified

5use crate::token::{Token, TokenKind};
6
7pub(crate) fn parse_into_statement(
8 tokens: &[Token],
9 position: &mut usize,
10) -> Result<Statement, Box<Diagnostic>> {
11 // Consume `INTO` keyword
12 *position += 1;
13
14 // Make sure user define explicitly the into type
15 if *position >= tokens.len()
16 || (tokens[*position].kind != TokenKind::Outfile
17 && tokens[*position].kind != TokenKind::Dumpfile)
18 {
19 return Err(Diagnostic::error(
20 "Expect Keyword `OUTFILE` or `DUMPFILE` after keyword `INTO`",
21 )
22 .with_location(calculate_safe_location(tokens, *position))
23 .as_boxed());
24 }
25
26 // Consume `OUTFILE` or `DUMPFILE` keyword
27 let file_format_kind = &tokens[*position].kind;
28 *position += 1;
29
30 // Make sure user defined a file path as string literal
31 if *position >= tokens.len() || !matches!(tokens[*position].kind, TokenKind::String(_)) {
32 return Err(Diagnostic::error(
33 "Expect String literal as file path after OUTFILE or DUMPFILE keyword",
34 )
35 .with_location(calculate_safe_location(tokens, *position))
36 .as_boxed());
37 }
38
39 let file_path = &tokens[*position].to_string();
40
41 // Consume File path token
42 *position += 1;
43
44 let is_dump_file = *file_format_kind == TokenKind::Dumpfile;
45
46 let mut lines_terminated = if is_dump_file { "" } else { "\n" }.to_string();
47 let mut lines_terminated_used = false;
48
49 let mut fields_terminated = if is_dump_file { "" } else { "," }.to_string();
50 let mut fields_terminated_used = false;
51
52 let mut enclosed = String::new();
53 let mut enclosed_used = false;
54
55 while *position < tokens.len() {
56 let token = &tokens[*position];
57
58 if token.kind == TokenKind::Lines {
59 if is_dump_file {
60 return Err(Diagnostic::error(
61 "`LINES TERMINATED` option can't be used with INTO DUMPFILE",
62 )
63 .add_help("To customize the format replace `DUMPFILE` with `OUTFILE` option")
64 .with_location(tokens[*position].location)

Callers 1

parse_select_queryFunction · 0.85

Calls 6

calculate_safe_locationFunction · 0.85
consume_token_or_errorFunction · 0.85
as_boxedMethod · 0.80
with_locationMethod · 0.80
add_helpMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…