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
a33838c1
Commit
a33838c1
authored
Feb 10, 2019
by
eckhart
Browse files
- DHParser/parse.py MetaParser._return_values(): flatten anonymous nodes already while parsing
parent
cd0e4a9e
Changes
3
Hide whitespace changes
Inline
Side-by-side
CHANGES.txt
View file @
a33838c1
DHParser Version 0.8.5 (DATE?)
..............................
-
pending
optimization: flattens anonymous nodes already while parsing
- optimization: flattens anonymous nodes already while parsing
- optimization: drops empty anonymous nodes already during parsing
- optimization: optionally allows to drop anonymous whitespace and tokens
while parsing
...
...
DHParser/parse.py
View file @
a33838c1
...
...
@@ -1247,6 +1247,7 @@ class DropWhitespace(Whitespace):
class
MetaParser
(
Parser
):
# TODO: Allow to turn optimization off
def
_return_value
(
self
,
node
:
Optional
[
Node
])
->
Node
:
# Node(self.tag_name, node) # unoptimized code
...
...
@@ -1267,9 +1268,14 @@ class MetaParser(Parser):
# return Node(self.tag_name, results) # unoptimized code
assert
isinstance
(
results
,
tuple
)
N
=
len
(
results
)
# TODO: if N >= 2, flatten results!
if
N
>
1
:
return
Node
(
self
.
tag_name
,
results
)
nr
=
[]
for
child
in
results
:
if
child
.
children
and
child
.
tag_name
[
0
]
==
':'
:
# faster than c.is_anonymous():
nr
.
extend
(
child
.
children
)
else
:
nr
.
append
(
child
)
return
Node
(
self
.
tag_name
,
tuple
(
nr
))
elif
N
==
1
:
return
self
.
_return_value
(
results
[
0
])
elif
self
.
pname
:
...
...
test/test_toolkit.py
View file @
a33838c1
...
...
@@ -99,8 +99,8 @@ class TestLoggingAndLoading:
except
AttributeError
:
pass
with
logging
(
"TESTLOGS"
):
assert
not
os
.
path
.
exists
(
"TEST
S
LOGS"
),
\
"Log dir should
not
be created
before first use
!"
assert
os
.
path
.
exists
(
"TESTLOGS"
),
\
"Log dir should be created
if it does not exist
!"
dirname
=
log_dir
()
assert
dirname
==
"TESTLOGS"
assert
is_logging
(),
"is_logging() should return True, if logging is on"
...
...
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