lfe_macro_include.erl - Include File Processor
Purpose: Handle include-file and include-lib macro forms.
Location: src/lfe_macro_include.erl
Size: 502 LOC, 18KB
Module Classification: Compiler support, macro system
Public API
file(Name, St) -> {ok, Forms, State}
| {error, Error, State}
Include a file by name. Located at lfe_macro_include.erl:45.
lib(Name, St) -> {ok, Forms, State}
| {error, Error, State}
Include a library file. Located at lfe_macro_include.erl:55.
Include Forms
Include File:
(include-file "common-macros.lfe")
Searches:
- Current directory
- Directories in
-Iinclude path option
Include Lib:
(include-lib "lfe/include/clj.lfe")
Searches:
- Erlang lib directories (
code:lib_dir/1) - Standard OTP application paths
File Resolution
Include File Resolution (lfe_macro_include.erl:115-140):
resolve_include(File, IncludePath) ->
% Try each directory in include path
case try_paths(["."|IncludePath], File) of
{ok, Path} -> Path;
error -> {error, {include_file, File}}
end.
Include Lib Resolution (lfe_macro_include.erl:142-178):
resolve_include_lib("app/include/file.lfe") ->
case code:lib_dir(app) of
{error, bad_name} ->
{error, {include_lib, "app not found"}};
Dir ->
Path = filename:join([Dir, "include", "file.lfe"]),
check_file(Path)
end.
File Reading and Parsing
Process (lfe_macro_include.erl:89-113):
- Resolve file path
- Read file contents
- Parse into tokens (
lfe_scan:string/1) - Parse tokens into forms (
lfe_parse:forms/1) - Return forms for expansion
Dependencies
lfe_scan- Lexical analysislfe_parse- Parsinglfe_io- File I/Ofilename,code(Erlang) - Path resolution
Used By
lfe_macro- Expandsinclude-fileandinclude-libforms
Special Considerations
Recursive Includes: Supported (include files can include other files)
Include Guards: Not built-in; user must avoid circular includes manually
Compile-Time Evaluation: Included forms are expanded at compile time, so changes to included files require recompilation
Performance: Large include files slow compilation; prefer modular design