From: lisch@tempest-sw.com (Ray Lischner)
Subject: Re: Delphi *Undocumented Functions - TParser*
Date: Sat, 10 Jun 1995 05:02:03 GMT

My guess is that TParser is used to parse the data for persistent
objects.

I tried experimenting with TParser.  Contrary to its name, it is
actually a rudimentary lexical scanner, not really a parser.  You
create it with a Stream argument, and it reads tokens from that
stream.  When you first create the TParser object, it automatically
scans the first token.  After that, call NextToken to advance to the
next token.  Severy properties and functions return information about
the current token.

Token: Char tells you the type of the current token:
   Chr(0) indicates end of file.  Once the parser reaches end of file,
it always returns Chr(0) after that.
  Chr(1) is for any Pascal identifier.  Call TokenString to learn the
text of the identifier.
  Chr(2) is for a Pascal string.  If the string is not terminated
properly, EParserError is raised.  Non-printing characters, like #13
are interpreted for you, as are doubled quotes.
  Chr(3) marks an integer.  Call TokenInt to obtain the value of the
integer.  Hexadecimal ($10) constants are interpreted.
  Chr(4) seems to be for floating point numbers.  Call TokenFloat to
learn the value.
  Other characters are tokens by themselves, without further
interpretation.  In other word, ":=" is two tokens: ':' and '='.
White space is silently ignored, except, of course, that is serves to
separate tokens.  Comments are not recognized or interpreted.

For any token, you can call TokenString to obtain the text of the
token.

SourceLine returns the line number for the current token.  SourcePos
returns the byte offset in the stream for the start of the token.

There seem to be some bugs.  For example, the token, '1.......4'
returns token Chr(4).  After an exception, the parser seems to be
stuck in an invalid state.  I don't know how to get it reset itself.

The private variables of TParser include some buffer management, so it
is probably unwise to manipulate the stream separately from the
parser.  I haven't tried this, though, so I don't really know if it
would work.

Well, that's all I have time for.  Share and enjoy!
--
Ray Lischner       (lisch@tempest-sw.com)
Tempest Software
