Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
630efad5
Commit
630efad5
authored
Dec 19, 2017
by
eckhart
Browse files
- transformation.py: doc strings adjusted
parent
48920684
Changes
1
Show whitespace changes
Inline
Side-by-side
DHParser/transform.py
View file @
630efad5
...
...
@@ -311,7 +311,7 @@ def single_child(context: List[Node]) -> bool:
@
transformation_factory
(
int
,
str
,
Callable
)
def
replace_by_child
(
context
:
List
[
Node
],
criteria
:
CriteriaType
=
single_child
):
"""
Replace a node by the first of its immediate descendants
Replace
s
a node by the first of its immediate descendants
that meets the `criteria`. The criteria can either be the
index of the child (counting from zero), or the tag name or
a boolean-valued function on the context of the child.
...
...
@@ -328,7 +328,7 @@ def replace_by_child(context: List[Node], criteria: CriteriaType=single_child):
@
transformation_factory
(
int
,
str
,
Callable
)
def
content_from_child
(
context
:
List
[
None
],
criteria
:
CriteriaType
=
single_child
):
"""
Reduce a node, by transferring the result of the first of its
Reduce
s
a node, by transferring the result of the first of its
immediate descendants that meets the `criteria` to this node,
but keeping this node's parser entry. The criteria can either
be the index of the child (counting from zero), or the tag
...
...
@@ -346,8 +346,9 @@ def content_from_child(context: List[None], criteria: CriteriaType=single_child)
def
replace_by_single_child
(
context
:
List
[
Node
]):
"""
Remove single branch node, replacing it by its immediate descendant.
If there are more than one children, no replacement takes place.
Removes single branch node, replacing it by its immediate descendant.
Replacement only takes place, if the last node in the context has
exactly one child.
"""
node
=
context
[
-
1
]
if
len
(
node
.
children
)
==
1
:
...
...
@@ -356,10 +357,10 @@ def replace_by_single_child(context: List[Node]):
def
content_from_sinlge_child
(
context
:
List
[
Node
]):
"""
Reduce a single branch node by transferring the result of its
Reduce
s
a single branch node by transferring the result of its
immediate descendant to this node, but keeping this node's parser entry.
This will only be don
e if the last node in the context has
is exactly
one child.
Reduction only takes plac
e if the last node in the context has
exactly
one child.
"""
node
=
context
[
-
1
]
if
len
(
node
.
children
)
==
1
:
...
...
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