mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-28 09:31:16 -03:00
ast: push try_source_range into default Node implementation
Minor refactoring, reducing macro size.
This commit is contained in:
25
src/ast.rs
25
src/ast.rs
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user