Class AMiniScanner
Unit
classwork
Declaration
type AMiniScanner = class(AnIterator)
Description
This class represents a miniature scanner. It is primarily designed to scan text input streams for custom format specifiers, but can be used wherever a full-fledged scanner and tokenizer is not required.
The scanner tokenizes by reading a single character from the source stream. It then compares this character with those provided in its lists of recognized digits, letters, and special characters. If a match is found, it continues collecting characters until a different character is found. The collected token is then checked to see whether it is a valid integer or floating-point value, and if it matches the list of recognized tokens.
Hierarchy
Overview
Fields
Methods
Description
Fields
|
myOwnSource: boolean; |
Indicates whether or not the scanner owns its source
|
|
myRecognizedDigits: string; |
Stores a list of characters that represent digits
|
|
myRecognizedLetters: string; |
Stores a list of characters that represent letters
|
|
myRecognizedSpecialCharacters: string; |
Stores a list of characters that represent special characters
|
|
MyRecognizedTokens: AStringTree; |
Refers to a list of recognized tokens
|
|
myPreviousToken: TMiniToken; |
Stores the previous token read from the source
|
|
myCurrentToken: TMiniToken; |
Stores the most recent token read from the source
|
Methods
|
procedure collectNumericToken; virtual; |
Collect a numeric token from the source.
This method is called automatically by AMiniScanner.nextToken when it encounters a character in the source that matches one of the characters in Self.recognizedDigits. The routine collects characters until it encounters a character which is not a recognized digit.
|
|
procedure collectWordToken; virtual; |
Collect a "word".
This method is called automatically by AMiniScanner.nextToken when it encounters a character in the source that matches one of the characters in Self.recognizedLetters. The routine collects characters until it encounters a character which is not a recognized letter.
|
|
procedure collectSpecialToken; virtual; |
Collect a sequence of special characters.
This method is called automatically by AMiniScanner.nextToken when it encounters a character in the source that matches one of the characters in Self.recognizedSpecialCharacters. The routine collects characters until it encounters a character which is not a recognized special character. It then returns characters to the source until it finds a match in Self.RecognizedTokens or until there is only one character left.
|
|
constructor forSource(const ThisTarget: ATextInputStream; const takeOwnershipOfTarget: boolean = true); virtual; |
Construct a new instance of AMiniScanner that will scan the specified stream for tokens.
If takeOwnershipOfTarget is True , then the scanner will assume ownership of ThisTarget and will free the stream when the scanner is, itself, freed.
|
|
constructor forString(const thisString: string); virtual; |
Construct a new instance of AMiniScanner that will scan the specified string for tokens.
This method will construct an instance of AStringStream for use as the scanner's Source.
|
|
function init: boolean; override; |
Initializer
|
|
destructor destroy; override; |
Destructor
|
|
function nextToken: PMiniToken; virtual; |
Retrieve the next token from the source.
|
|
function continues: boolean; override; |
Determine whether or not there are more tokens to retrieve from the source.
This method checks to see whether the end of the source stream has been reached and returns False if so. Otherwise it returns True .
|
|
function Source: ATextInputStream; virtual; |
Retrieve a reference to the source stream being scanned.
The caller should NOT attempt to free the reference returned by this stream.
|
|
function ownsSource: boolean; virtual; |
Retrieve whether or not the scanner assumes ownership of its source stream.
If this method returns True , then the mini-scanner instance assumes ownership of its source stream and will free the stream when it is, itself, freed. To change this behavior, call AMiniScanner.setOwnsSource.
|
|
function setOwnsSource(const flag: boolean): boolean; virtual; |
Set whether or not the scanner assumes ownership of its source stream.
If flag is True , then the mini-scanner instance will assume ownership of its source stream and will free the stream when it is, itself, freed. Otherwise, the caller will need to free AMiniScanner.Source when it is no longer required.
Returns
The previous value of AMiniScanner.ownsSource. |
|
function recognizedDigits: string; virtual; |
Retrieve the list of characters that are recognized as digits by the scanner.
|
|
function setRecognizedDigits(const newValue: string): string; virtual; |
Set the list of characters that are recognized as digits by the scanner.
Returns
The previous value of AMiniScanner.recognizedDigits. |
|
function recognizedLetters: string; virtual; |
Retrieve the list of characters that are recognized as letters by the scanner.
|
|
function setRecognizedLetters(const newValue: string): string; virtual; |
Set the list of characters that are recognized as letters by the scanner.
Returns
The previous value of AMiniScanner.recognizedLetters. |
|
function recognizedSpecialCharacters: string; virtual; |
Retrieve the list of characters that are recognized as special characters by the scanner.
|
|
function setRecognizedSpecialCharacters(const newValue: string): string; virtual; |
Set the list of characters that are recognized as special characters by the scanner.
Returns
The previous value of AMiniScanner.recognizedSpecialCharacters. |
|
function RecognizedTokens: AStringTree; virtual; |
Retrieve a reference to the list of recognized tokens. Tokens in this list are any combination of letters, digits, and/or special characters that, when combined, form a token that should be recognized and acted upon by the parser driving the mini-scanner instance.
The caller should NOT attempt to free the reference returned by this routine.
|
|
function previousToken: PMiniToken; virtual; |
Retrieve the previous token read from the source.
|
|
function currentToken: PMiniToken; virtual; |
Retrieve the most recent token read from the source.
|
Generated by PasDoc 0.13.0 on 2015-06-23 19:40:11
|