NaturalDocs:: Languages:: AdvancedNaturalDocs::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. Summary | The base class for all languages that have full support in Natural Docs. | | | | The class is implemented as a blessed arrayref. | | | | | | | | | | | | Returns the arrayref of automatically generated topics, or undef if none. | | | | Resets the automatic topic list. | | | | These functions are good general language building blocks. | | | | | | 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. | | Moves the position to the token following the next line break, or past the end of the tokens array if there is none. | | 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. | | Returns whether the position is at the first token of a line, not including whitespace. | | Returns whether the position is at the last token of a line, not including whitespace. | | Returns whether the position is at a sequence of tokens. | | Returns whether the position is after a backslash. | | These functions provide a nice scope stack implementation for language-specific parsers to use. | | Clears the scope stack for a new file. | | Records a new scope level. | | Records the end of the current scope level. | | Returns the symbol that ends the current scope level, or undef if we are at the top level. | | Returns the current calculated scope, or undef if global. | | Returns the current calculated namespace, or undef if none. | | Returns the current calculated package or class, or undef if none. | | Returns the current protection, or undef if none. | | Sets the namespace for the current scope level. | | Sets the package or class for the current scope level. | | Sets the protection for the current scope level. | | | | Adds a change to the scope record, condensing unnecessary entries. | | Converts the specified tokens into a string and returns it. |
MembersThe class is implemented as a blessed arrayref. The following constants are used as indexes. ClearTokensResets the token list. You may want to do this after parsing is over to save memory. AutoTopicsReturns the arrayref of automatically generated topics, or undef if none. Parsing FunctionsThese 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(). ParseForCommentsAndTokens| sub ParseForCommentsAndTokens # | ( | sourceFile, | | | lineCommentSymbols, openingCommentSymbols, | | | closingCommentSymbols | ) | |
|
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 - All consecutive alphanumeric and underscore characters.
- All consecutive whitespace.
- A single line break. It will always be “\n”; you don’t have to worry about platform differences.
- A single character not included above, which is usually a symbol. Multiple consecutive ones each get their own token.
The result will be placed in Tokens(). Parameters| sourceFile | The source file to load and parse. | | lineCommentSymbols | An arrayref of symbols that designate line comments, or undef if none. | | openingCommentSymbols | An arrayref of symbols that designate the start of multiline comments, or undef if none. | | closingCommentSymbols | An arrayref of symbols that designate the end of multiline comments, or undef if none. |
NotesTryToSkipString| 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. Parameters| 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. |
ReturnsWhether the position was on the passed delimiter or not. The index, line number, and content index ref variables will be updated only if true. SkipRestOfLine| 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. Parameters| indexRef | A reference to the position’s index into Tokens(). | | lineNumberRef | A reference to the position’s line number. |
SkipUntilAfter| sub SkipUntilAfter # | ( | indexRef, | | | lineNumberRef, token, 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 gof interest, such as a string delimiter, between the position and the end of the line. Parameters| 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. |
IsFirstLineTokensub IsFirstLineToken #(index) |
Returns whether the position is at the first token of a line, not including whitespace. Parameters| index | The index of the position. |
IsLastLineTokensub IsLastLineToken #(index) |
Returns whether the position is at the last token of a line, not including whitespace. Parameters| index | The index of the position. |
IsAtSequence| sub IsAtSequence # | ( | index, | | | token, token, | | | token ... | ) | |
|
Returns whether the position is at a sequence of tokens. Parameters| index | The index of the position. | | token | A token to match. Specify multiple times to specify the sequence. |
IsBackslashedsub IsBackslashed #(index) |
Returns whether the position is after a backslash. Parameters| index | The index of the postition. |
Scope FunctionsThese functions provide a nice scope stack implementation for language-specific parsers to use. The default implementation makes the following assumptions. - Namespaces and packages completely replace one another, rather than concatenating. If you call SetPackage(), it completely replaces the previous package for the current scope. You need to concatenate manually if that’s the behavior.
- Namespaces and packages inherit. So if a scope level doesn’t set its own, the namespace and package are the same as the parent scope’s.
- Protection applies to the current level only and does not inherit. So if one is not set for the current scope level, CurrentProtection() will return undef rather than the parent scope’s value.
StartScope| sub StartScope # | ( | symbol, | | | lineNumber, namespace, package, | | | protection | ) | |
|
Records a new scope level. Parameters| symbol | The closing symbol of the scope. | | lineNumber | The line number where the scope begins. | | namespace | The namespace of the scope. Undef means no change. | | package | The package or class of the scope. Undef means no change. | | protection | The protection of the scope, such as public/private/protected. Undef means no change. |
EndScopesub EndScope #(lineNumber) |
Records the end of the current scope level. Note that this is blind; you need to manually check ScopeSymbol() if you need to determine if it is correct to do so. Parameters| lineNumber | The line number where the scope ends. |
ScopeSymbolReturns the symbol that ends the current scope level, or undef if we are at the top level. CurrentNamespaceReturns the current calculated namespace, or undef if none. CurrentPackageReturns the current calculated package or class, or undef if none. CurrentProtectionReturns the current protection, or undef if none. Assumes protection doesn’t inherit like package and namespace do. SetNamespace| sub SetNamespace # | ( | namespace, | | | lineNumber | ) | |
|
Sets the namespace for the current scope level. Parameters| namespace | The new namespace. | | lineNumber | The line number the new namespace starts on. |
SetPackage| sub SetPackage # | ( | package, | | | lineNumber | ) | |
|
Sets the package or class for the current scope level. Parameters| package | The new package. | | lineNumber | The line number the new package starts on. |
SetProtection| sub SetProtection # | ( | protection, | | | lineNumber | ) | |
|
Sets the protection for the current scope level. Parameters| protection | The new protection level. | | lineNumber | The line number the new protection starts on. |
AddToScopeRecord| sub AddToScopeRecord # | ( | newScope, | | | lineNumber | ) | |
|
Adds a change to the scope record, condensing unnecessary entries. Parameters| newScope | What the scope changed to. | | lineNumber | Where the scope changed. |
CreateString| sub CreateString # | ( | startIndex, | | | endIndex | ) | |
|
Converts the specified tokens into a string and returns it. Parameters| startIndex | The starting index to convert. | | endIndex | The ending index, which is not inclusive. |
ReturnsThe string. |