Add ASTNode::position().

This commit is contained in:
Stephen Chung 2021-09-03 20:47:45 +08:00
parent cbe08fb64e
commit 6a2c9f0293
2 changed files with 11 additions and 0 deletions

View File

@ -26,6 +26,7 @@ Enhancements
* Added `Scope::is_constant` to check if a variable is constant. * 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. * 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`. * `Engine::register_type_XXX` are now available even under `no_object`.
* Added `ASTNode::position`.
Version 1.0.4 Version 1.0.4

View File

@ -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. /// _(internals)_ A statements block.
/// Exported under the `internals` feature only. /// Exported under the `internals` feature only.
/// ///