Commit d3bda00e authored by eckhart's avatar eckhart
Browse files

- XML-parser-example: AST Transformations added/extended

parent 9507e47e
......@@ -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
......
......@@ -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)
......
......@@ -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 = EmptyElemTag | STag §content ETag
element = emptyElement | STag §content ETag
STag = '<' TagName { ~ Attribute } ~ '>'
ETag = '</' §::TagName ~ '>'
EmptyElemTag = '<' Name { ~ Attribute } ~ '/>'
emptyElement = '<' 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] "'"
......
[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>
"""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment