1
//! Whitespace skipping and the `; @annotation` reader-comment
2
//! collector. The annotation handler is the only place that pulls
3
//! `parse_expr` back in from the surrounding module — annotations
4
//! evaluate their RHS as an expression so the sample harness can
5
//! attach metadata like `; @test (= (count 'defun) 5)`.
6

            
7
use winnow::ascii::{line_ending, space0, till_line_ending};
8
use winnow::combinator::opt;
9
use winnow::error::ModalResult;
10
use winnow::prelude::*;
11
use winnow::token::take_while;
12

            
13
use crate::ast::{Annotation, Expr};
14

            
15
1167005262
pub(super) fn skip_ws_and_comments(
16
1167005262
    input: &mut &str,
17
1167005262
    annotations: &mut Vec<Annotation>,
18
1167005262
) -> ModalResult<()> {
19
    loop {
20
1200886793
        let _ = space0.parse_next(input)?;
21
1200886793
        if input.starts_with("; @") {
22
31053
            let _ = "; @".parse_next(input)?;
23
155586
            let name: &str = take_while(1.., |c: char| c.is_alphanumeric() || c == '-' || c == '_')
24
31053
                .parse_next(input)?;
25
31053
            let _ = space0.parse_next(input)?;
26

            
27
31053
            let value = super::parse_expr(input).unwrap_or(Expr::Nil);
28
31053
            annotations.push(Annotation {
29
31053
                name: name.to_string(),
30
31053
                value,
31
31053
            });
32
31053
            let _ = till_line_ending.parse_next(input)?;
33
31053
            let _ = opt(line_ending).parse_next(input)?;
34
1200855740
        } else if input.starts_with(';') {
35
17658198
            let _ = till_line_ending.parse_next(input)?;
36
17658198
            let _ = opt(line_ending).parse_next(input)?;
37
1183197542
        } else if input.starts_with('\n') || input.starts_with('\r') {
38
16192280
            let _ = line_ending.parse_next(input)?;
39
        } else {
40
1167005262
            break;
41
        }
42
    }
43
1167005262
    Ok(())
44
1167005262
}
45

            
46
1126172632
pub(super) fn skip_ws_and_comments_no_annotations(input: &mut &str) -> ModalResult<()> {
47
1126172632
    let mut dummy = Vec::new();
48
1126172632
    skip_ws_and_comments(input, &mut dummy)
49
1126172632
}