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

Function lex_source

prqlc/prqlc-parser/src/lexer/mod.rs:85–100  ·  view source on GitHub ↗

Lex PRQL into LR, returning either the LR or the errors encountered

(source: &str)

Source from the content-addressed store, hash-verified

83
84/// Lex PRQL into LR, returning either the LR or the errors encountered
85pub fn lex_source(source: &str) -> Result<Tokens, Vec<E>> {
86 let result = lexer().parse(source).into_result();
87
88 match result {
89 Ok(tokens) => Ok(Tokens(insert_start(tokens.to_vec()))),
90 Err(errors) => {
91 // Convert chumsky Simple errors to our Error type
92 let errors = errors
93 .into_iter()
94 .map(|error| convert_lexer_error(source, &error, 0))
95 .collect();
96
97 Err(errors)
98 }
99 }
100}
101
102/// Insert a start token so later stages can treat the start of a file like a newline
103fn insert_start(tokens: Vec<Token>) -> Vec<Token> {

Callers 10

parse_sourceFunction · 0.85
test_lex_sourceFunction · 0.85
test_annotation_tokensFunction · 0.85
test_single_curly_quoteFunction · 0.85
test_interpolation_emptyFunction · 0.85
parse_doc_commentFunction · 0.85
prql_to_tokensFunction · 0.85
runFunction · 0.85

Calls 7

lexerFunction · 0.85
TokensClass · 0.85
insert_startFunction · 0.85
convert_lexer_errorFunction · 0.85
mapMethod · 0.80
into_iterMethod · 0.80
collectMethod · 0.45

Tested by 8

parse_sourceFunction · 0.68
test_lex_sourceFunction · 0.68
test_annotation_tokensFunction · 0.68
test_single_curly_quoteFunction · 0.68
test_interpolation_emptyFunction · 0.68
runFunction · 0.68