mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-28 06:14: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
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue