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

Function parse_doc_comment

prqlc/prqlc-parser/src/parser/mod.rs:205–250  ·  view source on GitHub ↗
(source: &str)

Source from the content-addressed store, hash-verified

203 use crate::error::Error;
204
205 fn parse_doc_comment(source: &str) -> Result<String, Vec<Error>> {
206 let tokens = crate::lexer::lex_source(source)?;
207 let semantic_tokens: Vec<_> = tokens
208 .0
209 .into_iter()
210 .filter(|token| {
211 !matches!(
212 token.kind,
213 crate::lexer::lr::TokenKind::Comment(_)
214 | crate::lexer::lr::TokenKind::LineWrap(_)
215 )
216 })
217 .collect();
218
219 let input = semantic_tokens
220 .as_slice()
221 .map_span(|simple_span: SimpleSpan| {
222 let start_idx = simple_span.start();
223 let end_idx = simple_span.end();
224
225 let start = semantic_tokens
226 .get(start_idx)
227 .map(|t| t.span.start)
228 .unwrap_or(0);
229 let end = semantic_tokens
230 .get(end_idx.saturating_sub(1))
231 .map(|t| t.span.end)
232 .unwrap_or(start);
233
234 Span {
235 start,
236 end,
237 source_id: 0,
238 }
239 });
240
241 let parser = doc_comment()
242 .then_ignore(new_line().repeated())
243 .then_ignore(end());
244 let (ast, errors) = parser.parse(input).into_output_errors();
245
246 if !errors.is_empty() {
247 return Err(errors.into_iter().map(Into::into).collect());
248 }
249 Ok(ast.unwrap())
250 }
251
252 #[test]
253 fn test_doc_comment() {

Callers

nothing calls this directly

Calls 10

lex_sourceFunction · 0.85
new_lineFunction · 0.85
into_iterMethod · 0.80
startMethod · 0.80
endMethod · 0.80
mapMethod · 0.80
is_emptyMethod · 0.80
doc_commentFunction · 0.70
collectMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected