NaturalDocs:: Languages

A package to manage all the programming languages Natural Docs supports. 

Usage and Dependencies

Summary
A package to manage all the programming languages Natural Docs supports.
An array of all the defined languages.
A hash of all the defined languages’ extensions.
A hash of all the defined languages’ strings to search for in the shebang (#!)
Returns the language of the passed source file.
Returns whether the language of the passed file is supported.
Separates a class from its member.
Adds a language to the package.

Variables

languages

my @languages

An array of all the defined languages.  Each entry is a NaturalDocs::Languages::Language object. 

extensions

my %extensions

A hash of all the defined languages’ extensions.  The keys are the all-lowercase extensions, and the values are indexes into languages

shebangs

my %shebangs

A hash of all the defined languages’ strings to search for in the shebang (#!) line.  The keys are the all-lowercase strings, and the values are indexes into languages

Functions

LanguageOf

sub LanguageOf #(file)

Returns the language of the passed source file. 

Parameters

fileThe source file to get the language of. 

Returns

A NaturalDocs::Languages::Language object for the passed file, or undef if the file is not a recognized language. 

IsSupported

sub IsSupported #(file)

Returns whether the language of the passed file is supported. 

Parameters

fileThe file to test. 

Returns

Whether the file’s language is supported. 

SeparateMember

sub SeparateMember #(string)

Separates a class from its member.  If there are multiple member separators in the string, it assumes the last one is correct and all previous ones are part of the class name.  For example, “package::class::function” will be split into “package::class” and “function”. 

Parameters

stringThe string of text to separate. 

Returns

An array.  If the string had a member separator in it, the first item will be the class and the second the identifier.  If there was no member separator, there will only be one item, which will contain the original string. 

Support Functions

Add

sub Add #(name, extensions, shebangStrings, lineComment, startComment, endComment, functionEnders, variableEnders)

Adds a language to the package. 

Parameters

nameThe name of the language. 
extensionsAn arrayref of the extensions of the language’s files. 
shebangStringsAn arrayref of the strings to search for in the #! line of the language’s files.  Only used when the file has a .cgi extension or no extension at all.  Undef if not applicable. 
lineCommentThe symbol that starts a single line comment.  Undef if none. 
startCommentThe symbol that starts a multi-line comment.  Undef if none. 
endCommentThe symbol that ends a multi-line comment.  Undef if none. 
functionEndersAn arrayref of symbols that end a function prototype.  Include “\n” if necessary.  Undef if the language doesn’t have functions. 
variableEndersAn arrayref of symbols that end a variable declaration.  Include “\n” if necessary.  Undef if the doesn’t have variables. 

Note that if neither of the comment styles are specified, it is assumed that the entire file should be treated as a comment.