MCPcopy Create free account
hub / github.com/PRQL/prql / parse_source

Function parse_source

prqlc/prqlc-parser/src/test.rs:11–56  ·  view source on GitHub ↗

Parse into statements

(source: &str)

Source from the content-addressed store, hash-verified

9
10/// Parse into statements
11pub(crate) fn parse_source(source: &str) -> Result<Vec<Stmt>, Vec<Error>> {
12 let tokens = crate::lexer::lex_source(source)?;
13
14 // Filter out comments
15 let semantic_tokens: Vec<_> = tokens
16 .0
17 .into_iter()
18 .filter(|token| {
19 !matches!(
20 token.kind,
21 crate::lexer::lr::TokenKind::Comment(_) | crate::lexer::lr::TokenKind::LineWrap(_)
22 )
23 })
24 .collect();
25
26 let input = semantic_tokens
27 .as_slice()
28 .map_span(|simple_span: SimpleSpan| {
29 let start_idx = simple_span.start();
30 let end_idx = simple_span.end();
31
32 let start = semantic_tokens
33 .get(start_idx)
34 .map(|t| t.span.start)
35 .unwrap_or(0);
36 let end = semantic_tokens
37 .get(end_idx.saturating_sub(1))
38 .map(|t| t.span.end)
39 .unwrap_or(start);
40
41 Span {
42 start,
43 end,
44 source_id: 0,
45 }
46 });
47
48 let parse_result = stmt::source().parse(input);
49 let (ast, parse_errors) = parse_result.into_output_errors();
50
51 if !parse_errors.is_empty() {
52 log::info!("ast: {ast:?}");
53 return Err(parse_errors.into_iter().map(|e| e.into()).collect());
54 }
55 Ok(ast.unwrap())
56}
57
58#[test]
59fn test_error_unicode_string() {

Callers 5

test_takeFunction · 0.70
test_aggregateFunction · 0.70
test_tab_charactersFunction · 0.70
test_annotationFunction · 0.70

Calls 9

lex_sourceFunction · 0.85
sourceFunction · 0.85
into_iterMethod · 0.80
startMethod · 0.80
endMethod · 0.80
mapMethod · 0.80
is_emptyMethod · 0.80
collectMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected