Class AMiniScanner

DescriptionHierarchyFieldsMethodsProperties

Unit

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

Protected MySource: ATextInputStream;
Protected myOwnSource: boolean;
Protected myRecognizedDigits: string;
Protected myRecognizedLetters: string;
Protected myRecognizedSpecialCharacters: string;
Protected MyRecognizedTokens: AStringTree;
Protected myPreviousToken: TMiniToken;
Protected myCurrentToken: TMiniToken;

Methods

Protected procedure collectNumericToken; virtual;
Protected procedure collectWordToken; virtual;
Protected procedure collectSpecialToken; virtual;
Protected procedure collectUnrecognizedToken; virtual;
Public constructor forSource(const ThisTarget: ATextInputStream; const takeOwnershipOfTarget: boolean = true); virtual;
Public constructor forString(const thisString: string); virtual;
Public function init: boolean; override;
Public destructor destroy; override;
Public function nextToken: PMiniToken; virtual;
Public procedure next; override;
Public function continues: boolean; override;
Public function Source: ATextInputStream; virtual;
Public function ownsSource: boolean; virtual;
Public function setOwnsSource(const flag: boolean): boolean; virtual;
Public function recognizedDigits: string; virtual;
Public function setRecognizedDigits(const newValue: string): string; virtual;
Public function recognizedLetters: string; virtual;
Public function setRecognizedLetters(const newValue: string): string; virtual;
Public function recognizedSpecialCharacters: string; virtual;
Public function setRecognizedSpecialCharacters(const newValue: string): string; virtual;
Public function RecognizedTokens: AStringTree; virtual;
Public function previousToken: PMiniToken; virtual;
Public function currentToken: PMiniToken; virtual;

Description

Fields

Protected MySource: ATextInputStream;

Refers to the source

Protected myOwnSource: boolean;

Indicates whether or not the scanner owns its source

Protected myRecognizedDigits: string;

Stores a list of characters that represent digits

Protected myRecognizedLetters: string;

Stores a list of characters that represent letters

Protected myRecognizedSpecialCharacters: string;

Stores a list of characters that represent special characters

Protected MyRecognizedTokens: AStringTree;

Refers to a list of recognized tokens

Protected myPreviousToken: TMiniToken;

Stores the previous token read from the source

Protected myCurrentToken: TMiniToken;

Stores the most recent token read from the source

Methods

Protected 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.

Protected 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.

Protected 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.

Protected procedure collectUnrecognizedToken; virtual;

Collect an unrecognized token.

This method is called automatically by AMiniScanner.nextToken when it encounters a character in the source that does not match any of those specified in Self.recognizedDigits, Self.recognizedLetters, and Self.recognizedSpecialCharacters. It collects characters until it encountes one which IS defined in one of the known lists.

Public 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.

Public 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.

Public function init: boolean; override;

Initializer

Public destructor destroy; override;

Destructor

Public function nextToken: PMiniToken; virtual;

Retrieve the next token from the source.

Public procedure next; override;

Increment the iterator.

This method simply calls AMiniScanner.nextToken.

Public 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.

Public 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.

Public 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.

Public 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.

Public function recognizedDigits: string; virtual;

Retrieve the list of characters that are recognized as digits by the scanner.

Public 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.

Public function recognizedLetters: string; virtual;

Retrieve the list of characters that are recognized as letters by the scanner.

Public 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.

Public function recognizedSpecialCharacters: string; virtual;

Retrieve the list of characters that are recognized as special characters by the scanner.

Public 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.

Public 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.

Public function previousToken: PMiniToken; virtual;

Retrieve the previous token read from the source.

Public 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