prolog - How can extract the module's name in a file? -
how can extract module's name , optional predicates present in file?
if have file.pl containing call 1 or more modules, how can extract name of these modules , name of predicates in module declaration?
example: if file contains call module
:- use_module(library(lists), [ member/2, append/2 list_concat ]). :- use_module(library(option).
i want create predicate extract(file.pl)
and output list=[[list,member,append],[option]]
thanks.
assuming swi-prolog (as tagged). write similar in logtalk adapter file prolog compiler:
list_of_exports(file, module, exports) :- absolute_file_name(file, path, [file_type(prolog), access(read), file_errors(fail)]), module_property(module, file(path)), % succeeds loaded modules module_property(module, exports(exports)), !. list_of_exports(file, module, exports) :- absolute_file_name(file, path, [file_type(prolog), access(read), file_errors(fail)]), open(path, read, in), ( peek_char(in, #) -> % deal #! script; if not present skip(in, 10) % assume module declaration ; true % first directive on file ), setup_call_cleanup(true, read(in, moduledecl), close(in)), moduledecl = (:- module(module, exports)), ( var(module) -> file_base_name(path, base), file_name_extension(module, _, base) ; true ).
note code doesn't deal encoding/1 directives might present first term of file. code written long ago of swi-prolog author.
Comments
Post a Comment