aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/macro/syntax
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/macro/syntax.lux36
-rw-r--r--stdlib/source/lux/macro/syntax/common.lux4
-rw-r--r--stdlib/source/lux/macro/syntax/common/reader.lux16
-rw-r--r--stdlib/source/lux/macro/syntax/common/writer.lux18
4 files changed, 24 insertions, 50 deletions
diff --git a/stdlib/source/lux/macro/syntax.lux b/stdlib/source/lux/macro/syntax.lux
index 48fd00a7c..5cd68ccb9 100644
--- a/stdlib/source/lux/macro/syntax.lux
+++ b/stdlib/source/lux/macro/syntax.lux
@@ -194,11 +194,6 @@
(wrap [real value]))))
## [Syntax]
-(def: #hidden text/join-with text.join-with)
-
-(def: #hidden _run_ p.run)
-(def: #hidden _Monad<Parser>_ p.Monad<Parser>)
-
(macro: #export (syntax: tokens)
{#.doc (doc "A more advanced way to define macros than \"macro:\"."
"The inputs to the macro can be parsed in complex ways through the use of syntax parsers."
@@ -216,16 +211,13 @@
(with-brackets (spaced (list/map constructor-arg$ constructor-args)))
(with-brackets (spaced (list/map (method-def$ id) methods))))))]
(wrap (list (` ((~ (code.text def-code)))))))))}
- (let [[exported? tokens] (: [(Maybe (Either Unit Unit)) (List Code)]
+ (let [[exported? tokens] (: [Bool (List Code)]
(case tokens
- (^ (list& [_ (#.Tag ["" "hidden"])] tokens'))
- [(#.Some #.Left) tokens']
-
(^ (list& [_ (#.Tag ["" "export"])] tokens'))
- [(#.Some #.Right) tokens']
+ [true tokens']
_
- [#.None tokens]))
+ [false tokens]))
?parts (: (Maybe [Text (List Code) Code Code])
(case tokens
(^ (list [_ (#.Form (list& [_ (#.Symbol ["" name])] args))]
@@ -241,7 +233,7 @@
#.None))]
(case ?parts
(#.Some [name args meta body])
- (with-gensyms [g!tokens g!body g!msg]
+ (with-gensyms [g!text/join-with g!tokens g!body g!msg]
(do macro.Monad<Meta>
[vars+parsers (monad.map @
(: (-> Code (Meta [Code Code]))
@@ -258,29 +250,25 @@
args)
#let [g!state ["" "*compiler*"]
error-msg (code.text (text/compose "Wrong syntax for " name))
- export-ast (: (List Code) (case exported?
- (#.Some #.Left)
- (list (' #hidden))
-
- (#.Some #.Right)
- (list (' #export))
-
- _
- (list)))]]
+ export-ast (: (List Code)
+ (if exported?
+ (list (' #export))
+ (list)))]]
(wrap (list (` (macro: (~+ export-ast) ((~ (code.symbol ["" name])) (~@ g!tokens) (~@ g!state))
(~ meta)
("lux case" (..run (~@ g!tokens)
(: (Syntax (Meta (List Code)))
- (do .._Monad<Parser>_
+ (do (~! p.Monad<Parser>)
[(~+ (join-pairs vars+parsers))]
- ((~' wrap) (do macro.Monad<Meta>
+ ((~' wrap) (do (~! macro.Monad<Meta>)
[]
(~ body))))))
{(#E.Success (~@ g!body))
((~@ g!body) (~@ g!state))
(#E.Error (~@ g!msg))
- (#E.Error (text/join-with ": " (list (~ error-msg) (~@ g!msg))))})))))))
+ (let [(~@ g!text/join-with) (~! text.join-with)]
+ (#E.Error ((~@ g!text/join-with) ": " (list (~ error-msg) (~@ g!msg)))))})))))))
_
(macro.fail "Wrong syntax for syntax:"))))
diff --git a/stdlib/source/lux/macro/syntax/common.lux b/stdlib/source/lux/macro/syntax/common.lux
index 8c684537e..9de36fe5d 100644
--- a/stdlib/source/lux/macro/syntax/common.lux
+++ b/stdlib/source/lux/macro/syntax/common.lux
@@ -3,10 +3,6 @@
The goal is to be able to reuse common syntax in macro definitions across libraries."}
lux)
-(type: #export Export
- #Exported
- #Hidden)
-
(type: #export Declaration
{#declaration-name Text
#declaration-args (List Text)})
diff --git a/stdlib/source/lux/macro/syntax/common/reader.lux b/stdlib/source/lux/macro/syntax/common/reader.lux
index ac6d876c3..0e8b5df9a 100644
--- a/stdlib/source/lux/macro/syntax/common/reader.lux
+++ b/stdlib/source/lux/macro/syntax/common/reader.lux
@@ -1,7 +1,7 @@
(.module: {#.doc "Commons syntax readers."}
lux
(lux (control monad
- ["p" parser])
+ ["p" parser "p/" Monad<Parser>])
(data (coll [list])
[ident "ident/" Eq<Ident>]
[product]
@@ -12,13 +12,9 @@
## Exports
(def: #export export
- {#.doc (doc "A reader for export levels."
- "Such as:"
- #export
- #hidden)}
- (Syntax (Maybe Export))
- (p.maybe (p.alt (s.this (' #export))
- (s.this (' #hidden)))))
+ (Syntax Bool)
+ (p.either (p.after (s.this (' #export)) (p/wrap true))
+ (p/wrap false)))
## Declarations
(def: #export declaration
@@ -28,7 +24,7 @@
(foo bar baz))}
(Syntax Declaration)
(p.either (p.seq s.local-symbol
- (:: p.Monad<Parser> wrap (list)))
+ (p/wrap (list)))
(s.form (p.seq s.local-symbol
(p.many s.local-symbol)))))
@@ -46,7 +42,7 @@
type s.any
value s.any]
(wrap [(#.Some type) value])))
- (p.seq (:: p.Monad<Parser> wrap #.None)
+ (p.seq (p/wrap #.None)
s.any)))
(def: _definition-anns-tag^
diff --git a/stdlib/source/lux/macro/syntax/common/writer.lux b/stdlib/source/lux/macro/syntax/common/writer.lux
index d5ad8cb61..5b5ab9ab5 100644
--- a/stdlib/source/lux/macro/syntax/common/writer.lux
+++ b/stdlib/source/lux/macro/syntax/common/writer.lux
@@ -1,24 +1,18 @@
(.module: {#.doc "Commons syntax writers."}
lux
- (lux (data (coll [list "L/" Functor<List>])
+ (lux (data (coll [list "list/" Functor<List>])
[product])
(macro [code]))
[// #*])
## Exports
-(def: #export (export ?el)
- (-> (Maybe Export) (List Code))
- (case ?el
- #.None
- (list)
-
- (#.Some #//.Exported)
+(def: #export (export exported?)
+ (-> Bool (List Code))
+ (if exported?
(list (' #export))
-
- (#.Some #//.Hidden)
- (list (' #hidden))))
+ (list)))
## Annotations
(def: #export (annotations anns)
(-> Annotations Code)
- (|> anns (L/map (product.both code.tag id)) code.record))
+ (|> anns (list/map (product.both code.tag id)) code.record))