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
8863780a
Commit
8863780a
authored
Jul 27, 2021
by
Eckhart Arnold
Browse files
some refactoring
parent
20dd34fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
DHParser/compile.py
View file @
8863780a
...
...
@@ -348,7 +348,8 @@ def compile_source(source: str,
ast
=
None
# type: Optional[Node]
original_text
=
load_if_file
(
source
)
# type: str
source_name
=
source
if
is_filename
(
source
)
else
'source'
compiler
.
source
=
original_text
if
isinstance
(
compiler
,
Compiler
):
compiler
.
source
=
original_text
log_file_name
=
logfile_basename
(
source
,
compiler
)
if
is_logging
()
else
''
# type: str
if
not
hasattr
(
parser
,
'free_char_parsefunc__'
)
or
parser
.
history_tracking__
:
# log only for custom parser/transformer/compilers
...
...
@@ -460,10 +461,8 @@ class TreeProcessor(Compiler):
assert
result
is
None
or
isinstance
(
result
,
RootNode
),
str
(
result
)
return
result
TreeProcessorCallable
=
Union
[
TreeProcessor
,
Callable
[[
RootNode
],
RootNode
],
functools
.
partial
]
def
process_tree
(
tp
:
TreeProcessorCallable
,
tree
:
RootNode
)
->
Tuple
[
RootNode
,
List
[
Error
]]:
def
process_tree
(
tp
:
TransformerCallable
,
tree
:
RootNode
):
"""Process a tree with the tree-processor `tp` only if no fatal error
has occurred so far. Catch any Python-exceptions in case
any normal errors have occurred earlier in the processing pipeline.
...
...
@@ -510,7 +509,6 @@ def process_tree(tp: TreeProcessorCallable, tree: RootNode) -> Tuple[RootNode, L
new_msgs
=
[
msg
for
msg
in
messages
if
msg
.
line
<
0
]
# Obsolete, because RootNode adjusts error locations whenever an error is added:
# adjust_error_locations(new_msgs, tree.source, tree.source_mapping)
return
tree
,
messages
...
...
DHParser/syntaxtree.py
View file @
8863780a
...
...
@@ -2276,7 +2276,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
text
.
append
(
children
[
i
].
content
)
i
+=
1
if
text
:
element
.
text
=
''
.
join
(
text
)
l
e
st_element
=
None
l
a
st_element
=
None
while
i
<
L
:
while
i
<
L
and
children
[
i
].
tag_name
not
in
string_tags
:
last_element
=
children
[
i
].
as_etree
(
ET
,
string_tags
,
empty_tags
)
...
...
@@ -2287,7 +2287,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
assert
not
children
[
i
].
children
text
.
append
(
children
[
i
].
content
)
i
+=
1
if
text
:
last_element
.
tail
=
''
.
join
(
text
)
if
text
and
last_element
is
not
None
:
last_element
.
tail
=
''
.
join
(
text
)
else
:
element
=
ET
.
Element
(
tag_name
,
attrib
=
attributes
)
if
tag_name
in
empty_tags
:
...
...
DHParser/transform.py
View file @
8863780a
...
...
@@ -151,7 +151,7 @@ ProcessingTableType = Dict[str, Union[Sequence[Callable], TransformationDict]]
ConditionFunc
=
Callable
# Callable[[TreeContext], bool]
KeyFunc
=
Callable
[[
Node
],
str
]
CriteriaType
=
Union
[
int
,
str
,
Callable
]
TransformerCallable
=
Union
[
Callable
[[
Node
],
None
],
partial
]
TransformerCallable
=
Union
[
Callable
[[
Root
Node
],
None
],
partial
]
def
transformation_factory
(
t1
=
None
,
t2
=
None
,
t3
=
None
,
t4
=
None
,
t5
=
None
):
...
...
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