1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Validation passes to run after the AST is constructed.
//!
//! Or maybe this is better done on the HIR?
//!
//! This doesn't do anything yet...
//!
//! TODO: add some passes for several things
//! - Checking record type labels to be numeric (+ positive), etc.
//! - Checking infix precedence is a single digit
//! - Checking unterminated strs, etc.
//! - Checking `val rec` always binds an `fn` expr
//! - No repetition of record labels in the same record
//! - No repetition of vids in a binding
//! - No repetition of tyvars in a binding
use crate::SyntaxTree;

/// Apply validation passes, etc.
///
/// This should output a list of errors or something,
/// but importantly should take `&SyntaxTree` since we probably want to
/// defer any semantic analysis to later
pub fn apply_passes(_tree: &SyntaxTree) {}

#[cfg(test)]
pub(crate) mod tests {
    use crate::{Parser, SyntaxTree};
    use expect_test::Expect;

    pub(crate) fn _check<F>(pass: F, should_error: bool, src: &str, expect_fixed: Expect)
    where
        F: Fn(SyntaxTree) -> SyntaxTree,
    {
        let parser = Parser::new(src);
        let tree = parser.parse();

        let fixed_tree = pass(tree);
        let fixed: String = format!("{}", fixed_tree);
        expect_fixed.assert_eq(&fixed);

        assert_eq!(fixed_tree.has_errors(), should_error);
    }
}