LDT/User Area/Documentation Language

This documentation language has been developed as part of Koneki, its main goal is to describe the API supplied by a file. It is strongly inspired by LDoc. Information given with this language is parsed by LDT and supply advanced features such as code completion and documentation view. Before diving into syntax, it is time to enumerate the underlying concepts, knowing them will enable you to write documentation more efficiently.

Concepts

Our documentation language introduce some concepts which may not be described explicitly in Lua, but help for API description and tooling.

Type

This is the most important one. A type is a set of values, accessible through keys. Theses keys can point to functions or scalar values. A type is the representation of a table returned by a Lua module.

Module

It is simply the type returned by a file.

Field

It is always a key of type, as a field of a table returned by a module in Lua.

Function

It is a special type of field which can have parameters and return values, just as Lua functions. Both parameters and returned values can be typed. This concept allow to express a contract about which parameters suit a function and expected outputs.

Global

In Lua you can affect and read globals at anytime. To handle those cases, the predefined type global is available. It is a reserved type which will be available everywhere, enabling you to attach field and function to it.

Type references

It is often needed to refer to a type. There is a notation for this. It is based on types. So if you want to type a field or a function, they are several kinds of references available.

Primitive references

Refer to Lua primitive types, it is the type prefixed with #.

#boolean

#nil

#number

#string

#table

Internal references

Enables to refer to types defined in current module, it is type name prefixed with #.

#typename will refer to type typename defined in current module.

External references

Enables to refer to a type defined in another module, it is targeted module name followed by internal reference which could be used in targeted module.

modulename#typename will refer to type typename defined in module modulename.

modulename#modulename will refer to type modulename returned in module modulename.

Comments

It is the only source of information of our documentation language. So far, there is no inference from code. So all aspect of the API has to be described explicitly.

Special comments

First of all, only special comments are parsed as part of Lua documentation. To mark your comment as special, just start it with ---.

Special comments can contain a short and an long description. The short description start at the beginning of the comment and continue till . or ?. The long description is the text coming after. By the way, Markdown is supported in all descriptions.

Module comment block

Denoted by @module keyword and followed by a module name, a module is the type described in a file. This is why there should be only one module declaration per file. Here is the simplest way to declare a module.

Note: We used #typename to refer to a declared type, if you want to know more about it refer to type reference section.

In previous sample, you may wonder in which case it could be of any use to return manually a type for a module. It is useful when you want to return a type different from the one automatically created.

Function comment block

The function comment block has to be attached to a type. Its keyword is @function. A function can have several parameters denoted by keyword @param, they can be optionally typed and have an optional description. Several @return cases are also possible, but LDT inference -which is used for code assistance- only handles the fist one. As Lua functions allow to return several values at once, it is possible to define several returned values per @return markup. Returned values can be optionally typed.Note: If the first @param is called self, LDT will show completion proposal without this parameter but using : invocation operator.

Short references

It is way to reference a types and their fields in a textual description. You just have to surround a type reference with @{}. You can reference a types and their fields, functions are handled as a specific type of fields.

Reference to types

@{#typename} will refer to type typename defined in current module.

@{#modulename} equivalent to previous notation, as a module is the type returned by a file.

@{modulename#typename} will refer to type typename defined in module modulename.

Reference to fields

@{#typename.fieldname} will refer to fieldname which could be a function or field attached to type typename defined in current module.

@{#{type.name}.fieldname} to remove ambiguity, when type name contains ".".

@{modulename#typename.fieldname} will refer to fieldname which could be a function or field attached to type typename defined in modulename module.

Limitations

Identifiers

Due to our way of parsing, is not possible to use tag names as identifiers. So assume that the following identifiers are reserved:

field

function

module

param

return

type

Markdown

Markdown allows reusable element. As each description is parsed separately, you cannot reuse an element from another description.

Inference

So far, all information about the documented module has to be explicitly described. There is no inference enabling us to extract documentation-valuable information from the code ... yet.

Parsing

We use Metalua to parse comments, and it can't parse only comments. So if you write a documentation only file, ensure it contains a least a valid statement. Most of the time we use, return nil at end of file.

Tips

Usage

When you have a comment block related to a concept, you can give a sample of it should be used by using the @usage keyword.