(.module: [lux (#- Module type) [abstract [monad (#+ do)]] [control ["<>" parser ["" code (#+ Parser)]]] [data ["." text] [collection ["." dictionary (#+ Dictionary)] ["." set (#+ Set)]]] [tool [compiler [meta [archive [descriptor (#+ Module)]]]]] [world [net (#+ URL)]]] ["." // #_ ["/" profile] ["#." project (#+ Project)] ["#." dependency] ["#." repository] ["#." artifact (#+ Artifact) ["#/." type]]]) (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) (def: name (Parser //artifact.Name) .text) (def: version (Parser //artifact.Version) .text) (def: artifact' (Parser //artifact.Artifact) ($_ <>.and ..group ..name ..version)) (def: artifact (Parser //artifact.Artifact) (.tuple ..artifact')) (def: url (Parser URL) .text) (def: scm (Parser /.SCM) ..url) (def: description (Parser Text) .text) (def: license (Parser /.License) (do {! <>.monad} [input (\ ! map (dictionary.from_list text.hash) (.record (<>.some (<>.and .local_tag .any))))] ($_ <>.and (..singular input "name" ..name) (..singular input "url" ..url) (<>.default #/.Repo (..singular input "type" (<>.or (.this! (' #repo)) (.this! (' #manual)))))))) (def: organization (Parser /.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) (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) ..developer) (def: info (Parser /.Info) (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 //repository.Address) ..url) (def: type (Parser //artifact/type.Type) .text) (def: dependency (Parser //dependency.Dependency) (.tuple ($_ <>.and ..artifact' (<>.default //artifact/type.lux_library ..type) ))) (def: source (Parser /.Source) .text) (def: target (Parser /.Target) .text) (def: module (Parser Module) .text) (def: deploy_repository (Parser (List [Text //repository.Address])) (.record (<>.some (<>.and .text ..repository)))) (def: profile (Parser /.Profile) (do {! <>.monad} [input (\ ! map (dictionary.from_list text.hash) (.record (<>.some (<>.and .local_tag .any)))) #let [^parents (: (Parser (List /.Name)) (<>.default (list) (..plural input "parents" .text))) ^identity (: (Parser (Maybe Artifact)) (<>.maybe (..singular input "identity" ..artifact))) ^info (: (Parser (Maybe /.Info)) (<>.maybe (..singular input "info" ..info))) ^repositories (: (Parser (Set //repository.Address)) (|> (..plural input "repositories" ..repository) (\ ! map (set.from_list text.hash)) (<>.default (set.new text.hash)))) ^dependencies (: (Parser (Set //dependency.Dependency)) (|> (..plural input "dependencies" ..dependency) (\ ! map (set.from_list //dependency.hash)) (<>.default (set.new //dependency.hash)))) ^sources (: (Parser (Set /.Source)) (|> (..plural input "sources" ..source) (\ ! map (set.from_list text.hash)) (<>.default (set.from_list text.hash (list /.default_source))))) ^target (: (Parser (Maybe /.Target)) (<>.maybe (..singular input "target" ..target))) ^program (: (Parser (Maybe Module)) (<>.maybe (..singular input "program" ..module))) ^test (: (Parser (Maybe Module)) (<>.maybe (..singular input "test" ..module))) ^deploy_repositories (: (Parser (Dictionary Text //repository.Address)) (<| (\ ! map (dictionary.from_list text.hash)) (<>.default (list)) (..singular input "deploy-repositories" ..deploy_repository)))]] ($_ <>.and ^parents ^identity ^info ^repositories ^dependencies ^sources ^target ^program ^test ^deploy_repositories ))) (def: #export project (Parser Project) (let [default_profile (: (Parser Project) (\ <>.monad map (|>> [/.default] (list) (dictionary.from_list text.hash)) ..profile)) multi_profile (: (Parser Project) (\ <>.monad map (dictionary.from_list text.hash) (.record (<>.many (<>.and .text ..profile)))))] (<>.either multi_profile default_profile)))