0 | module Language.XML.Attribute
3 | import Data.String.Parser
5 | import public Language.XML.Name
8 | record Attribute where
9 | constructor MkAttribute
13 | %name Attribute
attr
16 | lookup : (name : QName) -> List Attribute -> Maybe String
17 | lookup name attrs = lookup name $
map (\attr => (attr.name, attr.value)) attrs
20 | Show Attribute where
21 | show attr = "\{show attr.name}=\{show attr.value}"
24 | quotedString : Parser String
26 | quote <- satisfy (\c => c == '"' || c == '\'')
27 | content <- map pack $
many $
satisfy (/= quote)
32 | attribute : Parser Attribute
38 | value <- quotedString
39 | pure $
MkAttribute name value
40 | ) <?> "XML attribute"
43 | exactAttribute : QName -> Parser String
44 | exactAttribute expectedName = do
45 | MkAttribute name value <- attribute
46 | if name == expectedName
48 | else fail "Unexpected attribute: \{show name}"