Skip to content

Commit

Permalink
WIP: Try to simplify the existing Cursor helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Oct 28, 2023
1 parent 6ff92c2 commit 8156cec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 72 deletions.
29 changes: 5 additions & 24 deletions crates/codegen/parser/runtime/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,31 +369,19 @@ impl Cursor {
}

pub fn find_token_with_kind(&mut self, kinds: &[TokenKind]) -> Option<Rc<TokenNode>> {
while !self.is_completed {
if let Some(token_node) = self.current.node.as_token_with_kind(kinds).cloned() {
return Some(token_node);
}
self.go_to_next();
}

None
self.find_map(|node| node.as_token_with_kind(kinds).cloned())
}

pub fn find_token_matching<F: Fn(&Rc<TokenNode>) -> bool>(
&mut self,
predicate: F,
) -> Option<Rc<TokenNode>> {
while !self.is_completed {
if let Some(token_node) = self.current.node.as_token_matching(&predicate) {
return Some(token_node.clone());
}
self.go_to_next();
}

None
self.find_map(|node| node.as_token_matching(&predicate).cloned())
}

pub fn find_rule_with_kind(&mut self, kinds: &[RuleKind]) -> Option<Rc<RuleNode>> {
// TODO: It doesn't seem to work the same way?
// self.find_map(|node| node.as_rule_with_kind(kinds).cloned())
while !self.is_completed {
if let Some(rule_node) = self.current.node.as_rule_with_kind(kinds) {
return Some(rule_node.clone());
Expand All @@ -408,13 +396,6 @@ impl Cursor {
&mut self,
predicate: F,
) -> Option<Rc<RuleNode>> {
while !self.is_completed {
if let Some(rule_node) = self.current.node.as_rule_matching(&predicate) {
return Some(rule_node.clone());
}
self.go_to_next();
}

None
self.find_map(|node| node.as_rule_matching(&predicate).cloned())
}
}
29 changes: 5 additions & 24 deletions crates/solidity/outputs/cargo/crate/src/generated/cursor.rs

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

29 changes: 5 additions & 24 deletions crates/solidity/outputs/npm/crate/src/generated/cursor.rs

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

0 comments on commit 8156cec

Please sign in to comment.