Class AMiniParser

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type AMiniParser = class(ANode)

Description

This class represents a miniature parser. The purpose of the class is to provide a quick way to parse custom formatting strings.

The parser creates an instance of AMiniScanner which is used to scan the string in question. The scanner returns tokens which the parser will act upon by calling one of three callback routines. These callback routines can be set by the calling routine. This behavior allows the caller to customize the parser's response to a token without the need to define a custom descendant of this class (though, of course, that is also possible).

The three callback routines defined by this class are:

Hierarchy

Overview

Fields

Protected MyScanner: AMiniScanner;
Protected myRecognizedTokenCallback: AMiniParserCallback;
Protected myNumericTokenCallback: AMiniParserCallback;
Protected myUnrecognizedTokenCallback: AMiniParserCallback;

Methods

Public function init: boolean; override;
Public destructor destroy; override;
Public procedure nextToken; virtual;
Public function previousToken: PMiniToken; virtual;
Public function currentToken: PMiniToken; virtual;
Public function parse: int64; virtual;
Public function Scanner: AMiniScanner; virtual;
Public function RecognizedTokens: AStringTree; virtual;
Public function recognizedTokenCallback: AMiniParserCallback; virtual;
Public function setRecognizedTokenCallback(const newCallback: AMiniParserCallback): AMiniParserCallback; virtual;
Public function numericTokenCallback: AMiniParserCallback; virtual;
Public function setNumericTokenCallback(const newCallback: AMiniParserCallback): AMiniParserCallback; virtual;
Public function unrecognizedTokenCallback: AMiniParserCallback; virtual;
Public function setUnrecognizedTokenCallback(const newCallback: AMiniParserCallback): AMiniParserCallback; virtual;

Description

Fields

Protected MyScanner: AMiniScanner;

Refers to the scanner used to scan for tokens

Protected myRecognizedTokenCallback: AMiniParserCallback;

Refers to the callback used when a recognized token is found

Protected myNumericTokenCallback: AMiniParserCallback;

Refers to the callback used when a numeric token is found

Protected myUnrecognizedTokenCallback: AMiniParserCallback;

Refers to the callback used when an unrecognized token is found

Methods

Public function init: boolean; override;

Initializer

Public destructor destroy; override;

Destructor

Public procedure nextToken; virtual;

Retrieve the next token from the source.

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.

Public function parse: int64; virtual;

Parse the source.

Public function Scanner: AMiniScanner; virtual;

Retrieve a reference to the scanner used to obtain tokens.

The caller should NOT attempt to free the reference returned by this routine.

Public function RecognizedTokens: AStringTree; virtual;

Retrieve a reference to the list of recognized tokens.

This function is a pass-through function and returns the value returned by a call to Self.Scanner.RecognizedTokens.

The caller should NOT attempt to free the reference returned by this routine.

Public function recognizedTokenCallback: AMiniParserCallback; virtual;

Retrieve a reference to the recognized token callback. This is the method called when a token is found that matches a value in Self.RecognizedTokens.

Public function setRecognizedTokenCallback(const newCallback: AMiniParserCallback): AMiniParserCallback; virtual;

Set the recognized token callback. This is the method that will be called when a token is found that matches a value in Self.RecognizedTokens.

Returns

The previous value of AMiniParser.recognizedTokenCallback. The caller can save this reference in order to "chain up" to the previous handler.

Public function numericTokenCallback: AMiniParserCallback; virtual;

Retrieve a reference to the numeric token callback. This is the method called when an integer or floating-point token is encountered.

Public function setNumericTokenCallback(const newCallback: AMiniParserCallback): AMiniParserCallback; virtual;

Set the numeric token callback. This is the method that will be called when an integer or floating-point token is encountered.

Returns

The previous value of AMiniParser.numericTokenCallback. The caller can save this reference in order to "chain up" to the previous handler.

Public function unrecognizedTokenCallback: AMiniParserCallback; virtual;

Retrieve a reference to the unrecognized token callback. This is the method that will be called when an unrecognized token is encountered.

Public function setUnrecognizedTokenCallback(const newCallback: AMiniParserCallback): AMiniParserCallback; virtual;

Set the unrecognized token callback. This is the method that will be called when an unrecognized token is encountered.

Returns

The previous value of AMiniParser.unrecognizedTokenCallback. The caller can save this reference in order to "chain up" to the previous handler.


Generated by PasDoc 0.13.0 on 2015-06-23 19:40:11