ast: push try_source_range into default Node implementation

Minor refactoring, reducing macro size.
This commit is contained in:
Peter Ammon
2025-04-20 19:12:40 -07:00
parent 79ec558d08
commit e9d396615b

View File

@@ -119,7 +119,18 @@ fn describe(&self) -> WString {
/// Return the source range for this node, or none if unsourced.
/// This may return none if the parse was incomplete or had an error.
fn try_source_range(&self) -> Option<SourceRange>;
fn try_source_range(&self) -> Option<SourceRange> {
let mut visitor = SourceRangeVisitor {
total: SourceRange::new(0, 0),
any_unsourced: false,
};
visitor.visit(self.as_node());
if visitor.any_unsourced {
None
} else {
Some(visitor.total)
}
}
/// Return the source range for this node, or an empty range {0, 0} if unsourced.
fn source_range(&self) -> SourceRange {
@@ -509,18 +520,6 @@ fn typ(&self) -> Type {
fn category(&self) -> Category {
Category::$category
}
fn try_source_range(&self) -> Option<SourceRange> {
let mut visitor = SourceRangeVisitor {
total: SourceRange::new(0, 0),
any_unsourced: false,
};
visitor.visit(self);
if visitor.any_unsourced {
None
} else {
Some(visitor.total)
}
}
fn as_node(&self) -> &dyn Node {
self
}