Customizing Languages Index Prefixes · Adding Languages · File Extensions Prototypes · Special Languages · Syntax Reference Natural Docs has two files called 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. Natural Docs will keep an up-to-date list of all the languages defined in the main file in it so you can override their settings easily. However, if you’re using Natural Docs with a lot of projects and would like the changes to apply everywhere, you can edit the one in Natural Docs’ Config directory instead. Most of the text here will assume you’re editing the project one, so be sure to read the boxes at the end that explain the differences. Note that unlike other Natural Docs configuration files, comments can only appear on their own lines. They cannot appear after content on the same line because settings may need to use the Index Prefixes Natural Docs has the ability to ignore prefixes in the indexes. This is necessary because in certain languages, variables are prefixed with
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:
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 Alter Language: [your language] Add Ignored Class Prefix in Index: C Add Ignored Function Prefixes in Index: COM_ DB_ Note that only one prefix will ever be removed, so if you have variable names that start with One last tip: Do this for common hierarchy levels. For example, all of Natural Docs’ internal packages are under a top-level NaturalDocs package, so it’s package index ignores “ To do this in the main languages file instead of the user one, find the existing definition and either edit the “ 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 ( 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. File Extensions So Natural Docs doesn’t recognize some file extension you use for your code? No problem. Alter Language: [your language] Add Extensions: cxx hxx 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. To do this in the main languages file instead of the user one, find the existing language definition and add or remove from the existing “ 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 topic 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. Line Breaks For some languages, line breaks are significant. To have them end a prototype, use 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, which is explained in the Common Customizations section of the CSS Styles page. Special Languages There are two languages with special properties: Shebang Script and Text File. In Shebang Scripts, the language is not determined by the file extension but by the shebang ( In Text Files, 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 However, since it is possible to document classes, functions, etc. in text files, they also have their own Syntax Reference Unlike other Natural Docs configuration files, comments can only appear on their own lines. They cannot appear after content on the same line because settings may need to use the Singular and plural forms are generally both supported, so you can write 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. “ 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 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. “ Shebang Strings: [string] [string] ... [Add/Replace] Shebang Strings: [string] [string] ... Defines a list of strings that can appear in the shebang ( 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 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. “ 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. “ Enum Values: [global|under type|under parent] Defines the behavior of enum values. The default is global.
[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 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-2005 Greg Valure |