izanami/src/lib.rs
Seymur Bagirov 5988cd84ef feat: add basic lexing(scanning)
just following the Scanning section of the book. Partially implemented
2024-11-16 23:04:16 +04:00

52 lines
907 B
Rust

use std::{
error::Error,
fs,
io::{self, Write},
};
use token::Token;
mod scanner;
mod token;
mod utils;
pub fn run_file(path: &str) -> Result<(), Box<dyn Error>> {
let file = fs::read_to_string(path)?;
Ok(())
}
pub fn run(src: &str) {
let tokens: Vec<Token> = Vec::new();
}
pub fn run_prompt() -> Result<(), Box<dyn Error>> {
let stdin = io::stdin();
let input = &mut String::new();
print!("> ");
io::stdout().flush()?;
loop {
input.clear();
let _ = stdin.read_line(input)?;
print!("> ");
io::stdout().flush()?;
}
}
#[derive(Debug)]
pub struct RloxError {
msg: String,
line: usize,
}
impl RloxError {
pub fn error(line: i32, message: &str) {
report(line, "", message);
}
}
pub fn report(line: i32, location: &str, message: &str) {
eprintln!("[line {line}] Error {location}: {message}");
}