PeekToken (StringTokenizer function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
 
Line 4: Line 4:
the next token forward in the current tokenizer string.
the next token forward in the current tokenizer string.
The next token parsing begins from the tokenizing position,
The next token parsing begins from the tokenizing position,
which is the value returned by [[NextPosition (StringTokenizer property)|NextPosition]].
which is the value returned by <var>[[NextPosition (StringTokenizer property)|NextPosition]]</var>.


When the next token is determined,
When the next token is determined,
Line 11: Line 11:


The delimiters that are involved in determining the tokens
The delimiters that are involved in determining the tokens
are set initially by the [[New (StringTokenizer constructor)|New]] method
are set initially by the <var>[[New (StringTokenizer constructor)|New]]</var> method
that instantiates the <var>StringTokenizer</var> object.
that instantiates the <var>StringTokenizer</var> object.
The delimiters can be modified by the [[Spaces (StringTokenizer property)|Spaces]],
The delimiters can be modified by the <var>[[Spaces (StringTokenizer property)|Spaces]]</var>,
[[Quotes (StringTokenizer property)|Quotes]], and [[TokenChars (StringTokenizer property)|TokenChars]] properties.
<var>[[Quotes (StringTokenizer property)|Quotes]]</var>, <var>[[TokenChars (StringTokenizer property)|TokenChars]]</var>, and <var>[[Separators (StringTokenizer property)|Separators]]</var> properties.
 
==Syntax==
==Syntax==
{{Template:StringTokenizer:PeekToken syntax}}
{{Template:StringTokenizer:PeekToken syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
Line 27: Line 29:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If the value of [[AtEnd (StringTokenizer function)|AtEnd]] is <code>True</code>,
<li>If the value of <var>[[AtEnd (StringTokenizer function)|AtEnd]]</var> is <code>True</code>,
issuing <var>PeekToken</var> is invalid and cancels the request.
issuing <var>PeekToken</var> is invalid and cancels the request.
<li>The [[NextToken (StringTokenizer function)|NextToken]] and [[FindToken (StringTokenizer function)|FindToken]]
 
functions return the next token and
<li>The <var>[[NextToken (StringTokenizer function)|NextToken]]</var> and <var>[[FindToken (StringTokenizer function)|FindToken]]</var> functions return the next token and
advance the tokenizing position to the character or position following that token.
advance the tokenizing position to the character or position following that token.
[[SkipTokens (StringTokenizer subroutine)|SkipTokens]] similarly advances the tokenizing position,
<var>[[SkipTokens (StringTokenizer subroutine)|SkipTokens]]</var> similarly advances the tokenizing position,
but it returns no value.
but it returns no value.


Line 40: Line 42:
does ''not'' become the current token.
does ''not'' become the current token.
</ul>
</ul>
==Examples==
==Examples==
 
The following sequence of <var>[[Targeted Text statements|PrintText]]</var> statements display,
The following sequence of printText statements display,
respectively, <code>example</code>, <code>example</code>, and <code>example</code>,
respectively, <tt>example</tt>, <tt>example</tt>, and <tt>example</tt>,
showing that the tokenizing position does not move after <var>PeekToken</var> completes:
showing that the tokenizing position does not move after <var>PeekToken</var> completes:
<p class="code">%tok:string = 'example of peekToken'
<p class="code">%tok:string = 'example of peekToken'
Line 50: Line 52:
printText {%tok:peekToken}
printText {%tok:peekToken}
</p>
</p>
==See also==
==See also==
{{Template:StringTokenizer:PeekToken footer}}
{{Template:StringTokenizer:PeekToken footer}}

Latest revision as of 00:30, 6 July 2012

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