Lex PRQL into LR, returning either the LR or the errors encountered
(source: &str)
| 83 | |
| 84 | /// Lex PRQL into LR, returning either the LR or the errors encountered |
| 85 | pub 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 |
| 103 | fn insert_start(tokens: Vec<Token>) -> Vec<Token> { |