Skip to content

Commit

Permalink
Add Tree.find_token() method
Browse files Browse the repository at this point in the history
  • Loading branch information
makukha committed Sep 11, 2024
1 parent 5faea92 commit bd40098
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lark/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def find_data(self, data: str) -> 'Iterator[Tree[_Leaf_T]]':

###}

def find_token(self, typ: str) -> Iterator[_Leaf_T]:
"""Returns all tokens whose type equals the given typ."""
return self.scan_values(lambda v: isinstance(v, Token) and v.type == typ)

def expand_kids_by_data(self, *data_values):
"""Expand (inline) children with any of the given data values. Returns True if anything changed"""
changed = False
Expand Down

0 comments on commit bd40098

Please sign in to comment.