Search code examples
documentationd

Does D support documentation generation?


Many modern programming languages support a system of comments as documentation strings.

This feature is taken for granted in languages like Python or Clojure, where documentation strings may be useful in understanding the purpose of a function that might be unclear otherwise:

def gen_ast(s):
    ''' given a string, s, representing a program, generates object model of abstract syntax tree '''
    # function contents here ...

I am fairly novice in D programming, but have not yet found documentation for writing documentation string comments in a way that's accessible to the client (e.g., help(gen_ast) in Python). Does D provide support for docstrings?


Solution

  • Yes.

    For code itself: http://dlang.org/spec/ddoc.html

    For options on the command line: http://dlang.org/phobos/std_getopt.html

    To get from the code: http://dlang.org/spec/attribute.html#uda

    However, it is fair to pout out that the doc comment is not accessible directly in code - you will have to do it as a UDA or getopt library documentation string, or have a separate command in your build set to extract the comments (dmd -D makes them into html, dmd -D -X will make them into json, then you parse that)