NaturalDocs:: Languages:: Simple

A class containing the characteristics of a particular programming language for basic support within Natural Docs.  Also serves as a base class for languages that break from general conventions, such as not having parameter lists use parenthesis and commas.

Summary
A class containing the characteristics of a particular programming language for basic support within Natural Docs.
The class is implemented as a blessed arrayref.
Returns a new language object and adds it to NaturalDocs::Languages.
Returns the name of the language.
Returns all the possible extensions of the language’s files as an arrayref.
Returns all the possible strings that can appear in a shebang line (#!)
Returns an arrayref of symbols used to start a single line comment, or undef if none.
Returns an arrayref of symbols used to start a multi-line comment, or undef if none.
Returns an arrayref of symbols used to end a multi-line comment, or undef if none.
Returns whether the entire file should be treated as one big comment.
Returns an arrayref of the symbols that end a function prototype, or undef if not applicable.
Returns an arrayref of the symbols that end a variable declaration, or undef if not applicable.
Returns the symbol used to extend a line of code past a line break, or undef if not applicable.
Parses the passed source file, sending comments acceptable for documentation to NaturalDocs::Parser->OnComment() and all other sections to OnCode().
Called whenever a section of code is encountered by the parser.
Returns whether the language accepts prototypes from the passed <Topic Types>.
Returns the index of the end of the prototype in a string.
Strips any LineExtender() symbols out of the prototype.
Returns the index of the end of an arbitrary prototype in a string.
Returns an existence hashref of potential false positives for languages that can end a function prototype with a semicolon but also use them to separate parameters.

Implementation

Members

The class is implemented as a blessed arrayref.  The following constants are used as indexes.

NAMEThe name of the language.
EXTENSIONSAn arrayref of the all-lowercase extensions of the language’s files.
SHEBANG_STRINGSAn arrayref of the all-lowercase strings that can appear in the language’s shebang lines.
LINE_COMMENT_SYMBOLSAn arrayref of symbols that start a single line comment.  Undef if none.
OPENING_COMMENT_SYMBOLSAn arrayref of symbols that start a multi-line comment.  Undef if none.
CLOSING_COMMENT_SYMBOLSAn arrayref of symbols that ends a multi-line comment.  Undef if none.
FUNCTION_ENDERSAn arrayref of symbols that can end a function prototype.  Undef if not applicable.
VARIABLE_ENDERSAn arrayref of symbols that can end a variable declaration.  Undef if not applicable.
LINE_EXTENDERThe symbol to extend a line of code past a line break.  Undef if not applicable.

Creation Functions

New

sub New #(name,
extensions,
shebangStrings,
lineCommentSymbols,
openingCommentSymbols,
closingCommentSymbols,
functionEnders,
variableEnders,
lineExtender)

Returns a new language object and adds it to NaturalDocs::Languages.

Parameters

nameThe name of the language.
extensionsThe extensions of the language’s files.  A string or an arrayref of strings.
shebangStringsThe 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.  A string, an arrayref of strings, or undef if not applicable.
lineCommentSymbolsThe symbols that start a single-line comment.  A string, an arrayref of strings, or undef if none.
openingCommentSymbolsThe symbols that start a multi-line comment.  A string, an arrayref of strings, or undef if none.
closingCommentSymbolsThe symbols that end a multi-line comment.  A string, an arrayref of strings, or undef if none.
functionEndersThe symbols that can end a function prototype.  A string, an arrayref of strings, or undef if not applicable.
variableEndersThe symbols that can end a variable declaration.  A string, an arrayref of strings, or undef if not applicable.
lineExtenderThe symbel to extend a line of code past a line break.  A string or undef if not applicable.

Note that if neither opening/closingCommentSymbols or lineCommentSymbols are specified, the file will be interpreted as one big comment.

Information Functions

Name

sub Name

Returns the name of the language.

Extensions

sub Extensions

Returns all the possible extensions of the language’s files as an arrayref.  Each one is in all lowercase.

ShebangStrings

sub ShebangStrings

Returns all the possible strings that can appear in a shebang line (#!) of the language’s files.  It is returned as an arrayref, or undef if not applicable, and all the strings are in all lowercase.

LineCommentSymbols

sub LineCommentSymbols

Returns an arrayref of symbols used to start a single line comment, or undef if none.

OpeningCommentSymbols

sub OpeningCommentSymbols

Returns an arrayref of symbols used to start a multi-line comment, or undef if none.

ClosingCommentSymbols

sub ClosingCommentSymbols

Returns an arrayref of symbols used to end a multi-line comment, or undef if none.

FileIsComment

sub FileIsComment

Returns whether the entire file should be treated as one big comment.

FunctionEnders

sub FunctionEnders

Returns an arrayref of the symbols that end a function prototype, or undef if not applicable.

VariableEnders

sub VariableEnders

Returns an arrayref of the symbols that end a variable declaration, or undef if not applicable.

LineExtender

sub LineExtender

Returns the symbol used to extend a line of code past a line break, or undef if not applicable.

Parsing Functions

ParseFile

sub ParseFile #(sourceFile,
topicsList)

Parses the passed source file, sending comments acceptable for documentation to NaturalDocs::Parser->OnComment() and all other sections to OnCode().

Parameters

sourceFileThe name of the source file to parse.
topicListA reference to the list of NaturalDocs::Parser::ParsedTopics being built by the file.

Returns

Since this class cannot automatically document the code or generate a scope record, it always returns ( undef, undef ).

OnCode

sub OnCode #(codeLines,
codeLineNumber,
topicList,
lastCommentTopicCount)

Called whenever a section of code is encountered by the parser.  Is used to find the prototype of the last topic created.

Parameters

codeLinesThe source code as an arrayref of lines.
codeLineNumberThe line number of the first line of code.
topicListA reference to the list of NaturalDocs::Parser::ParsedTopics being built by the file.
lastCommentTopicCountThe number of Natural Docs topics that were created by the last comment.

Support Functions

HasPrototype

sub HasPrototype #(type)

Returns whether the language accepts prototypes from the passed <Topic Types>.

EndOfPrototype

sub EndOfPrototype #(type,
stringRef,
falsePositives)

Returns the index of the end of the prototype in a string.

Parameters

typeThe topic type of the prototype.
stringRefA reference to the string.
falsePositivesAn existence hashref of indexes into the string that would trigger false positives, and thus should be ignored.  This is for use by derived classes only, so set to undef.

Returns

The zero-based offset into the string of the end of the prototype, or -1 if the string doesn’t contain a symbol that would end it.

RemoveExtenders

sub RemoveExtenders #(stringRef)

Strips any LineExtender() symbols out of the prototype.

Parameters

stringRefA reference to the string.  It will be altered rather than a new one returned.

FindEndOfPrototype

sub FindEndOfPrototype #(stringRef,
falsePositives,
symbols)

Returns the index of the end of an arbitrary prototype in a string.

Parameters

stringRefA reference to the string.
falsePositivesAn existence hashref of indexes into the string that would trigger false positives, and thus should be ignored.  Undef if none.
symbolsAn arrayref of the symbols that can end the prototype.

Returns

The zero-based offset into the string of the end of the prototype, or -1 if the string doesn’t contain a symbol from the arrayref.

FalsePositivesForSemicolonsInParenthesis

sub FalsePositivesForSemicolonsInParenthesis #(stringRef)

Returns an existence hashref of potential false positives for languages that can end a function prototype with a semicolon but also use them to separate parameters.  For example:

function MyFunction( param1: type; param2, param3: type; param4: type);

It will create false positives for every semicolon appearing within parenthesis.

Parameters

stringRefThe potential function prototype.

Returns

An existence hashref of false positive indexes.  If none, will return an empty hashref.

A base class for all programming language parsers.
A subclass to handle the language variations of Pascal and Delphi.
A subclass to handle the language variations of Pascal and Delphi.
A subclass to handle the language variations of PHP.
A subclass to handle the language variations of PL/SQL.
sub New #(name,
extensions,
shebangStrings,
lineCommentSymbols,
openingCommentSymbols,
closingCommentSymbols,
functionEnders,
variableEnders,
lineExtender)
Returns a new language object and adds it to NaturalDocs::Languages.
A package to manage all the programming languages Natural Docs supports.
sub Name
Returns the name of the language.
sub Extensions
Returns all the possible extensions of the language’s files as an arrayref.
sub ShebangStrings
Returns all the possible strings that can appear in a shebang line (#!)
sub LineCommentSymbols
Returns an arrayref of symbols used to start a single line comment, or undef if none.
sub OpeningCommentSymbols
Returns an arrayref of symbols used to start a multi-line comment, or undef if none.
sub ClosingCommentSymbols
Returns an arrayref of symbols used to end a multi-line comment, or undef if none.
sub FileIsComment
Returns whether the entire file should be treated as one big comment.
sub FunctionEnders
Returns an arrayref of the symbols that end a function prototype, or undef if not applicable.
sub VariableEnders
Returns an arrayref of the symbols that end a variable declaration, or undef if not applicable.
sub LineExtender
Returns the symbol used to extend a line of code past a line break, or undef if not applicable.
sub ParseFile #(sourceFile,
topicsList)
Parses the passed source file, sending comments acceptable for documentation to NaturalDocs::Parser->OnComment() and all other sections to OnCode().
sub OnComment #(commentLines,
lineNumber)
The function called by NaturalDocs::Languages::Base-derived objects when their parsers encounter a comment suitable for documentation.
sub OnCode #(codeLines,
codeLineNumber,
topicList,
lastCommentTopicCount)
Called whenever a section of code is encountered by the parser.
sub HasPrototype #(type)
Returns whether the language accepts prototypes from the passed Topic Types.
sub EndOfPrototype #(type,
stringRef,
falsePositives)
Returns the index of the end of the prototype in a string.
sub RemoveExtenders #(stringRef)
Strips any LineExtender() symbols out of the prototype.
sub FindEndOfPrototype #(stringRef,
falsePositives,
symbols)
Returns the index of the end of an arbitrary prototype in a string.
sub FalsePositivesForSemicolonsInParenthesis #(stringRef)
Returns an existence hashref of potential false positives for languages that can end a function prototype with a semicolon but also use them to separate parameters.
A class for parsed topics of source files.