(.require [library [lux (.except) [abstract ["[0]" monad]] [control ["<>" parser (.use "[1]#[0]" monad) ["" code (.only Parser)]]] [data ["[0]" product] [collection ["[0]" list (.use "[1]#[0]" functor)]]] [macro (.only with_symbols) [syntax (.only syntax)] ["[0]" code]] [tool [compiler ["[0]" phase] [language [lux [analysis ["" \\parser]] [synthesis ["" \\parser]]]]]]]]) (type Declaration (Record [#name Code #label Text #phase Text #archive Text #inputs (List Code)])) (def (declaration default) (-> Code (Parser Declaration)) (.form (all <>.and .any .local .local .local (.tuple (<>.some .any))))) (with_template [ ] [(def .public (syntax (_ [[name extension phase archive inputs] (..declaration (` )) body .any]) (let [g!name (code.local extension) g!phase (code.local phase) g!archive (code.local archive)] (with_symbols [g!handler g!inputs g!error g!_] (in (list (` ( (~ name) (.function ((~ g!handler) (~ g!name) (~ g!phase) (~ g!archive) (~ g!inputs)) (.case ((~! ) ((~! monad.do) (~! <>.monad) [(~+ inputs) (~ g!_) ] (.at (~! <>.monad) (~' in) (~ body))) (~ g!inputs)) {.#Right (~ g!_)} (~ g!_) {.#Left (~ g!error)} ((~! phase.failure) (~ g!error))) )))))))))] [.any .end .and .result "lux def analysis" analysis] [.any .end .and .result "lux def synthesis" synthesis] [.any .end .and .result "lux def generation" generation] [.any .end .and .result "lux def directive" directive] )