unidok_parser/blocks/
comments.rs

1use unidok_repr::ast::blocks::Comment;
2
3use crate::utils::{is_ws, ParseSpaces, Until};
4use crate::{Input, Parse};
5
6pub(crate) struct ParseComment;
7
8impl Parse for ParseComment {
9    type Output = Comment;
10
11    fn parse(&mut self, input: &mut Input) -> Option<Self::Output> {
12        let mut input = input.start();
13
14        input.parse_i(ParseSpaces);
15        input.parse("//")?;
16        let content = input.parse_i(Until(|c| matches!(c, '\n' | '\r')));
17
18        input.apply();
19        Some(Comment { content })
20    }
21
22    fn can_parse(&mut self, input: &mut Input) -> bool {
23        input.rest().trim_start_matches(is_ws).starts_with("//")
24    }
25}