diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/meta/macro/context.lux | 3 | ||||
-rw-r--r-- | stdlib/source/library/lux/meta/macro/custom.lux | 53 | ||||
-rw-r--r-- | stdlib/source/library/lux/meta/macro/syntax/export.lux | 39 |
3 files changed, 74 insertions, 21 deletions
diff --git a/stdlib/source/library/lux/meta/macro/context.lux b/stdlib/source/library/lux/meta/macro/context.lux index 0cf61b454..99b62e8ab 100644 --- a/stdlib/source/library/lux/meta/macro/context.lux +++ b/stdlib/source/library/lux/meta/macro/context.lux @@ -19,8 +19,7 @@ ["[0]" code (.only) ["?[1]" \\parser]]]]] ["[0]" // (.only) - [syntax (.only syntax)] - ["^" pattern]]) + [syntax (.only syntax)]]) (type .public Stack List) diff --git a/stdlib/source/library/lux/meta/macro/custom.lux b/stdlib/source/library/lux/meta/macro/custom.lux new file mode 100644 index 000000000..632219851 --- /dev/null +++ b/stdlib/source/library/lux/meta/macro/custom.lux @@ -0,0 +1,53 @@ +(.require + [library + [lux (.except local) + [abstract + [monad (.only do)]] + [control + ["?" parser (.use "[1]#[0]" functor)] + ["[0]" exception (.only exception)]]]] + ["[0]" // (.only) + [syntax (.only syntax) + ["[0]" export]] + ["/[1]" // (.only) + ["[0]" code (.only) + ["?[1]" \\parser (.only Parser)]] + ["[0]" type (.only) + [primitive (.except)]]]]) + +(exception .public (invalid_type [expected Type + actual Type]) + (exception.report + (list ["Expected" (type.format expected)] + ["Actual" (type.format actual)]))) + +(def local + (Parser Code) + (?#each code.local ?code.local)) + +(def .public custom + (syntax (_ [[public|private <type> <in> <out> <by_name>] + (export.parser (all ?.and + ..local + ..local + ..local + ..local))]) + (//.with_symbols [g!_ g!type g!value] + (in (list (` (primitive (, public|private) (, <type>) + Macro)) + + (` (def (, public|private) (, <in>) + (-> Macro (, <type>)) + (|>> abstraction))) + + (` (def (, public|private) (, <out>) + (-> (, <type>) Macro) + (|>> representation))) + + (` (def (, public|private) ((, <by_name>) (, g!_)) + (-> Symbol (Meta (, <type>))) + ((,! do) (,! ///.monad) + [[(, g!_) (, g!type) (, g!value)] ((,! ///.export) (, g!_))] + (if (at (,! type.equivalence) (,' =) (, <type>) (, g!type)) + ((,' in) (as (, <type>) (, g!value))) + ((,! ///.failure) ((,! exception.except) ..invalid_type [(, <type>) (, g!type)]))))))))))) diff --git a/stdlib/source/library/lux/meta/macro/syntax/export.lux b/stdlib/source/library/lux/meta/macro/syntax/export.lux index d68b4a678..1bc78cb9f 100644 --- a/stdlib/source/library/lux/meta/macro/syntax/export.lux +++ b/stdlib/source/library/lux/meta/macro/syntax/export.lux @@ -7,30 +7,31 @@ ["<>" parser]] [meta ["[0]" code - ["<[1]>" \\parser (.only Parser)]] - [macro - ["^" pattern]]]]]) + ["<[1]>" \\parser (.only Parser)]]]]]) (def .public default_policy Code (` .private)) -(def policy - (Parser Code) - (do [! <>.monad] - [candidate <code>.next] - (case candidate - [_ {.#Symbol ["" _]}] - (in default_policy) - - (^.or [_ {.#Bit _}] - [_ {.#Symbol _}]) - (do ! - [_ <code>.any] - (in candidate)) - - _ - (in default_policy)))) +(`` (def policy + (Parser Code) + (do [! <>.monad] + [candidate <code>.next] + (case candidate + [_ {.#Symbol ["" _]}] + (in default_policy) + + (,, (with_template [<pattern>] + [<pattern> + (do ! + [_ <code>.any] + (in candidate))] + + [[_ {.#Bit _}]] + [[_ {.#Symbol _}]])) + + _ + (in default_policy))))) (def .public parser (All (_ a) (-> (Parser a) (Parser [Code a]))) |