Customizing Languages
Languages.txt

Natural Docs has two files called `Languages.txt`: one in its Config directory, and one in your project directory. These control the language, index prefix, and prototype features of Natural Docs.

You should edit the one in your project directory whenever possible. It keeps your changes separate and easier to manage, plus you don’t have to reapply them whenever you upgrade. Editing the one in Natural Docs’ Config directory would be better only if you’re using Natural Docs with a lot of projects and would like the changes to apply everywhere.

Note that unlike other Natural Docs configuration files, comments can only appear on their own lines. They cannot appear after something else on a line because settings may need to use the `#` symbol. Also, all lists are space-separated instead of comma-separated, again because some settings may need to use the comma symbol.

File Extensions

If Natural Docs doesn’t recognize a file extension you use for your code, it’s not a problem. You can alter the language definition from your project file to add them.

    Alter Language: [your language]
       Add Extensions: cxx hxx

On the other hand, if it’s scanning some files you don’t want it to scan, you can exclude extensions as well. Just add this to the top of your file:

    Ignore Extensions: c cpp

In this example, Natural Docs will ignore C++ source files, thus only scanning the headers.

Adding Languages

You can add basic language support for any programming language just by editing these configuration files. Here are the most important settings:

    Language: Fictional

       Extensions: fsrc fhdr
       Shebang Strings: fictional
       Line Comment: //
       Block Comment: /* */
       Package Separator: ::

This tells Natural Docs that any files with the .fsrc or .fhdr extensions are part of our fictional programming language. Also, any .cgi or extensionless files that have “fictional” in the shebang (`#!`) line are part of it as well. Line comments start with `//` and block comments appear between `/*` and `*/`. The default package separator is `::`. Not too hard, huh?

You can also add settings to ignore prefixes in the index and detect prototypes, but those are dealt with in their own sections on this page.

Prototypes

So you’ve added a new language and want to detect prototypes. Or perhaps you added a custom topic type and want to detect prototypes for that as well. Here’s an example of the properties you need:

    Function Prototype Enders: ; {
    Variable Prototype Enders: ; =

The algorithm for finding prototypes is very simple, yet it works really well in practice. All the code following the comment is grabbed until it reaches an ender symbol or another comment. Ender symbols appearing inside parenthesis, brackets, braces, or angle brackets don’t count. If it reaches an ender symbol and somewhere in that code is the topic title, the code is accepted as the prototype.

So in the example above, variables end at semicolons (the end of the declaration) or equal signs (the default value expression, which we don’t want to include.) Since the Natural Docs comment for the variable should have appeared right before the definition, that leaves us with the name and type. Functions are handled similarly: they end at a semicolon (the end of a predeclaration) or an opening brace (the beginning of the body) leaving us with the name, parameters, and return type.

You can do this with any topic type, including custom ones. Any prototypes that look like they have parameters will be formatted as such automatically.

Line Breaks

For some languages, line breaks are significant. To have them end a prototype, use `\n`. If it has an extender symbol that allows the code to continue on the next line, you can specify that as well.

    Function Prototype Ender: \n
    Variable Prototype Ender: \n =
    Line Extender: _

Colors

If you’re collecting prototypes for a custom topic type, they will not automatically get their own background color like the other types have. You have to define it via CSS.

Index Prefixes

Natural Docs has the ability to ignore prefixes in the indexes. This is necessary because in certain languages, variables are prefixed with `$` or other symbols and we don’t want them to get all grouped together under the symbols heading. Instead, they appear in the sidebar and are sorted as if they’re not there.

A |
| AddProperty, SomeClass
$ | amount
| Average

However, we can take advantage of this simply to get around coding conventions. Suppose you prefix all your class names with C. They’d all form one gigantic group under C in the index. If you want, you can have it ignored so CCat, CDog, and CMouse get filed under C, D, and M instead. Just add this to your languages file:

    Alter Language: [your language]
       Add Ignored Class Prefix in Index: C

Now C is ignored in your indexes:

A |
C | Account
C | AccountHolder
| AddProperty, SomeClass
$ | amount
| Average

You can include any number of prefixes and can do this for any topic type. So if you have a bunch of functions that start with `COM_` and `DB_`, you can ignore them too:

    Alter Language: [your language]
       Add Ignored Class Prefix in Index: C
       Add Ignored Function Prefixes in Index: COM_ DB_

Special Languages

There are two languages with special properties: Shebang Script and Text File.

Shebang Script allows you to define the file extensions where the language is really determined by the shebang (`#!`) line within it. For example, .cgi files. If Natural Docs finds a .cgi file, it sees that it’s a Shebang Script so it opens it up to parse it’s shebang line. It then searches it for substrings defined by other languages’ `Shebang String` settings to find out what language it really is. Files with no extension are always treated this way.

With Text File, the entire file is treated like a comment. There are no comment symbols required, you can just put Natural Docs content there in plain text. The most important setting is `Extensions`.

However, since it is possible to document classes, functions, etc. in text files, they also have their own `Package Separator` and `Ignored [type] Prefixes in Index` settings. To make things easier on you, by default it copies these settings from whichever language has the most source files in your project. You can override this by manually setting them, but you shouldn’t need to.

Syntax Reference

Unlike other Natural Docs configuration files, comments can only appear on their own lines. They cannot appear after something else on a line because settings may need to use the `#` symbol. Likewise, lists are separated with spaces instead of commas because commas themselves may need to appear on the list.

Singular and plural forms are generally both supported, so you can write `Extension` or `Extensions`. It doesn’t matter if they match how many items are set. Also, you can use either `Ignore` or `Ignored`.

    Ignore Extensions: [extension] [extension] ...

Causes the listed file extensions to be ignored, even if they were previously defined to be part of a language. The list is space-separated. ex. “`Ignore Extensions: cvs txt`”

    Language: [name]
    Alter Language: [name]

Creates a new language or alters an existing one. Names can use any characters. Note the special behavior for languages named Shebang Script and Text File.

If you’re altering an existing language and a property has an `[Add/Replace]` form, you have to specify whether you’re adding to or replacing the list if that property has already been defined.

General Language Properties

    Extensions: [extension] [extension] ...
    [Add/Replace] Extensions: [extension] [extension] ...

Defines file extensions for the language’s source files. The list is space-separated. ex. “`Extensions: c cpp`”. You can use extensions that were previously used by another language to redefine them. You can use `*` to specify all undefined extensions.

    Shebang Strings: [string] [string] ...
    [Add/Replace] Shebang Strings: [string] [string] ...

Defines a list of strings that can appear in the shebang (`#!`) line to designate that it’s part of this language. They can appear anywhere in the line, so `php` will work for “`#!/user/bin/php4`”. You can use strings that were previously used by another language to redefine them.

    Ignore Prefixes in Index: [prefix] [prefix] ...
    Ignore [type] Prefixes in Index: [prefix] [prefix] ...

    [Add/Replace] Ignored Prefixes in Index: [prefix] [prefix] ...
    [Add/Replace] Ignored [type] Prefixes in Index: [prefix] [prefix] ...

Specifies prefixes that should be ignored when sorting symbols for an index. Can be specified in general or for a specific topic type. The prefixes will still appear, the symbols will just be sorted as if they’re not there. For example, specifying `ADO_` for functions will mean that `ADO_DoSomething` will appear under D instead of A.

Basic Language Support Properties

These attributes are only available for languages with basic language support.

    Line Comments: [symbol] [symbol] ...

Defines a space-separated list of symbols that are used for line comments, if any. ex. “`Line Comment: //`”.

    Block Comments: [opening symbol] [closing symbol] [o.s.] [c.s.] ...

Defines a space-separated list of symbol pairs that are used for block comments, if any. ex. “`Block Comment: /* */`”.

    Enum Values: [global|under type|under parent]

Defines the behavior of enum values. The default is global.

Global | Enum values are always global and will be referenced as “Value”.
Under Type | Enum values appear under the type and will be referenced as “Package.Enum.Value”.
Under Parent | Enum values appear under the parent and will be referenced as “Package.Value”

    [type] Prototype Enders: [symbol] [symbol] ...

When defined, Natural Docs will attempt to collect prototypes from the code following the specified topic type. It grabs code until the first ender symbol or the next Natural Docs comment, and if it contains the topic name, it serves as its prototype. Use `\n` to specify a line break. ex. “`Function Prototype Enders: { ;`”, “`Variable Prototype Enders: = ;`”.

    Line Extender: [symbol]

Defines the symbol that allows a prototype to span multiple lines if normally a line break would end it.

    Perl Package: [perl package]

Specifies the Perl package used to fine-tune the language behavior in ways too complex to do in this file.

Full Language Support Properties

These attributes are only available for languages with full language support.

    Full Language Support: [perl package]

Specifies the Perl package that has the parsing routines necessary for full language support.

| Copyright © 2003-2008 Greg Valure