(.require [library [lux (.except global) [abstract ["[0]" monad (.only do)]] [control ["<>" parser]] [data ["[0]" text ["%" \\format] ["<[1]>" \\parser (.only Parser)]] [collection ["[0]" list (.use "[1]#[0]" monad mix)] ["[0]" set]]] ["[0]" meta (.only) [extension (.only declaration)] ["[0]" type] ["[0]" code (.only) ["<[1]>" \\parser]] [macro [syntax (.only syntax)] ["[0]" expansion]] [target ["/" ruby]] [compiler ["[0]" phase] [meta [cache ["[0]" dependency ["[1]" artifact]]]] [language [lux ["[0]" translation] ["[0]" declaration] ["[0]" analysis ["[1]" type]]]]]]]]) (def upper! (.one_of! "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) (def lower! (.one_of! "abcdefghijklmnopqrstuvwxyz")) (def decimal! (.one_of! "0123456789")) (def sigil! (.one_of! "_")) (def tail! (all <>.either ..upper! ..lower! ..decimal! ..sigil! )) (with_template [ ] [(def (Parser Text) (<| .slice (.and! ) (.some! ..tail!)))] [method ..lower!] [global (.one_of! "$")] [constant ..upper!] ) (type Name (Variant {#Method Text} {#Global Text})) (def name (Parser Name) (<>.or ..method (<>.either ..global ..constant))) (def definition (-> Code (Meta [Name Code])) (|>> (list) (.result (<| .form (<>.after (.this_symbol (symbol .def#))) (<>.before .any) (all <>.and (.then ..name .local) .any))) meta.of_try)) (def .public export_one (declaration (_ phase archive [global? .bit name .text term .any]) (do [! phase.monad] [next declaration.analysis [type term] (<| declaration.of_analysis analysis.inferring (next archive term)) lux (declaration.of_analysis meta.compiler_state) next declaration.synthesis term (declaration.of_synthesis (next lux archive term)) dependencies (declaration.of_translation (dependency.dependencies archive term)) next declaration.translation [interim_artifacts term] (declaration.of_translation (translation.with_interim_artifacts archive (next lux archive term))) _ (declaration.of_translation (do ! [@self (translation.learn_custom name (list#mix set.has dependencies interim_artifacts)) .let [[:input:/* :output:] (type.flat_function type) code (if global? (/.set (list (/.manual name)) term) (when :input:/* {.#End} (/.function (/.manual name) (list) (/.return term)) _ (/.statement (/.apply (list (/.string name) term) {.#None} (/.manual "define_method")))))] _ (translation.execute! code) _ (translation.save! @self {.#None} code)] (translation.log! (%.format "Export " (%.text name)))))] (in declaration.no_requirements)))) (def .public export (syntax (_ [exports (<>.many .any)]) (let [! meta.monad] (|> exports (monad.each ! expansion.complete) (at ! each (|>> list#conjoint (monad.each ! ..definition))) (at ! conjoint) (at ! each (list#each (function (_ [name term]) (` (export_one (,* (when name {#Method name} (list (code.bit false) (code.text name)) {#Global name} (list (code.bit true) (code.text name)))) (, term))))))))))