Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
d3bda00e
Commit
d3bda00e
authored
Jun 02, 2018
by
eckhart
Browse files
- XML-parser-example: AST Transformations added/extended
parent
9507e47e
Changes
4
Hide whitespace changes
Inline
Side-by-side
CONTRIBUTING.md
View file @
d3bda00e
...
...
@@ -76,7 +76,7 @@ For example if you know you are going to discard a whole branch starting
from a certain node, it is a waste to transform all the child nodes
first.
As the tree is traversed anyway, there no good reason why certain
As the tree is traversed anyway, there
is
no good reason why certain
transformation routines should not already be called on the way up. Of
course, as most routines more or less assume depth first, we would need
two transformation tables one for the routines that are called on the
...
...
DHParser/dsl.py
View file @
d3bda00e
...
...
@@ -97,7 +97,7 @@ from DHParser import logging, is_filename, load_if_file, \\
reduce_single_child, replace_by_single_child, replace_or_reduce, remove_whitespace,
\\
remove_expendables, remove_empty, remove_tokens, flatten, is_whitespace,
\\
is_empty, is_expendable, collapse, replace_content, WHITESPACE_PTYPE, TOKEN_PTYPE,
\\
remove_nodes, remove_content, remove_brackets, replace_parser,
\\
remove_nodes, remove_content, remove_brackets, replace_parser,
remove_anonymous_tokens,
\\
keep_children, is_one_of, has_content, apply_if, remove_first, remove_last,
\\
remove_anonymous_empty, keep_nodes, traverse_locally, strip, lstrip, rstrip
'''
.
format
(
dhparserdir
=
dhparserdir
)
...
...
examples/XML/XML.ebnf
View file @
d3bda00e
...
...
@@ -19,11 +19,11 @@
#######################################################################
document = prolog element [Misc] EOF
prolog = [ XMLDecl ] [Misc] [doctypedecl [Misc]]
prolog = [
~
XMLDecl ] [Misc] [doctypedecl [Misc]]
XMLDecl = '<?xml' VersionInfo [EncodingDecl] [SDDecl] ~ '?>'
VersionInfo = ~ 'version' ~ '=' ~ ("'" VersionNum "'" | '"' VersionNum '"')
VersionNum =
'1.' /
[0-9]+/
VersionNum =
/[0-9]+\.
[0-9]+/
EncodingDecl = ~ 'encoding' ~ '=' ~ ("'" EncName "'" | '"' EncName '"')
EncName = /[A-Za-z][A-Za-z0-9._\-]*/
...
...
@@ -108,11 +108,11 @@ NDataDecl = 'NData' §S Name
#
#######################################################################
element =
E
mptyElem
Tag
| STag §content ETag
element =
e
mptyElem
ent
| STag §content ETag
STag = '<' TagName { ~ Attribute } ~ '>'
ETag = '</' §::TagName ~ '>'
E
mptyElem
Tag
= '<' Name { ~ Attribute } ~ '/>'
e
mptyElem
ent
= '<' Name { ~ Attribute } ~ '/>'
TagName = Name
Attribute = Name ~ §'=' ~ AttValue
...
...
@@ -128,10 +128,10 @@ content = [ CharData ]
#
#######################################################################
EntityValue = '"' { /[^%&"]/ | PEReference | Reference } '"'
| "'" { /[^%&']/ | PEReference | Reference } "'"
AttValue = '"' { /[^<&"]/ | Reference } '"'
| "'" { /[^<&']/ | Reference } "'"
EntityValue = '"' { /[^%&"]
+
/ | PEReference | Reference } '"'
| "'" { /[^%&']
+
/ | PEReference | Reference } "'"
AttValue = '"' { /[^<&"]
+
/ | Reference } '"'
| "'" { /[^<&']
+
/ | Reference } "'"
SystemLiteral = '"' /[^"]*/ '"' | "'" /[^']*/ "'"
PubidLiteral = '"' [PubidChars] '"'
| "'" [PubidCharsSingleQuoted] "'"
...
...
examples/XML/grammar_tests/99_test_document.ini
View file @
d3bda00e
[match:document]
M1:
"""
M1
*
:
"""
<?xml
version
=
"1.0"
encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't
forget
me
this
weekend!</body>
<priority
level
=
"high"
/>
<remark></remark>
</note>
"""
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