TParser
[Properties (by Name)][Methods (by Name)][Events (by Name)]
Class to parse the contents of a stream containing text data.
Declaration
Source position: classesh.inc line 1774
Type
TParser = class (TObject)
private
fStream : TStream;
fBuf : PChar;
fBufLen : Integer;
fPos : Integer;
fDeltaPos : Integer;
fFloatType : Char;
fSourceLine : Integer;
fToken : Char;
fEofReached : Boolean;
fLastTokenStr : string;
fLastTokenWStr : WideString;
function GetTokenName(aTok: Char) : string;
procedure LoadBuffer;
procedure CheckLoadBuffer;
procedure ProcessChar;
function IsNumber : Boolean;
function IsHexNum : Boolean;
function IsAlpha : Boolean;
function IsAlphaNum : Boolean;
function GetHexValue(c: Char) : Byte;
function GetAlphaNum : string;
procedure HandleNewLine;
procedure SkipBOM;
procedure SkipSpaces;
procedure SkipWhitespace;
procedure HandleEof;
procedure HandleAlphaNum;
procedure HandleNumber;
procedure HandleHexNumber;
function HandleQuotedString : string;
procedure HandleDecimalCharacter(var ascii: Boolean;
out WideChr: WideChar;
out StringChr: Char);
procedure HandleString;
procedure HandleMinus;
procedure HandleUnknown;
public
constructor Create(Stream: TStream);
destructor Destroy; Override;
procedure CheckToken(T: Char);
procedure CheckTokenSymbol(const S: string);
procedure Error(const Ident: string);
procedure ErrorFmt(const Ident: string; const Args: Array of const);
procedure ErrorStr(const Message: string);
procedure HexToBinary(Stream: TStream);
function NextToken : Char;
function SourcePos : LongInt;
function TokenComponentIdent : string;
function TokenFloat : Extended;
function TokenInt : Int64;
function TokenString : string;
function TokenWideString : WideString;
function TokenSymbolIs(const S: string) : Boolean;
FloatType : Char;
SourceLine : Integer;
Token : Char;
end
;
Description
This class breaks a stream of text data in tokens. Its primary use is to help reading the contents of a form file (usually a file with dfm, xfm or lfm extension), and for this reason it isn't suitable to be used as a general parser.
The parser is always positioned on a certain token, whose type is stored in the Token property. Various methods are provided to obtain the token value in the desired format.
To advance to the next token, invoke NextToken method.
Members
Member | Type | Visibility | Description |
---|---|---|---|
CheckLoadBuffer | Method | private | |
CheckToken | Method | public | Checks whether the token if of the given type. |
CheckTokenSymbol | Method | public | Checks whether the token equals the given symbol |
Create | Method | public | Creates a new parser instance. |
Destroy | Method | public | Destroys the parser instance. |
Error | Method | public | Raises an EParserError exception with the given message |
ErrorFmt | Method | public | Raises an EParserError exception and formats the message. |
ErrorStr | Method | public | Raises an EParserError exception with the given message |
fBuf | Field | private | |
fBufLen | Field | private | |
fDeltaPos | Field | private | |
fEofReached | Field | private | |
fFloatType | Field | private | |
fLastTokenStr | Field | private | |
fLastTokenWStr | Field | private | |
FloatType | Property | public | The type of a float token. |
fPos | Field | private | |
fSourceLine | Field | private | |
fStream | Field | private | |
fToken | Field | private | |
GetAlphaNum | Method | private | |
GetHexValue | Method | private | |
GetTokenName | Method | private | |
HandleAlphaNum | Method | private | |
HandleDecimalCharacter | Method | private | |
HandleEof | Method | private | |
HandleHexNumber | Method | private | |
HandleMinus | Method | private | |
HandleNewLine | Method | private | |
HandleNumber | Method | private | |
HandleQuotedString | Method | private | |
HandleString | Method | private | |
HandleUnknown | Method | private | |
HexToBinary | Method | public | Writes hexadecimal data to a stream. |
IsAlpha | Method | private | |
IsAlphaNum | Method | private | |
IsHexNum | Method | private | |
IsNumber | Method | private | |
LoadBuffer | Method | private | |
NextToken | Method | public | Reads the next token and returns its type. |
ProcessChar | Method | private | |
SkipBOM | Method | private | |
SkipSpaces | Method | private | |
SkipWhitespace | Method | private | |
SourceLine | Property | public | Current source line number. |
SourcePos | Method | public | Returns the current position in the stream. |
Token | Property | public | The type of the current token. |
TokenComponentIdent | Method | public | Returns the path of a subcomponent starting from the current token. |
TokenFloat | Method | public | Returns the current token as a float. |
TokenInt | Method | public | Returns the current token as an integer. |
TokenString | Method | public | Returns the current token as a string. |
TokenSymbolIs | Method | public | Returns True if the token equals the given symbol. |
TokenWideString | Method | public | Returns the current token as a widestring |
Inheritance
Class | Description |
---|---|
TParser | Class to parse the contents of a stream containing text data. |
See also
Name | Description |
---|---|
Char | Character type (1 byte) |
Char | Character type (1 byte) |
Char | Character type (1 byte) |
Char | Character type (1 byte) |
Char | Character type (1 byte) |
Integer | A signed 16-bits integer |
Integer | A signed 16-bits integer |
Integer | A signed 16-bits integer |
Integer | A signed 16-bits integer |
Integer | A signed 16-bits integer |
TParser.NextToken | Reads the next token and returns its type. |
TParser.Token | The type of the current token. |
TStream | Base class for streams. |
WideString | UTF-16 widechar encoded unicode string |