NaturalDocs::Languages::Advanced |
The base class for all languages that have full support in Natural Docs. Each one will have a custom parser capable of documenting undocumented aspects of the code.
NaturalDocs:: | The base class for all languages that have full support in Natural Docs. |
Implementation | |
Members | The class is implemented as a blessed arrayref. |
Functions | |
New | Creates and returns a new object. |
Tokens | Returns the tokens found by ParseForCommentsAndTokens(). |
SetTokens | Replaces the tokens. |
ClearTokens | Resets the token list. |
AutoTopics | Returns the arrayref of automatically generated topics, or undef if none. |
AddAutoTopic | Adds a NaturalDocs::Parser::ParsedTopic to AutoTopics(). |
ClearAutoTopics | Resets the automatic topic list. |
ScopeRecord | Returns an arrayref of NaturalDocs::Languages::Advanced::ScopeChange objects describing how and when the scope changed thoughout the file. |
Parsing Functions | These functions are good general language building blocks. |
ParseForCommentsAndTokens | Loads the passed file, sends all appropriate comments to NaturalDocs::Parser->OnComment(), and breaks the rest into an arrayref of tokens. |
PreprocessFile | An overridable function if you’d like to preprocess the file before it goes into ParseForCommentsAndTokens(). |
TokenizeLine | Converts the passed line to tokens as described in ParseForCommentsAndTokens and adds them to Tokens(). |
TryToSkipString | If the position is on a string delimiter, moves the position to the token following the closing delimiter, or past the end of the tokens if there is none. |
SkipRestOfLine | Moves the position to the token following the next line break, or past the end of the tokens array if there is none. |
SkipUntilAfter | Moves the position to the token following the next occurance of a particular token sequence, or past the end of the tokens array if it never occurs. |
IsFirstLineToken | Returns whether the position is at the first token of a line, not including whitespace. |
IsLastLineToken | Returns whether the position is at the last token of a line, not including whitespace. |
IsAtSequence | Returns whether the position is at a sequence of tokens. |
IsBackslashed | Returns whether the position is after a backslash. |
Scope Functions | These functions provide a nice scope stack implementation for language-specific parsers to use. |
ClearScopeStack | Clears the scope stack for a new file. |
StartScope | Records a new scope level. |
EndScope | Records the end of the current scope level. |
ClosingScopeSymbol | Returns the symbol that ends the current scope level, or undef if we are at the top level. |
CurrentScope | Returns the current calculated scope, or undef if global. |
CurrentPackage | Returns the current calculated package or class, or undef if none. |
SetPackage | Sets the package for the current scope level. |
CurrentUsing | Returns the current calculated arrayref of SymbolStrings from Using statements, or undef if none. |
AddUsing | Adds a Using SymbolString to the current scope. |
Support Functions | |
AddToScopeRecord | Adds a change to the scope record, condensing unnecessary entries. |
CreateString | Converts the specified tokens into a string and returns it. |
The class is implemented as a blessed arrayref. The following constants are used as indexes.
TOKENS | An arrayref of tokens used in all the Parsing Functions. |
SCOPE_STACK | An arrayref of NaturalDocs::Languages::Advanced::Scope objects serving as a scope stack for parsing. There will always be one available, with a symbol of undef, for the top level. |
SCOPE_RECORD | An arrayref of NaturalDocs::Languages::Advanced::ScopeChange objects, as generated by the scope stack. If there is more than one change per line, only the last is stored. |
AUTO_TOPICS | An arrayref of NaturalDocs::Parser::ParsedTopics generated automatically from the code. |
sub Tokens
Returns the tokens found by ParseForCommentsAndTokens().
sub AddAutoTopic #( topic )
Adds a NaturalDocs::Parser::ParsedTopic to AutoTopics().
sub ClearAutoTopics
Resets the automatic topic list. Not necessary if you call ParseForCommentsAndTokens().
sub ScopeRecord
Returns an arrayref of NaturalDocs::Languages::Advanced::ScopeChange objects describing how and when the scope changed thoughout the file. There will always be at least one entry, which will be for line 1 and undef as the scope.
These functions are good general language building blocks. Use them to create your language-specific parser.
All functions work on Tokens() and assume it is set by ParseForCommentsAndTokens().
sub ParseForCommentsAndTokens #( FileName sourceFile, string[] lineCommentSymbols, string[] blockCommentSymbols, string[] javadocLineCommentSymbols, string[] javadocBlockCommentSymbols )
Loads the passed file, sends all appropriate comments to NaturalDocs::Parser->OnComment(), and breaks the rest into an arrayref of tokens. Tokens are defined as
The result will be placed in Tokens().
sourceFile | The source FileName to load and parse. |
lineCommentSymbols | An arrayref of symbols that designate line comments, or undef if none. |
blockCommentSymbols | An arrayref of symbol pairs that designate multiline comments, or undef if none. Symbol pairs are designated as two consecutive array entries, the opening symbol appearing first. |
javadocLineCommentSymbols | An arrayref of symbols that designate the start of a JavaDoc comment, or undef if none. |
javadocBlockCommentSymbols | An arrayref of symbol pairs that designate multiline JavaDoc comments, or undef if none. |
sub PreprocessFile #( lines )
An overridable function if you’d like to preprocess the file before it goes into ParseForCommentsAndTokens().
lines | An arrayref to the file’s lines. Each line has its line break stripped off, but is otherwise untouched. |
sub TokenizeLine #( line )
Converts the passed line to tokens as described in ParseForCommentsAndTokens and adds them to Tokens(). Also adds a line break token after it.
sub TryToSkipString #( indexRef, lineNumberRef, openingDelimiter, closingDelimiter, startContentIndexRef, endContentIndexRef )
If the position is on a string delimiter, moves the position to the token following the closing delimiter, or past the end of the tokens if there is none. Assumes all other characters are allowed in the string, the delimiter itself is allowed if it’s preceded by a backslash, and line breaks are allowed in the string.
indexRef | A reference to the position’s index into Tokens(). |
lineNumberRef | A reference to the position’s line number. |
openingDelimiter | The opening string delimiter, such as a quote or an apostrophe. |
closingDelimiter | The closing string delimiter, if different. If not defined, assumes the same as openingDelimiter. |
startContentIndexRef | A reference to a variable in which to store the index of the first token of the string’s content. May be undef. |
endContentIndexRef | A reference to a variable in which to store the index of the end of the string’s content, which is one past the last index of content. May be undef. |
Whether the position was on the passed delimiter or not. The index, line number, and content index ref variables will be updated only if true.
sub SkipRestOfLine #( indexRef, lineNumberRef )
Moves the position to the token following the next line break, or past the end of the tokens array if there is none. Useful for line comments.
Note that it skips blindly. It assumes there cannot be anything of interest, such as a string delimiter, between the position and the end of the line.
indexRef | A reference to the position’s index into Tokens(). |
lineNumberRef | A reference to the position’s line number. |
sub SkipUntilAfter #( indexRef, lineNumberRef, token, token, ... )
Moves the position to the token following the next occurance of a particular token sequence, or past the end of the tokens array if it never occurs. Useful for multiline comments.
Note that it skips blindly. It assumes there cannot be anything of interest, such as a string delimiter, between the position and the end of the line.
indexRef | A reference to the position’s index. |
lineNumberRef | A reference to the position’s line number. |
token | A token that must be matched. Can be specified multiple times to match a sequence of tokens. |
These functions provide a nice scope stack implementation for language-specific parsers to use. The default implementation makes the following assumptions.
sub ClearScopeStack
Clears the scope stack for a new file. Not necessary if you call ParseForCommentsAndTokens().
sub StartScope #( closingSymbol, lineNumber, package )
Records a new scope level.
closingSymbol | The closing symbol of the scope. |
lineNumber | The line number where the scope begins. |
package | The package SymbolString of the scope. Undef means no change. |
sub EndScope #( lineNumber )
Records the end of the current scope level. Note that this is blind; you need to manually check ClosingScopeSymbol() if you need to determine if it is correct to do so.
lineNumber | The line number where the scope ends. |
sub CurrentScope
Returns the current calculated scope, or undef if global. The default implementation just returns CurrentPackage(). This is a separate function because C++ may need to track namespaces and classes separately, and so the current scope would be a concatenation of them.
sub SetPackage #( package, lineNumber )
Sets the package for the current scope level.
package | The new package SymbolString. |
lineNumber | The line number the new package starts on. |
sub CurrentUsing
Returns the current calculated arrayref of SymbolStrings from Using statements, or undef if none.
sub AddUsing #( using )
Adds a Using SymbolString to the current scope.
sub AddToScopeRecord #( newScope, lineNumber )
Adds a change to the scope record, condensing unnecessary entries.
newScope | What the scope SymbolString changed to. |
lineNumber | Where the scope changed. |
Creates and returns a new object.
sub New #( name )
Returns the tokens found by ParseForCommentsAndTokens().
sub Tokens
Loads the passed file, sends all appropriate comments to NaturalDocs::Parser->OnComment(), and breaks the rest into an arrayref of tokens.
sub ParseForCommentsAndTokens #( FileName sourceFile, string[] lineCommentSymbols, string[] blockCommentSymbols, string[] javadocLineCommentSymbols, string[] javadocBlockCommentSymbols )
Replaces the tokens.
sub SetTokens #( tokens )
Resets the token list.
sub ClearTokens
Returns the arrayref of automatically generated topics, or undef if none.
sub AutoTopics
Adds a NaturalDocs::Parser::ParsedTopic to AutoTopics().
sub AddAutoTopic #( topic )
Resets the automatic topic list.
sub ClearAutoTopics
Returns an arrayref of NaturalDocs::Languages::Advanced::ScopeChange objects describing how and when the scope changed thoughout the file.
sub ScopeRecord
The function called by NaturalDocs::Languages::Base-derived objects when their parsers encounter a comment suitable for documentation.
sub OnComment #( string[] commentLines, int lineNumber, bool isJavaDoc )
An overridable function if you’d like to preprocess the file before it goes into ParseForCommentsAndTokens().
sub PreprocessFile #( lines )
Converts the passed line to tokens as described in ParseForCommentsAndTokens and adds them to Tokens().
sub TokenizeLine #( line )
If the position is on a string delimiter, moves the position to the token following the closing delimiter, or past the end of the tokens if there is none.
sub TryToSkipString #( indexRef, lineNumberRef, openingDelimiter, closingDelimiter, startContentIndexRef, endContentIndexRef )
Moves the position to the token following the next line break, or past the end of the tokens array if there is none.
sub SkipRestOfLine #( indexRef, lineNumberRef )
Moves the position to the token following the next occurance of a particular token sequence, or past the end of the tokens array if it never occurs.
sub SkipUntilAfter #( indexRef, lineNumberRef, token, token, ... )
Returns whether the position is at the first token of a line, not including whitespace.
sub IsFirstLineToken #( index )
Returns whether the position is at the last token of a line, not including whitespace.
sub IsLastLineToken #( index )
Returns whether the position is at a sequence of tokens.
sub IsAtSequence #( index, token, token, token ... )
Returns whether the position is after a backslash.
sub IsBackslashed #( index )
Clears the scope stack for a new file.
sub ClearScopeStack
Records a new scope level.
sub StartScope #( closingSymbol, lineNumber, package )
Records the end of the current scope level.
sub EndScope #( lineNumber )
Returns the symbol that ends the current scope level, or undef if we are at the top level.
sub ClosingScopeSymbol
Returns the current calculated scope, or undef if global.
sub CurrentScope
Returns the current calculated package or class, or undef if none.
sub CurrentPackage
Sets the package for the current scope level.
sub SetPackage #( package, lineNumber )
Returns the current calculated arrayref of SymbolStrings from Using statements, or undef if none.
sub CurrentUsing
Adds a Using SymbolString to the current scope.
sub AddUsing #( using )
Adds a change to the scope record, condensing unnecessary entries.
sub AddToScopeRecord #( newScope, lineNumber )
Converts the specified tokens into a string and returns it.
sub CreateString #( startIndex, endIndex )