From 2431e767a09894c2f685911ba7f1ba0b7de2a165 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 13 Jul 2021 02:41:45 -0400 Subject: Improved the XML parsing library. --- .../source/program/aedifex/artifact/snapshot.lux | 14 ++--- .../program/aedifex/artifact/snapshot/build.lux | 8 +-- .../program/aedifex/artifact/snapshot/stamp.lux | 7 +-- .../program/aedifex/artifact/snapshot/version.lux | 11 +--- .../source/program/aedifex/artifact/versioning.lux | 17 ++--- .../source/program/aedifex/metadata/artifact.lux | 18 ++---- .../source/program/aedifex/metadata/snapshot.lux | 11 +--- stdlib/source/program/aedifex/pom.lux | 73 +++++++++++----------- 8 files changed, 65 insertions(+), 94 deletions(-) (limited to 'stdlib/source/program') diff --git a/stdlib/source/program/aedifex/artifact/snapshot.lux b/stdlib/source/program/aedifex/artifact/snapshot.lux index 836365fed..89897316d 100644 --- a/stdlib/source/program/aedifex/artifact/snapshot.lux +++ b/stdlib/source/program/aedifex/artifact/snapshot.lux @@ -49,10 +49,9 @@ (def: local_copy_parser (Parser Any) - (do <>.monad - [_ (.node ..)] - (.children (.embed (.this ..local_copy_value) - .text)))) + (<| (.node ..) + (.embed (.this ..local_copy_value)) + .text)) (def: #export (format snapshot) (-> Snapshot XML) @@ -66,7 +65,6 @@ (def: #export parser (Parser Snapshot) - (do <>.monad - [_ (.node )] - (.children (<>.or ..local_copy_parser - /stamp.parser)))) + (<| (.node ) + (<>.or ..local_copy_parser + /stamp.parser))) diff --git a/stdlib/source/program/aedifex/artifact/snapshot/build.lux b/stdlib/source/program/aedifex/artifact/snapshot/build.lux index d9a8b729e..cd87c283e 100644 --- a/stdlib/source/program/aedifex/artifact/snapshot/build.lux +++ b/stdlib/source/program/aedifex/artifact/snapshot/build.lux @@ -36,8 +36,6 @@ (def: #export parser (Parser Build) - (do <>.monad - [_ (.node ..tag)] - (.embed (<>.codec nat.decimal - (.many .decimal)) - (.children .text)))) + (<| (.node ..tag) + (.embed (<>.codec nat.decimal (.many .decimal))) + .text)) diff --git a/stdlib/source/program/aedifex/artifact/snapshot/stamp.lux b/stdlib/source/program/aedifex/artifact/snapshot/stamp.lux index f321e11c1..2d127af21 100644 --- a/stdlib/source/program/aedifex/artifact/snapshot/stamp.lux +++ b/stdlib/source/program/aedifex/artifact/snapshot/stamp.lux @@ -44,10 +44,9 @@ (def: time_parser (Parser Time) - (do <>.monad - [_ (.node )] - (.embed //time.parser - (.children .text)))) + (<| (.node ) + (.embed //time.parser) + .text)) (def: #export parser (Parser Stamp) diff --git a/stdlib/source/program/aedifex/artifact/snapshot/version.lux b/stdlib/source/program/aedifex/artifact/snapshot/version.lux index 905523bd0..806d2b261 100644 --- a/stdlib/source/program/aedifex/artifact/snapshot/version.lux +++ b/stdlib/source/program/aedifex/artifact/snapshot/version.lux @@ -50,19 +50,14 @@ (..format_text .. value) (..format_text .. (///time.format updated))))) -(def: (sub tag parser) - (All [a] (-> xml.Tag (Parser a) (Parser a))) - (do <>.monad - [_ (.node tag)] - (.children parser))) - (def: (text tag) (-> xml.Tag (Parser Text)) - (..sub tag .text)) + (<| (.node tag) + .text)) (def: #export parser (Parser Version) - (<| (..sub ..) + (<| (.node ..) ($_ <>.and (.somewhere (..text ..)) (.somewhere (..text ..)) diff --git a/stdlib/source/program/aedifex/artifact/versioning.lux b/stdlib/source/program/aedifex/artifact/versioning.lux index a16d92796..be192e9a5 100644 --- a/stdlib/source/program/aedifex/artifact/versioning.lux +++ b/stdlib/source/program/aedifex/artifact/versioning.lux @@ -69,29 +69,24 @@ (list\map //snapshot/version.format) (#xml.Node .. xml.attributes))))) -(def: (sub tag parser) - (All [a] (-> xml.Tag (Parser a) (Parser a))) - (do <>.monad - [_ (.node tag)] - (.children parser))) - (def: (text tag) (-> xml.Tag (Parser Text)) - (..sub tag .text)) + (<| (.node tag) + .text)) (def: last_updated_parser (Parser //time.Time) - (.embed //time.parser - (..text ..))) + (<| (.embed //time.parser) + (..text ..))) (def: #export parser (Parser Versioning) - (<| (..sub ..) + (<| (.node ..) ($_ <>.and (<>.default #//snapshot.Local (.somewhere //snapshot.parser)) (<>.default //time.epoch (.somewhere ..last_updated_parser)) (<| (<>.default (list)) .somewhere - (..sub ..) + (.node ..) (<>.some //snapshot/version.parser)) ))) diff --git a/stdlib/source/program/aedifex/metadata/artifact.lux b/stdlib/source/program/aedifex/metadata/artifact.lux index 7150efbab..50f228e50 100644 --- a/stdlib/source/program/aedifex/metadata/artifact.lux +++ b/stdlib/source/program/aedifex/metadata/artifact.lux @@ -105,15 +105,10 @@ (list (..format_versions (get@ #versions value)) (..format_last_updated (get@ #last_updated value))))))) -(def: (sub tag parser) - (All [a] (-> xml.Tag (Parser a) (Parser a))) - (do <>.monad - [_ (.node tag)] - (.children parser))) - (def: (text tag) (-> xml.Tag (Parser Text)) - (..sub tag .text)) + (<| (.node tag) + .text)) (def: date_parser (.Parser Date) @@ -147,18 +142,17 @@ (def: #export parser (Parser Metadata) - (<| (..sub ..) + (<| (.node ..) ($_ <>.and (.somewhere (..text ..)) (.somewhere (..text ..)) - (<| (..sub ..) + (<| (.node ..) ($_ <>.and (<| .somewhere - (..sub ..) + (.node ..) (<>.many (..text ..))) (.somewhere ..last_updated_parser) - )) - ))) + ))))) (def: #export equivalence (Equivalence Metadata) diff --git a/stdlib/source/program/aedifex/metadata/snapshot.lux b/stdlib/source/program/aedifex/metadata/snapshot.lux index 518e0404a..41a0d9986 100644 --- a/stdlib/source/program/aedifex/metadata/snapshot.lux +++ b/stdlib/source/program/aedifex/metadata/snapshot.lux @@ -77,19 +77,14 @@ (..format_version version) (///artifact/versioning.format versioning))))) -(def: (sub tag parser) - (All [a] (-> xml.Tag (Parser a) (Parser a))) - (do <>.monad - [_ (.node tag)] - (.children parser))) - (def: (text tag) (-> xml.Tag (Parser Text)) - (..sub tag .text)) + (<| (.node tag) + .text)) (def: #export parser (Parser Metadata) - (<| (..sub ..) + (<| (.node ..) (do {! <>.monad} [group (.somewhere (..text ..)) name (.somewhere (..text ..)) diff --git a/stdlib/source/program/aedifex/pom.lux b/stdlib/source/program/aedifex/pom.lux index 0d468d5f2..8f45dda36 100644 --- a/stdlib/source/program/aedifex/pom.lux +++ b/stdlib/source/program/aedifex/pom.lux @@ -29,6 +29,7 @@ ## https://maven.apache.org/pom.html (def: project_tag "project") +(def: dependency_tag "dependency") (def: dependencies_tag "dependencies") (def: repositories_tag "repositories") (def: repository_tag "repository") @@ -78,7 +79,7 @@ (def: (dependency value) (-> Dependency XML) - (#_.Node ["" "dependency"] + (#_.Node ["" ..dependency_tag] _.attributes (list\compose (..artifact (get@ #//dependency.artifact value)) (list (..property "type" (get@ #//dependency.type value)))))) @@ -151,14 +152,18 @@ (def: parse_property (Parser [Tag Text]) - (<>.and .tag - (.children .text))) + (do {! <>.monad} + [tag .tag] + (<| (.node tag) + (\ ! map (|>> [tag])) + .text))) (def: (parse_dependency own_version parent_version) (-> Text Text (Parser Dependency)) (do {! <>.monad} [properties (\ ! map (dictionary.from_list name.hash) - (.children (<>.some ..parse_property)))] + (<| (.node ["" ..dependency_tag]) + (<>.some ..parse_property)))] (<| <>.lift try.from_maybe (do maybe.monad @@ -177,54 +182,46 @@ (def: (parse_dependencies own_version parent_version) (-> Text Text (Parser (List Dependency))) - (do {! <>.monad} - [_ (.node ["" ..dependencies_tag])] - (.children (<>.some (..parse_dependency own_version parent_version))))) + (<| (.node ["" ..dependencies_tag]) + (<>.some (..parse_dependency own_version parent_version)))) (def: parse_repository (Parser Address) - (do {! <>.monad} - [_ (.node ["" ..repository_tag])] - (.children - (do ! - [_ (.node ["" ..url_tag])] - (.children .text))))) + (<| (.node ["" ..repository_tag]) + (.node ["" ..url_tag]) + .text)) (def: parse_repositories (Parser (List Address)) - (do {! <>.monad} - [_ (.node ["" ..repositories_tag])] - (.children (<>.some ..parse_repository)))) + (<| (.node ["" ..repositories_tag]) + (<>.some ..parse_repository))) (def: own_version (Parser Text) - (do <>.monad - [_ (.node ["" ..version_tag])] - (.children .text))) + (<| (.node ["" ..version_tag]) + .text)) (def: parent_version (Parser Text) - (do <>.monad - [_ (.node ["" "parent"])] - ..own_version)) + (<| (.node ["" "parent"]) + ..own_version)) (def: #export parser (Parser /.Profile) (do {! <>.monad} [own_version (<>.default "" (.somewhere ..own_version)) - parent_version (<>.default "" (.somewhere ..parent_version)) - _ (.node ["" ..project_tag])] - (.children - (do ! - [dependencies (|> (..parse_dependencies own_version parent_version) - .somewhere - (<>.default (list))) - repositories (|> ..parse_repositories - .somewhere - (<>.default (list))) - _ (<>.some .ignore)] - (wrap (|> (\ /.monoid identity) - (update@ #/.dependencies (function (_ empty) - (list\fold set.add empty dependencies))) - (update@ #/.repositories (function (_ empty) - (list\fold set.add empty repositories))))))))) + parent_version (<>.default "" (.somewhere ..parent_version))] + (<| (.node ["" ..project_tag]) + (do ! + [dependencies (|> (..parse_dependencies own_version parent_version) + .somewhere + (<>.default (list))) + repositories (|> ..parse_repositories + .somewhere + (<>.default (list))) + _ (<>.some .ignore)] + (wrap (|> (\ /.monoid identity) + (update@ #/.dependencies (function (_ empty) + (list\fold set.add empty dependencies))) + (update@ #/.repositories (function (_ empty) + (list\fold set.add empty repositories))))))))) -- cgit v1.2.3