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 ...@@ -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 from a certain node, it is a waste to transform all the child nodes
first. 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 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 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 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, \\ ...@@ -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, \\ reduce_single_child, replace_by_single_child, replace_or_reduce, remove_whitespace, \\
remove_expendables, remove_empty, remove_tokens, flatten, is_whitespace, \\ remove_expendables, remove_empty, remove_tokens, flatten, is_whitespace, \\
is_empty, is_expendable, collapse, replace_content, WHITESPACE_PTYPE, TOKEN_PTYPE, \\ 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, \\ keep_children, is_one_of, has_content, apply_if, remove_first, remove_last, \\
remove_anonymous_empty, keep_nodes, traverse_locally, strip, lstrip, rstrip remove_anonymous_empty, keep_nodes, traverse_locally, strip, lstrip, rstrip
'''.format(dhparserdir=dhparserdir) '''.format(dhparserdir=dhparserdir)
......
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
####################################################################### #######################################################################
document = prolog element [Misc] EOF document = prolog element [Misc] EOF
prolog = [ XMLDecl ] [Misc] [doctypedecl [Misc]] prolog = [ ~ XMLDecl ] [Misc] [doctypedecl [Misc]]
XMLDecl = '<?xml' VersionInfo [EncodingDecl] [SDDecl] ~ '?>' XMLDecl = '<?xml' VersionInfo [EncodingDecl] [SDDecl] ~ '?>'
VersionInfo = ~ 'version' ~ '=' ~ ("'" VersionNum "'" | '"' VersionNum '"') VersionInfo = ~ 'version' ~ '=' ~ ("'" VersionNum "'" | '"' VersionNum '"')
VersionNum = '1.' /[0-9]+/ VersionNum = /[0-9]+\.[0-9]+/
EncodingDecl = ~ 'encoding' ~ '=' ~ ("'" EncName "'" | '"' EncName '"') EncodingDecl = ~ 'encoding' ~ '=' ~ ("'" EncName "'" | '"' EncName '"')
EncName = /[A-Za-z][A-Za-z0-9._\-]*/ EncName = /[A-Za-z][A-Za-z0-9._\-]*/
...@@ -108,11 +108,11 @@ NDataDecl = 'NData' §S Name ...@@ -108,11 +108,11 @@ NDataDecl = 'NData' §S Name
# #
####################################################################### #######################################################################
element = EmptyElemTag | STag §content ETag element = emptyElement | STag §content ETag
STag = '<' TagName { ~ Attribute } ~ '>' STag = '<' TagName { ~ Attribute } ~ '>'
ETag = '</' §::TagName ~ '>' ETag = '</' §::TagName ~ '>'
EmptyElemTag = '<' Name { ~ Attribute } ~ '/>' emptyElement = '<' Name { ~ Attribute } ~ '/>'
TagName = Name TagName = Name
Attribute = Name ~ §'=' ~ AttValue Attribute = Name ~ §'=' ~ AttValue
...@@ -128,10 +128,10 @@ content = [ CharData ] ...@@ -128,10 +128,10 @@ content = [ CharData ]
# #
####################################################################### #######################################################################
EntityValue = '"' { /[^%&"]/ | PEReference | Reference } '"' EntityValue = '"' { /[^%&"]+/ | PEReference | Reference } '"'
| "'" { /[^%&']/ | PEReference | Reference } "'" | "'" { /[^%&']+/ | PEReference | Reference } "'"
AttValue = '"' { /[^<&"]/ | Reference } '"' AttValue = '"' { /[^<&"]+/ | Reference } '"'
| "'" { /[^<&']/ | Reference } "'" | "'" { /[^<&']+/ | Reference } "'"
SystemLiteral = '"' /[^"]*/ '"' | "'" /[^']*/ "'" SystemLiteral = '"' /[^"]*/ '"' | "'" /[^']*/ "'"
PubidLiteral = '"' [PubidChars] '"' PubidLiteral = '"' [PubidChars] '"'
| "'" [PubidCharsSingleQuoted] "'" | "'" [PubidCharsSingleQuoted] "'"
......
[match:document] [match:document]
M1: """ M1*: """
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<note> <note>
<to>Tove</to> <to>Tove</to>
<from>Jani</from> <from>Jani</from>
<heading>Reminder</heading> <heading>Reminder</heading>
<body>Don't forget me this weekend!</body> <body>Don't forget me this weekend!</body>
<priority level="high" />
<remark></remark>
</note> </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