Skip to content

Commit

Permalink
Fix bug, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
makukha committed Sep 12, 2024
1 parent 979f6e2 commit 01c4f42
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lark/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,15 @@ 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 find_token(self, token_type: str) -> Iterator[_Leaf_T]:
"""Returns all tokens whose type equals the given token_type.
This is a recursive function that will find tokens in all the subtrees.
Example:
>>> term_tokens = tree.find_token('TERM')
"""
return self.scan_values(lambda v: not isinstance(v, Tree) and v.type == token_type)

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

0 comments on commit 01c4f42

Please sign in to comment.