diff --git a/CHANGELOG.md b/CHANGELOG.md index bf7045bd..7cf40d74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Enhancements * Added `Scope::is_constant` to check if a variable is constant. * Added `Scope::set_or_push` to add a new variable only if one doesn't already exist. * `Engine::register_type_XXX` are now available even under `no_object`. +* Added `ASTNode::position`. Version 1.0.4 diff --git a/src/ast.rs b/src/ast.rs index e7541387..40b90dfb 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -875,6 +875,16 @@ impl<'a> From<&'a Expr> for ASTNode<'a> { } } +impl ASTNode<'_> { + /// Get the [`Position`] of this [`ASTNode`]. + pub const fn position(&self) -> Position { + match self { + ASTNode::Stmt(stmt) => stmt.position(), + ASTNode::Expr(expr) => expr.position(), + } + } +} + /// _(internals)_ A statements block. /// Exported under the `internals` feature only. ///