1% lfe_macro(3) 2% Robert Virding 3% 2008-2016 4 5 6# NAME 7 8lfe_macro - Lisp Flavoured Erlang (LFE) macro expander 9 10 11# SYNOPSIS 12 13This module provides an interface to the LFE macro expander. 14The expander is used by the LFE compile and in the shell but 15can also be used by applications explicitly wanting to handle 16a file. 17 18 19# DATA TYPES 20 21**sexpr()** 22 23An LFE s-expression, a list structure. 24 25**filesexpr() = {Sexpr,Line}** 26 27This is the format returned by ``lfe_io:parse_file/1`` and 28is used by the compiler to give better error information. 29 30**env()** 31 32This is an macro and evaluation environment as created 33by ``lfe_lib:new_env()``. 34 35 36# EXPORTS 37 38**expand_forms([FileSexpr], Env) -> ExpRet** 39 40where 41 42``` 43 FileSexpr = filesexpr() 44 Env = env() 45 ExpRet = {yes,[FileSexpr],Env,Warnings} | {error,Errors,Warnings} 46``` 47 48**macro_forms([FileSexpr], Env) -> {[FileSexpr],Env}.** 49 50where 51 52``` 53FileSexpr = filesexpr() 54Env = env() 55``` 56 57**expand_expr_all(Sexpr, Env) -> Sexpr.** 58 59where 60 61``` 62Sexpr = sexpr() 63Env = env() 64``` 65 66Expand all macros in Sexpr either using the definitions in Env 67or just the default macros. Note that any eventual new macro 68definitions will be lost. 69 70**expand_expr(Sexpr, Env) -> {yes,Exp} | no.** 71 72**expand_expr_1(Sexpr, Env) -> {yes,Exp} | no.** 73 74where 75 76``` 77Sexpr = Exp = sexpr() 78Env = env() 79``` 80 81Test if the top s-expression here is a macro call, if so 82expand it and return {yes,Expansion}, if not then return no. 83``expand_expr/2`` will expand the top s-expression as much as 84possible while ``expand_expr_1/2`` will only try it once. These 85functions use the macro definitions in the environment and the 86standard pre-defined macros. 87 88 89# SEE ALSO 90 91**lfe_comp(3)**, **lfe_gen(3)** 92