Set AST source on compile.

This commit is contained in:
Stephen Chung 2022-08-14 18:22:07 +08:00
parent 5f2262214d
commit b35a9762fb
2 changed files with 6 additions and 1 deletions

View File

@ -64,6 +64,7 @@ Enhancements
* `Scope::remove` is added to remove a variable from a `Scope`, returning its value.
* The code base is cleaner by running it through Clippy.
* `ParseError::err_type` and `ParseError::position` are added for convenience.
* The source of an `AST` compiled from a script file is set to the file's path.
Version 1.8.0

View File

@ -106,7 +106,11 @@ impl Engine {
/// ```
#[inline]
pub fn compile_file_with_scope(&self, scope: &Scope, path: PathBuf) -> RhaiResultOf<AST> {
Self::read_file(path).and_then(|contents| Ok(self.compile_with_scope(scope, &contents)?))
Self::read_file(&path).and_then(|contents| {
let mut ast = self.compile_with_scope(scope, &contents)?;
ast.set_source(path.to_string_lossy());
Ok(ast)
})
}
/// Evaluate a script file, returning the result value or an error.
///