epp: parse_file / 3 executes preprocesses and parses the source Erlang file. For pre-processing, he needs all the macro definition. There are 3 possibilities.
- A macro can be defined in the same file, or the hrl file where it is defined is included in the full path. In this case, it automatically solves the same thing.
- A macro can be defined in the hrl file. Then the directories of the included files can be specified in the second argument. Example:
epp:parse_file("test.erl", ["../include"], []). It searches for all files in the directory and resolves it. - A macro cannot be defined (or you may not want to look for it in include directories). This will result in a form error. for instance
{error,{21,epp,{undefined,'YOURSERVER',none}}},
In this case, you can specify it in the parse_file function itself. for instance
epp:parse_file("yaws.erl", [], [{'YOURSERVER',yourserver}]).
This will allow the macro.
So, if you have a macro in the source file, you do not need to send it. Only if it is not in the source or in the include (or do not want to specify the directory), you can specify it in the function
Note. You can send even if you have it in the source file. But in abstract form there will be a tuple {error, redefine, 'YOURSERVER'} . But it will be redefined in all places with the value sent to the function.
Edit:
From an analysis of the epp code, I found that it is currently not possible to give arguments. The epp module cannot handle complex macro types. Functional structure transfer is not possible in the current mode.
I modified the epp file to handle this case. You can check this link if you are ok to have the modified epp file (only 3 lines added).
Vinod source share