2023-09-25 23:06:03 +00:00
|
|
|
//! This example grabs input from stdin, lexes it, and prints which lexer rules matched
|
|
|
|
#![allow(unused_imports)]
|
|
|
|
use conlang::lexer::Lexer;
|
2023-09-27 23:13:01 +00:00
|
|
|
use std::{error::Error, io::stdin};
|
2023-09-25 23:06:03 +00:00
|
|
|
|
2023-09-27 23:13:01 +00:00
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
2023-09-25 23:06:03 +00:00
|
|
|
// get input from stdin
|
|
|
|
for line in stdin().lines() {
|
|
|
|
let line = line?;
|
2023-09-27 23:13:01 +00:00
|
|
|
let mut lexer = Lexer::new(&line);
|
|
|
|
while let Some(token) = lexer.any() {
|
2023-09-28 06:34:56 +00:00
|
|
|
println!("{:#19} │{}│", token.ty(), &line[token.range()])
|
2023-09-25 23:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
2023-09-27 23:13:01 +00:00
|
|
|
}
|