mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-29 14:54:56 +00:00
Add Located::start
, Located::end
and impl Deref
This commit is contained in:
parent
3873414b30
commit
ae9d3c3193
4 changed files with 65 additions and 36 deletions
|
@ -24,6 +24,24 @@ impl<T> Located<T> {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue