diff options
author | The Lux Programming Language | 2017-12-02 14:33:40 -0400 |
---|---|---|
committer | GitHub | 2017-12-02 14:33:40 -0400 |
commit | a3687e36a71ebbc3069260e904e47272933a48a1 (patch) | |
tree | 0783fac3f94ea4765dfc91b0fe85b9b1a37cb5d8 /new-luxc/source/luxc/lang/analysis/procedure | |
parent | 0ea9403e482b7f01df9e634ae2533b20ef56a9ab (diff) | |
parent | c72e120e8c2c300411c0cb07ecb3b6bc32e0cb24 (diff) |
Merge pull request #42 from LuxLang/context_sensitive_macro_expansion
Context sensitive macro expansion
Diffstat (limited to 'new-luxc/source/luxc/lang/analysis/procedure')
-rw-r--r-- | new-luxc/source/luxc/lang/analysis/procedure/common.lux | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/new-luxc/source/luxc/lang/analysis/procedure/common.lux b/new-luxc/source/luxc/lang/analysis/procedure/common.lux index b003edfa7..ecdcd0bfd 100644 --- a/new-luxc/source/luxc/lang/analysis/procedure/common.lux +++ b/new-luxc/source/luxc/lang/analysis/procedure/common.lux @@ -20,6 +20,7 @@ [".A" type])))) (exception: #export Incorrect-Procedure-Arity) +(exception: #export Invalid-Syntax) ## [Utils] (type: #export Proc @@ -80,7 +81,7 @@ ## [Analysers] ## "lux is" represents reference/pointer equality. -(def: (lux-is proc) +(def: (lux//is proc) (-> Text Proc) (function [analyse eval args] (do macro.Monad<Meta> @@ -90,7 +91,7 @@ ## "lux try" provides a simple way to interact with the host platform's ## error-handling facilities. -(def: (lux-try proc) +(def: (lux//try proc) (-> Text Proc) (function [analyse eval args] (case args @@ -127,6 +128,22 @@ _ (&.throw Incorrect-Procedure-Arity (wrong-arity proc +2 (list.size args)))))) +(def: (lux//in-module proc) + (-> Text Proc) + (function [analyse eval argsC+] + (case argsC+ + (^ (list [_ (#.Text module-name)] exprC)) + (&.with-current-module module-name + (analyse exprC)) + + _ + (&.throw Invalid-Syntax (format "Procedure: " proc "\n" + " Inputs:" (|> argsC+ + list.enumerate + (list/map (function [[idx argC]] + (format "\n " (%n idx) " " (%code argC)))) + (text.join-with "")) "\n"))))) + (do-template [<name> <analyser>] [(def: (<name> proc) (-> Text Proc) @@ -158,13 +175,14 @@ (def: lux-procs Bundle (|> (dict.new text.Hash<Text>) - (install "is" lux-is) - (install "try" lux-try) + (install "is" lux//is) + (install "try" lux//try) (install "function" lux//function) (install "case" lux//case) (install "check" lux//check) (install "coerce" lux//coerce) - (install "check type" lux//check//type))) + (install "check type" lux//check//type) + (install "in-module" lux//in-module))) (def: io-procs Bundle |