1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::scanner::Scanner;
use color_eyre::eyre::Result;

pub fn compile(source: &str) -> Result<()> {
    let mut scanner = Scanner::new(source);

    let mut line = None;
    for token in &mut scanner {
        if Some(token.line) != line {
            print!("{:4} ", token.line);
            line = Some(token.line);
        } else {
            print!("   | ");
        }
        println!("{:2?} '{}'", token.kind, token.value);
    }

    Ok(())
}