Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
DHParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
badw-it
DHParser
Commits
afda6166
Commit
afda6166
authored
Apr 25, 2019
by
di68kap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- syntaxtree.py: added Node.index()-method
parent
abb212a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
DHParser/syntaxtree.py
DHParser/syntaxtree.py
+1
-0
test/test_syntaxtree.py
test/test_syntaxtree.py
+11
-0
No files found.
DHParser/syntaxtree.py
View file @
afda6166
...
...
@@ -505,6 +505,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
if
child
.
tag_name
==
tag_name
:
return
i
i
+=
1
raise
ValueError
(
"Node with tag name '%s' not among child-nodes."
%
tag_name
)
def
select
(
self
,
match_function
:
Callable
,
include_root
:
bool
=
False
,
reverse
:
bool
=
False
)
\
->
Iterator
[
'Node'
]:
...
...
test/test_syntaxtree.py
View file @
afda6166
...
...
@@ -317,6 +317,17 @@ class TestNodeFind():
assert
'c'
not
in
tree
assert
any
(
tree
.
select_by_tag
(
'c'
,
False
))
def
test_index
(
self
):
tree
=
parse_sxpr
(
'(a (b 0) (c 1) (d 2))'
)
assert
tree
.
index
(
'd'
)
==
2
assert
tree
.
index
(
'b'
)
==
0
assert
tree
.
index
(
'c'
)
==
1
try
:
i
=
tree
.
index
(
'x'
)
raise
AssertionError
(
'ValueError expected!'
)
except
ValueError
:
pass
class
TestSerialization
:
def
test_sxpr_roundtrip
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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