(.using [library [lux (.except) [abstract [equivalence (.only Equivalence)] [monad (.only do)]] [control ["[0]" exception (.only exception:)] ["<>" parser (.only) ["<[0]>" xml (.only Parser)] ["<[0]>" text]]] [data ["[0]" product] ["[0]" text (.only) ["%" format]] [format ["[0]" xml (.only XML)]] [collection ["[0]" list (.open: "[1]#[0]" functor)]]] [math [number ["n" nat]]] ["[0]" time (.only Time) ["[0]" date (.only Date)] ["[0]" year] ["[0]" month]]]] ["[0]" // ["[1][0]" time] ["[1][0]" snapshot (.only Snapshot) ["[1]/[0]" version (.only Version)]]]) (type: .public Versioning (Record [#snapshot Snapshot #last_updated //time.Time #versions (List Version)])) (def: .public init [#snapshot {//snapshot.#Local} #last_updated //time.epoch #versions (list)]) (def: .public equivalence (Equivalence Versioning) (all product.equivalence //snapshot.equivalence //time.equivalence (list.equivalence //snapshot/version.equivalence) )) (template [ ] [(def: xml.Tag ["" ])] [ "lastUpdated"] [ "snapshotVersions"] [ "versioning"] ) (def: last_updated_format (-> //time.Time XML) (|>> //time.format {xml.#Text} list {xml.#Node .. xml.attributes})) (def: .public (format (open "_[0]")) (-> Versioning XML) (<| {xml.#Node .. xml.attributes} (list (//snapshot.format _#snapshot) (..last_updated_format _#last_updated) (|> _#versions (list#each //snapshot/version.format) {xml.#Node .. xml.attributes})))) (def: (text tag) (-> xml.Tag (Parser Text)) (<| (.node tag) .text)) (def: last_updated_parser (Parser //time.Time) (<| (.then //time.parser) (..text ..))) (def: .public parser (Parser Versioning) (<| (.node ..) (all <>.and (<>.else {//snapshot.#Local} (.somewhere //snapshot.parser)) (<>.else //time.epoch (.somewhere ..last_updated_parser)) (<| (<>.else (list)) .somewhere (.node ..) (<>.some //snapshot/version.parser)) )))