Skip to content

Commit 07a3eac

Browse files
committed
feat: add new api (Node::children and Range::extended_by)
1 parent 449673d commit 07a3eac

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

crates/postgresql-cst-parser/src/tree_sitter.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ impl std::fmt::Display for Range {
9898
}
9999
}
100100

101+
impl Range {
102+
pub fn extended_by(&self, other: &Self) -> Self {
103+
Range {
104+
start_byte: self.start_byte.min(other.start_byte),
105+
end_byte: self.end_byte.max(other.end_byte),
106+
107+
start_position: Point {
108+
row: self.start_position.row.min(other.start_position.row),
109+
column: self.start_position.column.min(other.start_position.column),
110+
},
111+
end_position: Point {
112+
row: self.end_position.row.max(other.end_position.row),
113+
column: self.end_position.column.max(other.end_position.column),
114+
},
115+
}
116+
}
117+
}
118+
101119
impl<'a> Node<'a> {
102120
pub fn walk(&self) -> TreeCursor<'a> {
103121
TreeCursor {
@@ -144,6 +162,20 @@ impl<'a> Node<'a> {
144162
}
145163
}
146164

165+
pub fn children(&self) -> Vec<Node<'a>> {
166+
if let Some(node) = self.node_or_token.as_node() {
167+
node.children_with_tokens()
168+
.map(|node| Node {
169+
input: self.input,
170+
range_map: Rc::clone(&self.range_map),
171+
node_or_token: node,
172+
})
173+
.collect()
174+
} else {
175+
vec![]
176+
}
177+
}
178+
147179
pub fn next_sibling(&self) -> Option<Node<'a>> {
148180
self.node_or_token
149181
.next_sibling_or_token()

0 commit comments

Comments
 (0)