diff options
author | Richard Carlsson <carlsson.richard@gmail.com> | 2020-06-12 12:47:42 +0200 |
---|---|---|
committer | Richard Carlsson <carlsson.richard@gmail.com> | 2021-02-01 11:26:56 +0100 |
commit | 81bce85477dea8ab3eb219130370458c9cae6a1d (patch) | |
tree | 4eec63dedc155090195777e721d21b59df2a8d61 /lib/stdlib/src | |
parent | e0dc4f920f4e26ee68832b6c689633ea5d6eab73 (diff) | |
download | erlang-81bce85477dea8ab3eb219130370458c9cae6a1d.tar.gz |
Document epp:scan_erl_form/1 and add epp:scan_file/2
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/epp.erl | 46 | ||||
-rw-r--r-- | lib/stdlib/src/erl_scan.erl | 2 |
2 files changed, 46 insertions, 2 deletions
diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl index b390697a56..1ec3307dbd 100644 --- a/lib/stdlib/src/epp.erl +++ b/lib/stdlib/src/epp.erl @@ -23,7 +23,7 @@ -export([open/1,open/2,open/3,close/1,format_error/1]). -export([scan_erl_form/1,parse_erl_form/1,macro_defs/1]). --export([parse_file/1, parse_file/2, parse_file/3]). +-export([scan_file/1, scan_file/2, parse_file/1, parse_file/2, parse_file/3]). -export([default_encoding/0, encoding_to_string/1, read_encoding_from_binary/1, read_encoding_from_binary/2, set_encoding/1, set_encoding/2, read_encoding/1, read_encoding/2]). @@ -82,6 +82,8 @@ %% close(Epp) %% scan_erl_form(Epp) %% parse_erl_form(Epp) +%% scan_file(Epp) +%% scan_file(FileName, Options) %% parse_file(Epp) %% parse_file(FileName, Options) %% parse_file(FileName, IncludePath, PreDefMacros) @@ -151,6 +153,15 @@ close(Epp) -> receive {'DOWN',Ref,_,_,_} -> ok end, R. +-spec scan_erl_form(Epp) -> + {'ok', Tokens} | {error, ErrorInfo} | + {'warning',WarningInfo} | {'eof',Line} when + Epp :: epp_handle(), + Tokens :: erl_scan:tokens(), + Line :: erl_anno:line(), + ErrorInfo :: erl_scan:error_info() | erl_parse:error_info(), + WarningInfo :: warning_info(). + scan_erl_form(Epp) -> epp_request(Epp, scan_erl_form). @@ -230,6 +241,39 @@ format_error({warning,Term}) -> io_lib:format("-warning(~tp).", [Term]); format_error(E) -> file:format_error(E). +-spec scan_file(FileName, Options) -> + {'ok', [Form], Extra} | {error, OpenError} when + FileName :: file:name(), + Options :: [{'includes', IncludePath :: [DirectoryName :: file:name()]} | + {'source_name', SourceName :: file:name()} | + {'macros', PredefMacros :: macros()} | + {'default_encoding', DefEncoding :: source_encoding()}], + Form :: erl_scan:tokens() | {'error', ErrorInfo} | {'eof', Loc}, + Loc :: erl_anno:location(), + ErrorInfo :: erl_scan:error_info(), + Extra :: [{'encoding', source_encoding() | 'none'}], + OpenError :: file:posix() | badarg | system_limit. + +scan_file(Ifile, Options) -> + case open([{name, Ifile}, extra | Options]) of + {ok,Epp,Extra} -> + Forms = scan_file(Epp), + close(Epp), + {ok,Forms,Extra}; + {error,E} -> + {error,E} + end. + +scan_file(Epp) -> + case scan_erl_form(Epp) of + {ok,Toks} -> + [Toks|scan_file(Epp)]; + {error,E} -> + [{error,E}|scan_file(Epp)]; + {eof,Location} -> + [{eof,Location}] + end. + -spec parse_file(FileName, IncludePath, PredefMacros) -> {'ok', [Form]} | {error, OpenError} when FileName :: file:name(), diff --git a/lib/stdlib/src/erl_scan.erl b/lib/stdlib/src/erl_scan.erl index 312b040002..0fe242220f 100644 --- a/lib/stdlib/src/erl_scan.erl +++ b/lib/stdlib/src/erl_scan.erl @@ -63,7 +63,7 @@ -export_type([error_info/0, options/0, return_cont/0, - token/0, + token/0, tokens/0, tokens_result/0]). %% Removed functions and types |