diff options
Diffstat (limited to 'stdlib/source/lux/macro/syntax/common.lux')
-rw-r--r-- | stdlib/source/lux/macro/syntax/common.lux | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/stdlib/source/lux/macro/syntax/common.lux b/stdlib/source/lux/macro/syntax/common.lux index 9d1887b87..69564fc7d 100644 --- a/stdlib/source/lux/macro/syntax/common.lux +++ b/stdlib/source/lux/macro/syntax/common.lux @@ -3,7 +3,9 @@ ## If a copy of the MPL was not distributed with this file, ## You can obtain one at http://mozilla.org/MPL/2.0/. -(;module: +(;module: {#;doc "Commons syntax parsers and generators. + + The goal is to be able to reuse common syntax in macro definitions across libraries."} lux (lux (control monad) (data (struct [list]) @@ -20,6 +22,10 @@ #Hidden) (def: #export export-level + {#;doc (doc "A parser for export levels." + "Such as:" + #export + #hidden)} (Syntax (Maybe Export-Level)) (s;opt (s;alt (s;tag! ["" "export"]) (s;tag! ["" "hidden"])))) @@ -42,6 +48,11 @@ #decl-args (List Text)}) (def: #export decl + {#;doc (doc "A parser for declaration syntax." + "Such as:" + quux + (foo bar baz))} + (Syntax Decl) (s;either (s;seq s;local-symbol (:: s;Monad<Syntax> wrap (list))) (s;form (s;seq s;local-symbol @@ -52,7 +63,7 @@ {#def-name Text #def-type (Maybe AST) #def-value AST - #def-meta (List [Ident AST]) + #def-anns (List [Ident AST]) #def-args (List Text) }) @@ -66,17 +77,17 @@ (s;seq (:: s;Monad<Syntax> wrap #;None) s;any))) -(def: _def-meta-tag^ +(def: _def-anns-tag^ (Syntax Ident) (s;tuple (s;seq s;text s;text))) -(def: (_def-meta^ _) +(def: (_def-anns^ _) (-> Top (Syntax (List [Ident AST]))) (s;alt (s;tag! ["lux" "Nil"]) (s;form (do s;Monad<Syntax> [_ (s;tag! ["lux" "Cons"]) - [head tail] (s;seq (s;tuple (s;seq _def-meta-tag^ s;any)) - (_def-meta^ []))] + [head tail] (s;seq (s;tuple (s;seq _def-anns-tag^ s;any)) + (_def-anns^ []))] (wrap [head tail]))) )) @@ -119,6 +130,7 @@ )) (def: #export (def compiler) + {#;doc "A parser that first macro-expands and then analyses the input AST, to ensure it's a definition."} (-> Compiler (Syntax Def-Syntax)) (do s;Monad<Syntax> [def-raw s;any @@ -129,17 +141,18 @@ [_ (s;symbol! ["lux" "_lux_def"]) def-name s;local-symbol [?def-type def-value] check^ - def-meta s;any - def-meta (s;local (list def-meta) - (_def-meta^ [])) - #let [def-args (find-def-args def-meta)]] + def-anns s;any + def-anns (s;local (list def-anns) + (_def-anns^ [])) + #let [def-args (find-def-args def-anns)]] (wrap {#def-name def-name #def-type ?def-type - #def-meta def-meta + #def-anns def-anns #def-value def-value #def-args def-args})))))) -(def: #export (typed-de compiler) +(def: #export (typed-def compiler) + {#;doc "A parser for definitions that ensures the input syntax is typed."} (-> Compiler (Syntax Def-Syntax)) (do s;Monad<Syntax> [_def (def compiler) @@ -152,14 +165,17 @@ )] (wrap _def))) -(def: #export def-meta +(def: #export def-anns + {#;doc "Parser for the common annotations syntax used by def: statements."} (Syntax (List [Ident AST])) (s;record (s;some (s;seq s;tag s;any)))) (def: #export typed-arg + {#;doc "Parser for the common typed-argument syntax used by many macros."} (Syntax [Text AST]) (s;tuple (s;seq s;local-symbol s;any))) (def: #export type-params + {#;doc "Parser for the common type var/param used by many macros."} (Syntax (List Text)) (s;tuple (s;some s;local-symbol))) |