Add source location tracking to AST nodes
The commit expands the source location tracking through the AST by: 1. Switching from raw Expr/Stmt nodes to AstNode wrappers containing source slices 2. Updating interpreter and parser to preserve location info through node traversal 3. Enhancing error reporting with richer source context information
This commit is contained in:
+7
-6
@@ -24,16 +24,16 @@ fn main() -> LoxResult<()> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let mut lox = LoxInterpreter::new();
|
||||
|
||||
if args.len() > 2 {
|
||||
let _ = if args.len() > 2 {
|
||||
eprintln!("Usage: {} [script]", args[0]);
|
||||
std::process::exit(64);
|
||||
} else if args.len() == 2 {
|
||||
// Esegui file
|
||||
lox.run_file(&args[1])?;
|
||||
lox.run_file(&args[1])
|
||||
} else {
|
||||
// Modalità interattiva
|
||||
lox.run_prompt()?;
|
||||
}
|
||||
lox.run_prompt()
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -86,8 +86,9 @@ impl LoxInterpreter {
|
||||
let mut env = Environment::new();
|
||||
let mut interpreter = Interpreter::new(&mut env);
|
||||
let mut result = None;
|
||||
for stmt in stmts {
|
||||
result = Some(interpreter.interpret(stmt)?);
|
||||
for (index, stmt) in stmts.iter().enumerate() {
|
||||
println!("executing stmt {}: {:?}", index, stmt);
|
||||
result = Some(interpreter.interpret(stmt.clone())?);
|
||||
}
|
||||
match result {
|
||||
Some(res) => Ok(res),
|
||||
|
||||
Reference in New Issue
Block a user