Skip to content

Commit

Permalink
Return Option<Edge> from Helper::current() instead of `Option<(Ed…
Browse files Browse the repository at this point in the history
…geLabel, Node)>`
  • Loading branch information
mjoerussell committed Jan 2, 2025
1 parent 5ef9fd4 commit 049dd40
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ impl Helper {
}

fn try_select(&mut self, target_label: EdgeLabel) -> Option<Node> {
let (label, node) = self.current()?;
let edge = self.current()?;

if label == target_label {
if edge.label == target_label {
self.index += 1;
Some(node.clone())
Some(edge.node)
} else {
None
}
}

fn current(&mut self) -> Option<(EdgeLabel, Node)> {
fn current(&mut self) -> Option<Edge> {
loop {
let Edge { label, node } = self.node.children.get(self.index)?;
let edge = self.node.children.get(self.index)?;

match label {
match edge.label {
// Skip root nodes:
| EdgeLabel::Root
// Skip trivia:
Expand All @@ -170,17 +170,17 @@ impl Helper {
continue;
}
// Otherwise, return the edge:
other_label => {
return Some((*other_label, node.clone()));
_ => {
return Some(edge.clone());
}
}
}
}

fn finalize(mut self) -> Result<()> {
match self.current() {
Some((label, _)) => {
Err(format!("Unrecognized child with label '{label}'. Creating AST types from incorrect/incomplete CST nodes is not supported yet."))
Some(edge) => {
Err(format!("Unrecognized child with label '{label}'. Creating AST types from incorrect/incomplete CST nodes is not supported yet.", label = edge.label))
}
None => {
Ok(())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 049dd40

Please sign in to comment.