Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
badw-it
DHParser
Commits
a9354ef2
Commit
a9354ef2
authored
Mar 07, 2018
by
eckhart
Browse files
- transform.py: added remove_anonymous_tokens
parent
f00dd967
Changes
1
Hide whitespace changes
Inline
Side-by-side
DHParser/transform.py
View file @
a9354ef2
...
...
@@ -382,8 +382,7 @@ def is_token(context: List[Node], tokens: AbstractSet[str] = frozenset()) -> boo
return
""
.
join
(
child
.
content
for
child
in
node
.
children
[
i
:
k
])
return
nd
.
content
node
=
context
[
-
1
]
return
(
node
.
parser
.
ptype
==
TOKEN_PTYPE
and
(
not
tokens
or
stripped
(
node
)
in
tokens
))
return
node
.
parser
.
ptype
==
TOKEN_PTYPE
and
(
not
tokens
or
stripped
(
node
)
in
tokens
)
@
transformation_factory
(
AbstractSet
[
str
])
...
...
@@ -755,6 +754,7 @@ remove_expendables = remove_children_if(is_expendable)
# partial(remove_children_if, condition=is_expendable)
remove_anonymous_expendables
=
remove_children_if
(
lambda
ctx
:
is_anonymous
(
ctx
)
and
is_expendable
(
ctx
))
remove_anonymous_tokens
=
remove_children_if
(
lambda
ctx
:
is_token
(
ctx
)
and
is_anonymous
(
ctx
))
remove_first
=
apply_if
(
keep_children
(
slice
(
1
,
None
)),
lambda
ctx
:
len
(
ctx
[
-
1
].
children
)
>
1
)
remove_last
=
apply_if
(
keep_children
(
slice
(
None
,
-
1
)),
lambda
ctx
:
len
(
ctx
[
-
1
].
children
)
>
1
)
remove_brackets
=
apply_if
(
keep_children
(
slice
(
1
,
-
1
)),
lambda
ctx
:
len
(
ctx
[
-
1
].
children
)
>=
2
)
...
...
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