edoc.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 772 行 · 第 1/2 页

ERL
772
字号
    Ctxt1 = Ctxt#context{env = Env},    Cmd = #doclet_gen{sources = Ss1,		      app = App1,		      packages = Ps2,		      modules = Ms2,		      filemap = Fs		     },    F = fun (M) ->		M:run(Cmd, Ctxt1)	end,    edoc_lib:run_doclet(F, Opts).expand_opts(Opts0) ->    proplists:substitute_negations(opt_negations(),				   Opts0 ++ opt_defaults()).%% NEW-OPTIONS: dir%% DEFER-OPTIONS: run/3init_context(Opts) ->    #context{dir = proplists:get_value(dir, Opts, ?CURRENT_DIR),	     opts = Opts	    }.%% INHERIT-OPTIONS: edoc_lib:find_sources/3sources(Path, Packages, Opts) ->    lists:foldl(fun (P, Xs) ->			edoc_lib:find_sources(Path, P, Opts) ++ Xs		end,		[], Packages).package_files(Path, Packages) ->    Name = ?PACKAGE_FILE,    % this is hard-coded for now    D = lists:foldl(fun (P, D) ->			    F = edoc_lib:find_file(Path, P, Name),			    dict:store(P, F, D)		    end,		    dict:new(), Packages),    fun (P) ->	    case dict:find(P, D) of		{ok, F} -> F;		error -> ""	    end    end.%% Expand user-specified sets of files.expand_files([{P, Fs1} | Fs]) ->    [{P, filename:basename(F), filename:dirname(F)} || F <- Fs1]	++ expand_files(Fs);expand_files([F | Fs]) ->    [{'', filename:basename(F), filename:dirname(F)} |     expand_files(Fs)];expand_files([]) ->    [].%% Create the (assumed) full module names. Keep only the first source%% for each module, but preserve the order of the list.%% NEW-OPTIONS: source_suffix, packages%% DEFER-OPTIONS: run/3expand_sources(Ss, Opts) ->    Suffix = proplists:get_value(source_suffix, Opts,				 ?DEFAULT_SOURCE_SUFFIX),    Ss1 = case proplists:get_bool(packages, Opts) of	      true -> Ss;	      false -> [{'',F,D} || {_P,F,D} <- Ss]	  end,    expand_sources(Ss1, Suffix, sets:new(), [], []).expand_sources([{P, F, D} | Fs], Suffix, S, As, Ms) ->    M = list_to_atom(packages:concat(P, filename:rootname(F, Suffix))),    case sets:is_element(M, S) of	true ->	    expand_sources(Fs, Suffix, S, As, Ms);	false ->	    S1 = sets:add_element(M, S),	    expand_sources(Fs, Suffix, S1, [{M, P, F, D} | As],			   [M | Ms])    end;expand_sources([], _Suffix, _S, As, Ms) ->    {lists:reverse(As), lists:reverse(Ms)}.%% NEW-OPTIONS: newtarget_dir_info(Dir, App, Ps, Ms, Opts) ->    case proplists:get_bool(new, Opts) of	true ->	    {App, Ps, Ms};	false ->	    {App1, Ps1, Ms1} = edoc_lib:read_info_file(Dir),	    {if App == ?NO_APP -> App1;		true -> App	     end,	     Ps ++ Ps1,	     Ms ++ Ms1}    end.%% @hidden   Not official yettoc(Dir) ->    toc(Dir, []).%% @equiv toc(Dir, Paths, [])%% @hidden   Not official yet%% NEW-OPTIONS: doc_pathtoc(Dir, Opts) ->    Paths = proplists:append_values(doc_path, Opts)	++ edoc_lib:find_doc_dirs(),    toc(Dir, Paths, Opts).%% @doc Create a meta-level table of contents.%% @hidden   Not official yet%% INHERIT-OPTIONS: init_context/1%% INHERIT-OPTIONS: edoc_lib:run_doclet/2%% INHERIT-OPTIONS: edoc_lib:get_doc_env/4toc(Dir, Paths, Opts0) ->    Opts = expand_opts(Opts0 ++ [{dir, Dir}]),    Ctxt = init_context(Opts),    Env = edoc_lib:get_doc_env('', [], [], Opts),    Ctxt1 = Ctxt#context{env = Env},    F = fun (M) ->		M:run(#doclet_toc{paths=Paths}, Ctxt1)	end,    edoc_lib:run_doclet(F, Opts).%% @spec read(File::filename()) -> string()%% @equiv read(File, [])read(File) ->    read(File, []).%% @spec read(File::filename(), Options::proplist()) -> string()%%%% @doc Reads and processes a source file and returns the resulting%% EDoc-text as a string. See {@link get_doc/2} and {@link layout/2} for%% options.%%%% @see file/2%% INHERIT-OPTIONS: get_doc/2, layout/2read(File, Opts) ->    {_ModuleName, Doc} = get_doc(File, Opts),    layout(Doc, Opts).%% @spec layout(Doc::edoc_module()) -> string()%% @equiv layout(Doc, [])layout(Doc) ->    layout(Doc, []).%% @spec layout(Doc::edoc_module(), Options::proplist()) -> string()%%%% @doc Transforms EDoc module documentation data to text. The default%% layout creates an HTML document.%%%% Options:%% <dl>%%  <dt>{@type {layout, Module::atom()@}}%%  </dt>%%  <dd>Specifies a callback module to be used for formatting. The%%      module must export a function `module(Doc, Options)'. The%%      default callback module is {@link edoc_layout}; see {@link%%      edoc_layout:module/2} for layout-specific options.%%  </dd>%% </dl>%%%% @see layout/1%% @see run/3%% @see read/2%% @see file/2%% INHERIT-OPTIONS: edoc_lib:run_layout/2layout(Doc, Opts) ->    F = fun (M) ->		M:module(Doc, Opts)	end,    edoc_lib:run_layout(F, Opts).%% @spec (File) ->  [comment()]%% @equiv read_comments(File, [])read_comments(File) ->    read_comments(File, []).%% @spec read_comments(File::filename(), Options::proplist()) ->%%           [comment()]%% where%%   comment() = {Line, Column, Indentation, Text},%%   Line = integer(),%%   Column = integer(),%%   Indentation = integer(),%%   Text = [string()]%%%% @doc Extracts comments from an Erlang source code file. See the%% module {@link //syntax_tools/erl_comment_scan} for details on the%% representation of comments. Currently, no options are avaliable.read_comments(File, _Opts) ->    erl_comment_scan:file(File).%% @spec (File) -> [syntaxTree()]%% @equiv read_source(File, [])read_source(Name) ->    read_source(Name, []).%% @spec read_source(File::filename(), Options::proplist()) ->%%           [syntaxTree()]%%%% @type syntaxTree() = //syntax_tools/erl_syntax:syntaxTree()%%%% @doc Reads an Erlang source file and returns the list of "source code%% form" syntax trees.%%%% Options:%% <dl>%%  <dt>{@type {preprocess, bool()@}}%%  </dt>%%  <dd>If the value is `true', the source file will be read via the%%      Erlang preprocessor (`epp'). The default value is `false'.%%      `no_preprocess' is an alias for `{preprocess, false}'.%%%%      Normally, preprocessing is not necessary for EDoc to work, but%%      if a file contains too exotic definitions or uses of macros, it%%      will not be possible to read it without preprocessing. <em>Note:%%      comments in included files will not be available to EDoc, even%%      with this option enabled.</em>%%  </dd>%%  <dt>{@type {includes, Path::[string()]@}}%%  </dt>%%  <dd>Specifies a list of directory names to be searched for include%%      files, if the `preprocess' option is turned on. Also used with%%      the `@headerfile' tag. The default value is the empty list. The%%      directory of the source file is always automatically appended to%%      the search path.%%  </dd>%%  <dt>{@type {macros, [{atom(), term()@}]@}}%%  </dt>%%  <dd>Specifies a list of pre-defined Erlang preprocessor (`epp')%%      macro definitions, used if the `preprocess' option is turned on.%%      The default value is the empty list.</dd>%% </dl>%%%% @see get_doc/2%% @see //syntax_tools/erl_syntax%% NEW-OPTIONS: [no_]preprocess (preprocess -> includes, macros)read_source(Name, Opts0) ->    Opts = expand_opts(Opts0),    case read_source_1(Name, Opts) of	{ok, Forms} ->	    check_forms(Forms, Name),	    Forms;	{error, R} ->	    error({"error reading file '~s'.",		   [edoc_lib:filename(Name)]}),	    exit({error, R})    end.read_source_1(Name, Opts) ->    case proplists:get_bool(preprocess, Opts) of	true ->	    read_source_2(Name, Opts);	false ->	    epp_dodger:quick_parse_file(Name, Opts ++ [{no_fail, false}])    end.read_source_2(Name, Opts) ->    Includes = proplists:append_values(includes, Opts)	++ [filename:dirname(Name)],    Macros = proplists:append_values(macros, Opts),    epp:parse_file(Name, Includes, Macros).check_forms(Fs, Name) ->    Fun = fun (F) ->	     case erl_syntax:type(F) of		 error_marker ->		     case erl_syntax:error_marker_info(F) of			 {L, M, D} ->			     error(L, Name, {format_error, M, D});			 Other ->			     report(Name, "unknown error in "				    "source code: ~w.", [Other])		     end,		     exit(error);		 _ ->		     ok	     end	  end,    lists:foreach(Fun, Fs).%% @spec get_doc(File::filename()) -> {ModuleName, edoc_module()}%% @equiv get_doc(File, [])get_doc(File) ->    get_doc(File, []).%% @spec get_doc(File::filename(), Options::proplist()) ->%%           {ModuleName, edoc_module()}%%	ModuleName = atom()%%%% @type edoc_module(). The EDoc documentation data for a module,%% expressed as an XML document in {@link //xmerl. XMerL} format. See%% the file <a href="../priv/edoc.dtd">`edoc.dtd'</a> for details.%%%% @doc Reads a source code file and extracts EDoc documentation data.%% Note that without an environment parameter (see {@link get_doc/3}),%% hypertext links may not be correct.%%%% Options:%% <dl>%%  <dt>{@type {def, Macros@}}%%  </dt>%%  <dd><ul>%%       <li>`Macros' = {@type Macro | [Macro]}</li>%%       <li>`Macro' = {@type {Name::atom(), Text::string()@}}</li>%%      </ul>%%    Specifies a set of EDoc macro definitions. See%%    <a href="overview-summary.html#Macro_expansion">Inline macro expansion</a>%%    for details.%%  </dd>%%  <dt>{@type {hidden, bool()@}}%%  </dt>%%  <dd>If the value is `true', documentation of hidden functions will%%      also be included. The default value is `false'.%%  </dd>%%  <dt>{@type {private, bool()@}}%%  </dt>%%  <dd>If the value is `true', documentation of private functions will%%      also be included. The default value is `false'.%%  </dd>%%  <dt>{@type {todo, bool()@}}%%  </dt>%%  <dd>If the value is `true', To-Do notes written using `@todo' or%%  `@TODO' tags will be included in the documentation. The default%%  value is `false'.%%  </dd>%% </dl>%%%% See {@link read_source/2}, {@link read_comments/2} and {@link%% edoc_lib:get_doc_env/4} for further options.%%%% @see get_doc/3%% @see run/3%% @see edoc_extract:source/5%% @see read/2%% @see layout/2%% INHERIT-OPTIONS: get_doc/3%% INHERIT-OPTIONS: edoc_lib:get_doc_env/4get_doc(File, Opts) ->    Env = edoc_lib:get_doc_env(Opts),    get_doc(File, Env, Opts).%% @spec get_doc(File::filename(), Env::edoc_lib:edoc_env(),%%        Options::proplist()) -> {ModuleName, edoc_module()}%%     ModuleName = atom()%%%% @doc Like {@link get_doc/2}, but for a given environment%% parameter. `Env' is an environment created by {@link%% edoc_lib:get_doc_env/4}.%% INHERIT-OPTIONS: read_source/2, read_comments/2, edoc_extract:source/5%% DEFER-OPTIONS: get_doc/2get_doc(File, Env, Opts) ->    edoc_extract:source(File, Env, Opts).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?