aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/parser/xml.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/control/parser/xml.lux')
-rw-r--r--stdlib/source/lux/control/parser/xml.lux58
1 files changed, 34 insertions, 24 deletions
diff --git a/stdlib/source/lux/control/parser/xml.lux b/stdlib/source/lux/control/parser/xml.lux
index da21c1dfb..f734a2684 100644
--- a/stdlib/source/lux/control/parser/xml.lux
+++ b/stdlib/source/lux/control/parser/xml.lux
@@ -7,7 +7,8 @@
["." exception (#+ exception:)]]
[data
["." name ("#@." equivalence codec)]
- ["." text ("#@." monoid)]
+ ["." text
+ ["%" format (#+ format)]]
[collection
["." list ("#@." functor)]
["." dictionary]]
@@ -20,13 +21,22 @@
(exception: #export empty-input)
(exception: #export unexpected-input)
-(exception: #export unknown-attribute)
-(exception: #export (wrong-tag {tag Name})
- (exception.report
- ["Tag" (name@encode tag)]))
+(def: (label [namespace name])
+ (-> Name Text)
+ (format namespace ":" name))
-(def: blank-line ($_ text@compose text.new-line text.new-line))
+(template [<exception> <header>]
+ [(exception: #export (<exception> {label Name})
+ (exception.report
+ [<header> (%.text (..label label))]))]
+
+ [wrong-tag "Tag"]
+ [unknown-attribute "Attribute"]
+ )
+
+(def: blank-line
+ (format text.new-line text.new-line))
(exception: #export (unconsumed-inputs {inputs (List XML)})
(|> inputs
@@ -48,6 +58,23 @@
(#/.Node _)
(exception.throw ..unexpected-input [])))))
+(def: #export (node tag)
+ (-> Name (Parser Any))
+ (function (_ docs)
+ (case docs
+ #.Nil
+ (exception.throw ..empty-input [])
+
+ (#.Cons head _)
+ (case head
+ (#/.Text _)
+ (exception.throw ..unexpected-input [])
+
+ (#/.Node _tag _attrs _children)
+ (if (name@= tag _tag)
+ (#try.Success [docs []])
+ (exception.throw ..wrong-tag tag))))))
+
(def: #export (attr name)
(-> Name (Parser Text))
(function (_ docs)
@@ -63,7 +90,7 @@
(#/.Node tag attrs children)
(case (dictionary.get name attrs)
#.None
- (exception.throw ..unknown-attribute [])
+ (exception.throw ..unknown-attribute [name])
(#.Some value)
(#try.Success [docs value]))))))
@@ -79,23 +106,6 @@
(#try.Failure error)
(#try.Failure error)))
-(def: #export (node tag)
- (-> Name (Parser Any))
- (function (_ docs)
- (case docs
- #.Nil
- (exception.throw ..empty-input [])
-
- (#.Cons head _)
- (case head
- (#/.Text _)
- (exception.throw ..unexpected-input [])
-
- (#/.Node _tag _attrs _children)
- (if (name@= tag _tag)
- (#try.Success [docs []])
- (exception.throw ..wrong-tag tag))))))
-
(def: #export (children reader)
(All [a] (-> (Parser a) (Parser a)))
(function (_ docs)