use std::fmt::Debug;

use crate::lst_parser::syntax_kind::SyntaxKind::*;

use self::module::{mod_body, top_level_item};

use super::{
    input::Input,
    output::Output,
    syntax_kind::{self, lex},
    Parser,
};

mod expression;
mod module;

pub fn source_file(p: &mut Parser) {
    let root = p.start("root");

    mod_body(p);
    // expression::expression(p, false);
    p.eat_succeeding_ws();

    root.complete(p, ROOT);
}

fn check_parser(input: &str, parser_fn: fn(&mut Parser), output: &str) {
    let toks = lex(input);
    let mut parser = Parser::new(Input::new(&toks));

    parser_fn(&mut parser);

    let p_out = dbg!(parser.finish());
    let o = Output::from_parser_output(toks, p_out);

    let s = strip_ansi_escapes::strip_str(format!("{o:?}"));
    assert_eq!(&s, output);
}
