PeekToken (StringTokenizer function)

From m204wiki
Jump to navigation Jump to search

Value of next token in current tokenizer string, do not advance (StringTokenizer class)


This method returns the string value of the next token forward in the current tokenizer string. The next token parsing begins from the tokenizing position, which is the value returned by NextPosition.

When the next token is determined, PeekToken does not advance the tokenizing position, which remains what it was when PeekToken was called.

The delimiters that are involved in determining the tokens are set initially by the New method that instantiates the StringTokenizer object. The delimiters can be modified by the Spaces, Quotes, TokenChars, and Separators properties.

Syntax

%string = stringTokenizer:PeekToken Throws MismatchedQuote, OutOfBounds

Syntax terms

%string A string variable to receive the value of the current token.
stringTokenizer A StringTokenizer object expression.

Usage notes

  • If the value of AtEnd is True, issuing PeekToken is invalid and cancels the request.
  • The NextToken and FindToken functions return the next token and advance the tokenizing position to the character or position following that token. SkipTokens similarly advances the tokenizing position, but it returns no value. After a successful execution of NextToken, FindToken, or SkipTokens, the token located becomes the current token. This is not true for PeekToken: after it completes successfully, the token located does not become the current token.

Examples

The following sequence of PrintText statements display, respectively, example, example, and example, showing that the tokenizing position does not move after PeekToken completes:

%tok:string = 'example of peekToken' printText {%tok:peekToken} printText {%tok:peekToken} printText {%tok:peekToken}

See also