From fc2737b5226eda69c12bc593e83e22ed54e4d3af Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 8 Jul 2022 19:15:02 -0400 Subject: Extracted macro-expansion machinery into its own module. --- stdlib/source/test/lux/control/remember.lux | 13 ++--- stdlib/source/test/lux/data/text/regex.lux | 5 +- stdlib/source/test/lux/debug.lux | 7 +-- stdlib/source/test/lux/documentation.lux | 7 +-- stdlib/source/test/lux/ffi.jvm.lux | 9 ++-- stdlib/source/test/lux/meta/configuration.lux | 7 +-- stdlib/source/test/lux/meta/macro.lux | 72 +++++++++++++------------- stdlib/source/test/lux/meta/macro/local.lux | 7 +-- stdlib/source/test/lux/meta/macro/template.lux | 7 +-- stdlib/source/test/lux/meta/type/resource.lux | 7 +-- stdlib/source/test/lux/meta/version.lux | 7 +-- 11 files changed, 79 insertions(+), 69 deletions(-) (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/control/remember.lux b/stdlib/source/test/lux/control/remember.lux index 5f4fae4ac..5ad579363 100644 --- a/stdlib/source/test/lux/control/remember.lux +++ b/stdlib/source/test/lux/control/remember.lux @@ -18,8 +18,9 @@ ["[0]" meta (.only) ["[0]" code (.only) ["<[1]>" \\parser]] - ["[0]" macro (.only) - ["[0]" syntax (.only syntax)]]] + [macro + ["[0]" syntax (.only syntax)] + ["[0]" expansion]]] [world [time ["[0]" date (.only Date)] @@ -74,10 +75,10 @@ message (product.right (random.result prng ..message)) expected (product.right (random.result prng ..focus))] (do meta.monad - [should_fail0 (..attempt (macro.expansion (..memory macro yesterday message {.#None}))) - should_fail1 (..attempt (macro.expansion (..memory macro yesterday message {.#Some expected}))) - should_succeed0 (..attempt (macro.expansion (..memory macro tomorrow message {.#None}))) - should_succeed1 (..attempt (macro.expansion (..memory macro tomorrow message {.#Some expected})))] + [should_fail0 (..attempt (expansion.complete (..memory macro yesterday message {.#None}))) + should_fail1 (..attempt (expansion.complete (..memory macro yesterday message {.#Some expected}))) + should_succeed0 (..attempt (expansion.complete (..memory macro tomorrow message {.#None}))) + should_succeed1 (..attempt (expansion.complete (..memory macro tomorrow message {.#Some expected})))] (in (list (code.bit (and (case should_fail0 {try.#Failure error} (and (test_failure yesterday message {.#None} error) diff --git a/stdlib/source/test/lux/data/text/regex.lux b/stdlib/source/test/lux/data/text/regex.lux index 48b376358..c057aeaf0 100644 --- a/stdlib/source/test/lux/data/text/regex.lux +++ b/stdlib/source/test/lux/data/text/regex.lux @@ -18,7 +18,8 @@ ["[0]" code (.only) ["<[1]>" \\parser]] ["[0]" macro (.only) - [syntax (.only syntax)]]]]] + [syntax (.only syntax)] + ["[0]" expansion]]]]] [\\library ["[0]" /]]) @@ -280,7 +281,7 @@ (def expands? (syntax (_ [form .any]) (function (_ lux) - {try.#Success [lux (list (code.bit (case (macro.single_expansion form lux) + {try.#Success [lux (list (code.bit (case (expansion.single form lux) {try.#Success _} true diff --git a/stdlib/source/test/lux/debug.lux b/stdlib/source/test/lux/debug.lux index 8dae4a18e..a503b00cd 100644 --- a/stdlib/source/test/lux/debug.lux +++ b/stdlib/source/test/lux/debug.lux @@ -23,8 +23,9 @@ ["@" target] ["[0]" code (.only) ["<[1]>" \\parser]] - ["[0]" macro (.only) - [syntax (.only syntax)]]] + [macro + [syntax (.only syntax)] + ["[0]" expansion]]] [world [time (.only Time) [instant (.only Instant)] @@ -219,7 +220,7 @@ (def macro_error (syntax (_ [macro .any]) (function (_ compiler) - (case ((macro.expansion macro) compiler) + (case ((expansion.complete macro) compiler) {try.#Failure error} {try.#Success [compiler (list (code.text error))]} diff --git a/stdlib/source/test/lux/documentation.lux b/stdlib/source/test/lux/documentation.lux index 4196ab09d..53296522c 100644 --- a/stdlib/source/test/lux/documentation.lux +++ b/stdlib/source/test/lux/documentation.lux @@ -13,16 +13,17 @@ ["[0]" meta (.only) ["[0]" code (.only) ["<[1]>" \\parser]] - ["[0]" macro (.only) + [macro [syntax (.only syntax)] - ["[0]" template]]]]] + ["[0]" template] + ["[0]" expansion]]]]] [\\library ["[0]" /]]) (def macro_error (syntax (_ [macro .any]) (function (_ compiler) - {try.#Success [compiler (list (code.bit (case ((macro.expansion macro) compiler) + {try.#Success [compiler (list (code.bit (case ((expansion.complete macro) compiler) {try.#Failure error} true diff --git a/stdlib/source/test/lux/ffi.jvm.lux b/stdlib/source/test/lux/ffi.jvm.lux index 91b97276f..b03264c22 100644 --- a/stdlib/source/test/lux/ffi.jvm.lux +++ b/stdlib/source/test/lux/ffi.jvm.lux @@ -28,9 +28,10 @@ ["[0]" type (.use "[1]#[0]" equivalence)] ["[0]" code (.only) ["<[1]>" \\parser]] - ["[0]" macro (.only) + [macro [syntax (.only syntax)] - ["[0]" template]] + ["[0]" template] + ["[0]" expansion]] [target ["[0]" jvm ["[1]" type (.use "[1]#[0]" equivalence)]]]]]] @@ -74,7 +75,7 @@ (def macro_error (syntax (_ [expression .any]) (function (_ lux) - (|> (macro.single_expansion expression) + (|> (expansion.single expression) (meta.result lux) (pipe.case {try.#Success expansion} @@ -670,7 +671,7 @@ (def expands? (syntax (_ [expression .any]) (function (_ lux) - (|> (macro.single_expansion expression) + (|> (expansion.single expression) (meta.result lux) (pipe.case {try.#Success expansion} diff --git a/stdlib/source/test/lux/meta/configuration.lux b/stdlib/source/test/lux/meta/configuration.lux index 0630f5186..ed0998646 100644 --- a/stdlib/source/test/lux/meta/configuration.lux +++ b/stdlib/source/test/lux/meta/configuration.lux @@ -21,8 +21,9 @@ ["[0]" meta (.only) ["[0]" code (.only) ["<[1]>" \\parser]] - ["[0]" macro (.only) - [syntax (.only syntax)]]]]] + [macro + [syntax (.only syntax)] + ["[0]" expansion]]]]] [\\library ["[0]" /]]) @@ -39,7 +40,7 @@ (def failure (syntax (_ [it .any]) (function (_ lux) - (case (macro.expansion it lux) + (case (expansion.complete it lux) {try.#Failure error} {try.#Success [lux (list (code.text error))]} diff --git a/stdlib/source/test/lux/meta/macro.lux b/stdlib/source/test/lux/meta/macro.lux index 80faef121..59dbf995f 100644 --- a/stdlib/source/test/lux/meta/macro.lux +++ b/stdlib/source/test/lux/meta/macro.lux @@ -21,13 +21,13 @@ ["[0]" location] ["[0]" symbol] ["[0]" code (.use "[1]#[0]" equivalence) - ["<[1]>" \\parser]] - [macro - ["^" pattern]]]]] + ["<[1]>" \\parser]]]]] [\\library ["[0]" / (.only) + ["^" pattern] [syntax (.only syntax)] - ["[0]" template]]] + ["[0]" template] + ["[0]" expansion]]] ["[0]" / ["[1][0]" local] ["[1][0]" syntax] @@ -85,9 +85,9 @@ [.#module_hash 0 .#module_aliases (list) .#definitions (is (List [Text .Global]) - (list (!global /.log_single_expansion!) - (!global /.log_expansion!) - (!global /.log_full_expansion!))) + (list (!global expansion.log_single!) + (!global expansion.log_complete!) + (!global expansion.log_total!))) .#imports (list) .#module_state {.#Active}]] [current_module @@ -131,33 +131,33 @@ full_expansion (` (n.* (n.* (, pow/1) (, pow/1)) (n.* (, pow/1) (, pow/1))))]] (`` (all _.and - (,, (with_template [ ] - [(_.coverage [] - (|> ( (` (..pow/4 (, pow/1)))) - (meta.result lux) - (try#each (at (list.equivalence code.equivalence) = - (list ))) - (try.else false))) - - (_.coverage [] - (and (|> (/.single_expansion (` ( "omit" (..pow/4 (, pow/1))))) - (meta.result lux) - (try#each (at (list.equivalence code.equivalence) = (list))) - (try.else false)) - (|> (/.single_expansion (` ( (..pow/4 (, pow/1))))) - (meta.result lux) - (try#each (at (list.equivalence code.equivalence) = (list ))) - (try.else false))))] - - [/.single_expansion /.log_single_expansion! single_expansion] - [/.expansion /.log_expansion! expansion] - [/.full_expansion /.log_full_expansion! full_expansion] - )) - (_.coverage [/.one_expansion] - (bit#= (not (n.= 1 repetitions)) - (|> (/.one_expansion (` (..repeated (, (code.nat repetitions)) (, pow/1)))) - (meta.result lux) - (!expect {try.#Failure _})))) + ... (,, (with_template [ ] + ... [(_.coverage [] + ... (|> ( (` (..pow/4 (, pow/1)))) + ... (meta.result lux) + ... (try#each (at (list.equivalence code.equivalence) = + ... (list ))) + ... (try.else false))) + + ... (_.coverage [] + ... (and (|> (expansion.single (` ( "omit" (..pow/4 (, pow/1))))) + ... (meta.result lux) + ... (try#each (at (list.equivalence code.equivalence) = (list))) + ... (try.else false)) + ... (|> (expansion.single (` ( (..pow/4 (, pow/1))))) + ... (meta.result lux) + ... (try#each (at (list.equivalence code.equivalence) = (list ))) + ... (try.else false))))] + + ... [expansion.single expansion.log_single! single_expansion] + ... [expansion.complete expansion.log_complete! expansion] + ... [expansion.total expansion.log_total! full_expansion] + ... )) + ... (_.coverage [expansion.one] + ... (bit#= (not (n.= 1 repetitions)) + ... (|> (expansion.one (` (..repeated (, (code.nat repetitions)) (, pow/1)))) + ... (meta.result lux) + ... (!expect {try.#Failure _})))) (_.coverage [/.final] (with_expansions [ (static.random_nat) (static.random code.nat @@ -219,10 +219,10 @@ (and (text.contains? symbol_prefix actual_symbol) (text.contains? (%.nat seed) actual_symbol)))))) (_.coverage [/.wrong_syntax_error] - (|> (/.single_expansion (` (/.log_single_expansion!))) + (|> (expansion.single (` (expansion.log_single!))) (meta.result lux) (!expect (^.multi {try.#Failure error} - (text.contains? (/.wrong_syntax_error (symbol /.log_single_expansion!)) + (text.contains? (/.wrong_syntax_error (symbol expansion.log_single!)) error))))) (_.coverage [/.with_symbols] (with_expansions [ (fresh_symbol)] diff --git a/stdlib/source/test/lux/meta/macro/local.lux b/stdlib/source/test/lux/meta/macro/local.lux index 1aa793639..19398b395 100644 --- a/stdlib/source/test/lux/meta/macro/local.lux +++ b/stdlib/source/test/lux/meta/macro/local.lux @@ -22,7 +22,8 @@ ["[0]" code (.only) ["<[1]>" \\parser]] ["[0]" macro (.only) - [syntax (.only syntax)]]]]] + [syntax (.only syntax)] + ["[0]" expansion]]]]] [\\library ["[0]" /]]) @@ -35,7 +36,7 @@ (def macro_error (syntax (_ [macro .any]) (function (_ compiler) - (case ((macro.expansion macro) compiler) + (case ((expansion.complete macro) compiler) {try.#Failure error} {try.#Success [compiler (list (code.text error))]} @@ -69,7 +70,7 @@ (, pop!) (, g!output))))] (if pre_remove - (macro.full_expansion pre_expansion) + (expansion.total pre_expansion) (in (list pre_expansion)))))))) (def .public test diff --git a/stdlib/source/test/lux/meta/macro/template.lux b/stdlib/source/test/lux/meta/macro/template.lux index d2952d268..c239d6821 100644 --- a/stdlib/source/test/lux/meta/macro/template.lux +++ b/stdlib/source/test/lux/meta/macro/template.lux @@ -17,8 +17,9 @@ [meta ["[0]" code (.only) ["<[1]>" \\parser]] - ["[0]" macro (.only) - [syntax (.only syntax)]]]]] + [macro + [syntax (.only syntax)] + ["[0]" expansion]]]]] [\\library ["[0]" /]]) @@ -31,7 +32,7 @@ (def macro_error (syntax (_ [macro .any]) (function (_ compiler) - (case ((macro.expansion macro) compiler) + (case ((expansion.complete macro) compiler) {try.#Failure error} {try.#Success [compiler (list (code.text error))]} diff --git a/stdlib/source/test/lux/meta/type/resource.lux b/stdlib/source/test/lux/meta/type/resource.lux index 34a3bc422..65618e66a 100644 --- a/stdlib/source/test/lux/meta/type/resource.lux +++ b/stdlib/source/test/lux/meta/type/resource.lux @@ -20,8 +20,9 @@ ["[0]" meta (.only) ["[0]" code (.only) ["<[1]>" \\parser]] - ["[0]" macro (.only) - [syntax (.only syntax)]]]]] + [macro + [syntax (.only syntax)] + ["[0]" expansion]]]]] [\\library ["[0]" / (.only Res)]]) @@ -161,7 +162,7 @@ [[_ _ exception] (meta.export exception)] (function (_ compiler) {.#Right [compiler - (list (code.bit (case ((macro.single_expansion to_expand) compiler) + (list (code.bit (case ((expansion.single to_expand) compiler) {try.#Success _} false diff --git a/stdlib/source/test/lux/meta/version.lux b/stdlib/source/test/lux/meta/version.lux index 1df94e003..6df9bf4e5 100644 --- a/stdlib/source/test/lux/meta/version.lux +++ b/stdlib/source/test/lux/meta/version.lux @@ -17,15 +17,16 @@ ["[0]" static] ["[0]" code (.only) ["<[1]>" \\parser]] - ["[0]" macro (.only) - [syntax (.only syntax)]]]]] + [macro + [syntax (.only syntax)] + ["[0]" expansion]]]]] [\\library ["[0]" /]]) (def failure (syntax (_ [it .any]) (function (_ lux) - (case (macro.expansion it lux) + (case (expansion.complete it lux) {try.#Failure error} {try.#Success [lux (list (code.text error))]} -- cgit v1.2.3