Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

Using the tab function for parsing in Icon

Tech Computer Center logo

Recall that Icon's ``e1 ? e2'' operator not only sets the subject ``&subject'' to e1 during the evaluation of e2, but it also sets up an implied position in a variable called ``&pos''.

The implied subject for string scanning is strictly defined as the portion of the current subject past the current position. So, if ``&pos'' is 3, then the current subject is all but the first two characters of ``&subject''.

You can use the tab() function to work your way through a complex subject. Here is what a call to ``tab ( n )'' does:

  1. The current position (&pos) is saved.
  2. The position is set to n.
  3. The function returns the portion of the subject between the old (saved) position and the new position, as a string.

For example, ``tab ( many ( &digits ) )'' finds the position of the next character in the subject that is not a digit, sets the new position there, and returns the string of digits between the old and new positions.


Next: An example of Icon parsing
See also: Implicit scanning in Icon
Previous: Implicit matching in Icon
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437
Home: About New Mexico Tech

John Shipman, john@nmt.edu
Last updated: 1996/01/06 21:12:57 UT
URL: http://www.nmt.edu/tcc/help/lang/icon/tab.html
QR two-dimensional bar code