TApxTerminalParser.ProcessChar

TApxTerminalParser

function ProcessChar(aCh : AnsiChar) : TApxParserCmdType; virtual;
TApxParserCmdType = (pctNone, pctChar, pctPending, pctComplete);

Processes a single character.

ProcessChar is the main workhorse of the parser class. It is the method that takes a character and decides whether that character forms part of a terminal control sequence or is just one that must be displayed. ProcessChar must maintain the current state of the parser (in other words, whether the parser is building up a terminal control sequence, has just completed a sequence, etc.).

ProcessChar can return one of several values. pctNone means that the character passed in was not understood by the parser. Either the character was a single-byte control character (in other words, a non-displayable character less than the space character) that would be ignored by the original terminal, or the character terminated an escape sequence, but that escape sequence was not known by the parser. The caller of ProcessChar can safely ignore the problem since there is no recovery action to take because the parser has been left in a correct state. pctChar means that the input character should be displayed on the terminal. pctPending means that the input character formed part of an escape sequence that is being built up, character by character. There is nothing further to do at this point since the escape sequence has not yet been completed.

The last possible result value is pctComplete. This value indicates that the parser has captured a complete terminal control sequence. Furthermore it indicates that the parser has identified the command defined by the escape sequence and has set the Command property. It will have extracted all of the command arguments or parameters and set both the Argument and ArgumentCount properties. Finally, it will make sure that the Sequence property returns the entire escape sequence.

In this ancestor class, the ProcessChar method always returns pctNone.

If ProcessChar is called for a parser that was created to expect wide characters, a parser exception will be raised.

See also: Argument, ArgumentCount, Command, Create, ProcessWideChar, Sequence