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
0b2dd583
Commit
0b2dd583
authored
May 03, 2019
by
Eckhart Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- compile.py - removed obsolete compile children method
parent
d43a732c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
13 deletions
+22
-13
DHParser/compile.py
DHParser/compile.py
+12
-12
examples/XML/XMLCompiler.py
examples/XML/XMLCompiler.py
+1
-1
examples/XML/example2.xml
examples/XML/example2.xml
+9
-0
No files found.
DHParser/compile.py
View file @
0b2dd583
...
...
@@ -131,23 +131,23 @@ class Compiler:
result
=
self
.
compile
(
root
)
return
result
def
compile_children
(
self
,
node
:
Node
)
->
StrictResultType
:
"""Compiles all children of the given node and returns the tuple
of the compiled children or the node's (potentially empty) result
in case the node does not have any children.
"""
if
node
.
children
:
return
tuple
(
self
.
compile
(
child
)
for
child
in
node
.
children
)
else
:
return
node
.
result
# Obsolete, because never used...
# def compile_children(self, node: Node) -> StrictResultType:
# """Compiles all children of the given node and returns the tuple
# of the compiled children or the node's (potentially empty) result
# in case the node does not have any children.
# """
# if node.children:
# return tuple(self.compile(child) for child in node.children)
# else:
# return node.result
def
fallback_compiler
(
self
,
node
:
Node
)
->
Any
:
"""This is a generic compiler function which will be called on
all those node types for which no compiler method `on_XXX` has
been defined."""
if
node
.
children
:
result
=
tuple
(
self
.
compile
(
nd
)
for
nd
in
node
.
children
)
node
.
result
=
result
node
.
result
=
tuple
(
self
.
compile
(
nd
)
for
nd
in
node
.
children
)
return
node
def
compile
(
self
,
node
:
Node
)
->
Any
:
...
...
@@ -253,7 +253,7 @@ def compile_source(source: str,
# which could (fatally) break AST transformations.
try
:
transformer
(
syntax_tree
)
except
Exc
pe
tion
as
e
:
except
Exc
ep
tion
as
e
:
syntax_tree
.
new_error
(
syntax_tree
,
"AST-Transformation failed due to earlier parser errors. "
"Crash Message: "
+
str
(
e
),
Error
.
AST_TRANSFORM_CRASH
)
...
...
examples/XML/XMLCompiler.py
View file @
0b2dd583
...
...
@@ -573,7 +573,7 @@ class XMLCompiler(Compiler):
node
.
attr
.
update
(
attributes
)
preserve_whitespace
|=
attributes
.
get
(
'xml:space'
,
''
)
==
'preserve'
node
.
tag_name
=
tag_name
content
=
self
.
compile_children
(
node
.
get
(
'content'
,
PLACEHOLDER
)
)
content
=
tuple
(
self
.
compile
(
nd
)
for
nd
in
node
.
get
(
'content'
,
PLACEHOLDER
).
children
)
if
len
(
content
)
==
1
:
if
content
[
0
].
tag_name
==
"CharData"
:
# reduce single CharData children
...
...
examples/XML/example2.xml
0 → 100644
View file @
0b2dd583
<?xml version="1.0" encoding="UTF-8"?>
<note
date=
"2018-06-14"
>
<to>
Tove
</to>
<from>
Jani
</from>
<heading>
Reminder
</heading>
<body>
Don't forget me this weekend!
</body>
<priority
level=
"high"
/>
Some Mixed Content...
</note>
\ No newline at end of file
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