Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
d1adc0ce
Commit
d1adc0ce
authored
Oct 23, 2018
by
di68kap
Browse files
Merge remote-tracking branch 'origin/development' into development
parents
393a5e2c
2c9ea16d
Changes
1
Hide whitespace changes
Inline
Side-by-side
DHParser/syntaxtree.py
View file @
d1adc0ce
...
...
@@ -665,7 +665,8 @@ class Node(collections.abc.Sized):
density
=
1
,
inline_fn
=
inlining
)
def
select
(
self
,
match_function
:
Callable
,
include_root
:
bool
=
False
)
->
Iterator
[
'Node'
]:
def
select
(
self
,
match_function
:
Callable
,
include_root
:
bool
=
False
,
reverse
:
bool
=
False
)
\
->
Iterator
[
'Node'
]:
"""
Finds nodes in the tree that fulfill a given criterion.
...
...
@@ -680,14 +681,17 @@ class Node(collections.abc.Sized):
object as argument and returns True or False
include_root (bool): If False, only descendant nodes will be
checked for a match.
reverse (bool): If True, the tree will be walked in reverse
order, i.e. last children first.
Yields:
Node: All nodes of the tree for which
``match_function(node)`` returns True
"""
if
include_root
and
match_function
(
self
):
yield
self
for
child
in
self
.
children
:
for
node
in
child
.
select
(
match_function
,
True
):
child_iterator
=
reversed
(
self
.
children
)
if
reverse
else
self
.
children
for
child
in
child_iterator
:
for
node
in
child
.
select
(
match_function
,
True
,
reverse
):
yield
node
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment