aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/data/format/xml.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/data/format/xml.lux')
-rw-r--r--stdlib/source/library/lux/data/format/xml.lux126
1 files changed, 63 insertions, 63 deletions
diff --git a/stdlib/source/library/lux/data/format/xml.lux b/stdlib/source/library/lux/data/format/xml.lux
index dfab48227..ff08ad834 100644
--- a/stdlib/source/library/lux/data/format/xml.lux
+++ b/stdlib/source/library/lux/data/format/xml.lux
@@ -232,68 +232,68 @@
" encoding=" (quote "UTF-8")
"?>")))
-(implementation: .public codec
+(def: .public codec
(Codec Text XML)
-
- (def: encoded
- (let [attributes (is (-> Attrs Text)
- (function (_ attrs)
- (|> attrs
- dictionary.entries
- (list#each (function (_ [key value])
- (all text#composite (..attribute key) "=" text.double_quote (sanitize_value value) text.double_quote)))
- (text.interposed " "))))]
- (function (_ input)
- (all text#composite
- ..xml_header text.new_line
- (loop (again [prefix ""
- input input])
- (case input
- {#Text value}
- (sanitize_value value)
-
- (pattern {#Node xml_tag xml_attrs (list {#Text value})})
- (let [tag (..tag xml_tag)
- attrs (if (dictionary.empty? xml_attrs)
- ""
- (all text#composite " " (attributes xml_attrs)))]
- (all text#composite
- prefix "<" tag attrs ">"
- (sanitize_value value)
- "</" tag ">"))
-
- {#Node xml_tag xml_attrs xml_children}
- (let [tag (..tag xml_tag)
- attrs (if (dictionary.empty? xml_attrs)
- ""
- (all text#composite " " (attributes xml_attrs)))]
- (if (list.empty? xml_children)
- (all text#composite prefix "<" tag attrs "/>")
- (all text#composite prefix "<" tag attrs ">"
- (|> xml_children
- (list#each (|>> (again (text#composite prefix text.tab)) (text#composite text.new_line)))
- text.together)
- text.new_line prefix "</" tag ">")))))
- ))))
- (def: decoded
- (<text>.result ..xml^)))
-
-(implementation: .public equivalence
+ (implementation
+ (def: encoded
+ (let [attributes (is (-> Attrs Text)
+ (function (_ attrs)
+ (|> attrs
+ dictionary.entries
+ (list#each (function (_ [key value])
+ (all text#composite (..attribute key) "=" text.double_quote (sanitize_value value) text.double_quote)))
+ (text.interposed " "))))]
+ (function (_ input)
+ (all text#composite
+ ..xml_header text.new_line
+ (loop (again [prefix ""
+ input input])
+ (case input
+ {#Text value}
+ (sanitize_value value)
+
+ (pattern {#Node xml_tag xml_attrs (list {#Text value})})
+ (let [tag (..tag xml_tag)
+ attrs (if (dictionary.empty? xml_attrs)
+ ""
+ (all text#composite " " (attributes xml_attrs)))]
+ (all text#composite
+ prefix "<" tag attrs ">"
+ (sanitize_value value)
+ "</" tag ">"))
+
+ {#Node xml_tag xml_attrs xml_children}
+ (let [tag (..tag xml_tag)
+ attrs (if (dictionary.empty? xml_attrs)
+ ""
+ (all text#composite " " (attributes xml_attrs)))]
+ (if (list.empty? xml_children)
+ (all text#composite prefix "<" tag attrs "/>")
+ (all text#composite prefix "<" tag attrs ">"
+ (|> xml_children
+ (list#each (|>> (again (text#composite prefix text.tab)) (text#composite text.new_line)))
+ text.together)
+ text.new_line prefix "</" tag ">")))))
+ ))))
+ (def: decoded
+ (<text>.result ..xml^))))
+
+(def: .public equivalence
(Equivalence XML)
-
- (def: (= reference sample)
- (case [reference sample]
- [{#Text reference/value} {#Text sample/value}]
- (text#= reference/value sample/value)
-
- [{#Node reference/tag reference/attrs reference/children}
- {#Node sample/tag sample/attrs sample/children}]
- (and (symbol#= reference/tag sample/tag)
- (at (dictionary.equivalence text.equivalence) = reference/attrs sample/attrs)
- (n.= (list.size reference/children)
- (list.size sample/children))
- (|> (list.zipped_2 reference/children sample/children)
- (list.every? (product.uncurried =))))
-
- _
- false)))
+ (implementation
+ (def: (= reference sample)
+ (case [reference sample]
+ [{#Text reference/value} {#Text sample/value}]
+ (text#= reference/value sample/value)
+
+ [{#Node reference/tag reference/attrs reference/children}
+ {#Node sample/tag sample/attrs sample/children}]
+ (and (symbol#= reference/tag sample/tag)
+ (at (dictionary.equivalence text.equivalence) = reference/attrs sample/attrs)
+ (n.= (list.size reference/children)
+ (list.size sample/children))
+ (|> (list.zipped_2 reference/children sample/children)
+ (list.every? (product.uncurried =))))
+
+ _
+ false))))