Add Located::start, Located::end and impl Deref

This commit is contained in:
Micha Reiser 2023-04-26 10:24:34 -06:00
parent 3873414b30
commit ae9d3c3193
4 changed files with 65 additions and 36 deletions

View file

@ -671,6 +671,24 @@ def write_ast_def(mod, typeinfo, f):
pub fn new(location: Location, end_location: Location, node: T) -> Self {
Self { location, end_location: Some(end_location), custom: (), node }
}
pub const fn start(&self) -> Location {
self.location
}
/// Returns the node's [`end_location`](Located::end_location) or [`location`](Located::start) if
/// [`end_location`](Located::end_location) is `None`.
pub fn end(&self) -> Location {
self.end_location.unwrap_or(self.location)
}
}
impl<T, U> std::ops::Deref for Located<T, U> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.node
}
}
\n
""".lstrip()