From c10e3c13866ef25bab020ec597fd11aa8d01c862 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 16 Sep 2020 05:54:25 -0400 Subject: Changed the format of project descriptor files. --- stdlib/source/program/aedifex/parser.lux | 166 +++++++++++++++++++------------ 1 file changed, 101 insertions(+), 65 deletions(-) (limited to 'stdlib/source/program/aedifex') diff --git a/stdlib/source/program/aedifex/parser.lux b/stdlib/source/program/aedifex/parser.lux index 508550a2a..bbcbabb95 100644 --- a/stdlib/source/program/aedifex/parser.lux +++ b/stdlib/source/program/aedifex/parser.lux @@ -1,12 +1,19 @@ (.module: - [lux (#- type) + [lux (#- Module type) [abstract [monad (#+ do)]] [control ["<>" parser ["" code (#+ Parser)]]] [data - ["." text]] + ["." text] + [collection + ["." dictionary (#+ Dictionary)]]] + [tool + [compiler + [meta + [archive + [descriptor (#+ Module)]]]]] [world [net (#+ URL)]]] [// @@ -14,6 +21,25 @@ ["//." artifact (#+ Artifact)] ["//." dependency]]) +(def: (as-input input) + (-> (Maybe Code) (List Code)) + (case input + (#.Some input) + (list input) + + #.None + (list))) + +(def: (singular input tag parser) + (All [a] (-> (Dictionary Text Code) Text (Parser a) (Parser a))) + (.local (..as-input (dictionary.get tag input)) + parser)) + +(def: (plural input tag parser) + (All [a] (-> (Dictionary Text Code) Text (Parser a) (Parser (List a)))) + (.local (..as-input (dictionary.get tag input)) + (.tuple (<>.some parser)))) + (def: group (Parser //artifact.Group) .text) @@ -42,42 +68,52 @@ (Parser /.SCM) ..url) +(def: description + (Parser Text) + .text) + (def: license (Parser /.License) - (.tuple ($_ <>.and - ..name - ..url - (<>.default #/.Repo - (<>.or (.this! (' #repo)) - (.this! (' #manual))))))) + (do {@ <>.monad} + [input (:: @ map + (dictionary.from-list text.hash) + (.record (<>.some (<>.and .local-tag + .any))))] + (.tuple ($_ <>.and + (..singular input "name" ..name) + (..singular input "url" ..url) + (<>.default #/.Repo + (..singular input "type" + (<>.or (.this! (' #repo)) + (.this! (' #manual))))))))) (def: organization (Parser /.Organization) - (<| .form - (<>.after (.this! (' #organization))) - ($_ <>.and - ..name - ..url))) - -(def: developer' - (Parser /.Developer) - ($_ <>.and - ..name - ..url - (<>.maybe ..organization) - )) + (do {@ <>.monad} + [input (:: @ map + (dictionary.from-list text.hash) + (.record (<>.some (<>.and .local-tag + .any))))] + ($_ <>.and + (..singular input "name" ..name) + (..singular input "url" ..url)))) (def: developer (Parser /.Developer) - (<| .form - (<>.after (.this! (' #developer))) - ..developer')) + (do {@ <>.monad} + [input (:: @ map + (dictionary.from-list text.hash) + (.record (<>.some (<>.and .local-tag + .any))))] + ($_ <>.and + (..singular input "name" ..name) + (..singular input "url" ..url) + (<>.maybe (..singular input "organization" ..organization)) + ))) (def: contributor (Parser /.Contributor) - (<| .form - (<>.after (.this! (' #contributor))) - ..developer')) + ..developer) (def: no-info /.Info @@ -89,26 +125,22 @@ #/.developers (list) #/.contributors (list)}) -(def: (singular tag parser) - (All [a] (-> Code (Parser a) (Parser a))) - (.form (<>.after (.this! tag) parser))) - -(def: (plural tag parser) - (All [a] (-> Code (Parser a) (Parser (List a)))) - (.form (<>.after (.this! tag) - (<>.some parser)))) - (def: info (Parser /.Info) - ($_ <>.and - (<>.maybe ..url) - (<>.maybe ..scm) - (<>.maybe .text) - (<>.default (list) (..plural (' #licenses) ..license)) - (<>.maybe ..organization) - (<>.default (list) (..plural (' #developers) ..developer)) - (<>.default (list) (..plural (' #contributors) ..contributor)) - )) + (do {@ <>.monad} + [input (:: @ map + (dictionary.from-list text.hash) + (.record (<>.some (<>.and .local-tag + .any))))] + ($_ <>.and + (<>.maybe (..singular input "url" ..url)) + (<>.maybe (..singular input "scm" ..scm)) + (<>.maybe (..singular input "description" ..description)) + (<>.default (list) (..plural input "licenses" ..license)) + (<>.maybe (..singular input "organization" ..organization)) + (<>.default (list) (..plural input "developers" ..developer)) + (<>.default (list) (..plural input "contributors" ..contributor)) + ))) (def: repository (Parser //dependency.Repository) @@ -130,25 +162,29 @@ (Parser /.Source) .text) +(def: module + (Parser Module) + .text) + (def: #export project (Parser /.Project) - (<| .form - (<>.after (.this! (' project:))) - (`` ($_ <>.and - ..artifact - (<| (<>.default ..no-info) - (..singular (' #info) ..info)) - (<| (<>.default (list)) - (..plural (' #repositories)) - ..repository) - (<| (<>.default (list)) - (..plural (' #dependencies)) - ..dependency) - (<| (<>.default (list "source")) - (..plural (' #sources)) - ..source) - (<| (<>.default "target") - (..singular (' #target) .text)) - (<>.maybe (..singular (' #program) .text)) - (<>.maybe (..singular (' #test) .text)) - )))) + (do {@ <>.monad} + [input (:: @ map + (dictionary.from-list text.hash) + (.record (<>.some (<>.and .local-tag + .any))))] + ($_ <>.and + (..singular input "identity" ..artifact) + (<>.default ..no-info + (..singular input "info" ..info)) + (<>.default (list) + (..plural input "repositories" ..repository)) + (<>.default (list) + (..plural input "dependencies" ..dependency)) + (<>.default (list "source") + (..plural input "sources" ..source)) + (<>.default "target" + (..singular input "target" .text)) + (<>.maybe (..singular input "program" ..module)) + (<>.maybe (..singular input "test" ..module)) + ))) -- cgit v1.2.3