Add check for trailing tokens
Ensure that a script does not contain any tokens after the main expression. This prevents accidental trailing expressions and enforces a clearer script structure.
This commit is contained in:
@@ -108,11 +108,16 @@ impl Environment {
|
||||
let mut parser = Parser::new(source)?;
|
||||
let untyped_ast = parser.parse_expression()?;
|
||||
|
||||
// 2. Bind & Type Check
|
||||
// 2. Check for trailing tokens
|
||||
if !parser.at_eof() {
|
||||
return Err("Unexpected trailing expressions in script. Use (do ...) for sequences.".to_string());
|
||||
}
|
||||
|
||||
// 3. Bind & Type Check
|
||||
let mut binder = Binder::new(self.global_names.clone());
|
||||
let bound_ast = binder.bind(&untyped_ast)?;
|
||||
|
||||
// 3. Execute
|
||||
// 4. Execute
|
||||
let mut vm = VM::new(self.global_values.clone());
|
||||
vm.run(&bound_ast)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user