fdoc: a poor man's 'edoc', or, what I stole from Lisp

Luke Gorrie <>
Wed Feb 26 23:31:40 CET 2003


Just did a kinda fun hack. The idea is a semi-automatic documentation
system that:

  1. Can be queried online
  2. Can find documentation by itself (nothing extra in Makefiles)
  3. Has a simple documentation syntax that looks good in source files

Basically, Lisp "docstrings".

The syntax I chose is: any comment appearing before a function head is
considered to be documentation for that function. Happily, this syntax
is already used by a lot of erlang code :-).

To find the documentation I have it look at the loaded modules, find
out where their sources are, and then scan the comments out of the
source files. So, it doesn't need any setup, but you may need to have
it regenerate its doc database after you load a lot of new modules.

The main interface functions are:

  apropos(Regexp): print docs for all functions matching the regexp

  describe(Mod, [Fun, [Arity]]): print docs for specific function(s)

Anyway, I hacked it up and checked it in on the Jungerl: module 'fdoc'
in the 'msc' application - it's kinda fun. The results it gets are
mixed (an incredible understatement), but here are a few
not-so-randomly-chosen examples to give the idea:

  ()220> fdoc:apropos("FIXME").
    FIXME: Currently we accept newlines in strings and handle this at
    the Tcl side. Is this the best way or should we translate to "\n"

    Returns: Font specification string in Tk format
    The input is {Family,Size} or {Family,Style,Size} where Family and
    Style are atoms ?! FIXME true???

  ()221> fdoc:describe(gen_server, call).
    Make a call to a generic server.
    If the server is located at another node, that node will
    be monitored.
    If the client is trapping exits and is linked server termination
    is handled here (? Shall we do that here (or rely on timeouts) ?).


  ()222> fdoc:describe(regexp).
    -type first_match(String, RegExp) -> matchres().
     Find the first match of RegExp in String.

    format_error(Error) -> String.

    -type gsub(String, RegExp, Replace) -> subres().
     Substitute every match of the regular expression RegExp with the
     string New in String. Accept pre-parsed regular expressions.

    -type match(String, RegExp) -> matchres().
     Find the longest match of RegExp in String.

    -type matches(String, RegExp) -> {match,[{Start,Length}]} | {error,E}.
     Return the all the non-overlapping matches of RegExp in String.

    parse(RegExp) -> {ok,RE} | {error,E}.
     Parse the regexp described in the string RegExp.

     Convert a sh style regexp into a full AWK one. The main difficulty is
     getting character sets right as the conventions are different.

    -type split(String, RegExp) -> splitres().
     Split a string into substrings where the RegExp describes the
     field seperator. The RegExp " " is specially treated.

    -type sub(String, RegExp, Replace) -> subsres().
     Substitute the first match of the regular expression RegExp with
     the string Replace in String. Accept pre-parsed regular



More information about the erlang-questions mailing list