6. Templates for ARG, PULL, and PARSE
The PULL, ARG and PARSE instructions use a template to parse a string.
The simplest template is a list of variables where each of them is assigned one word from the string, except the last variable in the list which will contain the rest of the string.
1 PARSE VALUE "one two three four " WITH a b c
2 now a="one"; b="two"; c="three four"
3 PARSE VALUE "one two three four " WITH a b c d e
4 now a="one"; b="two"; c="three"; d="four" and e=""
A dot ‘.’ can be in the place of one or more variables, it is used as a place-holder.
1 PARSE VALUE "one two three four " WITH a . . d
2 now a="one"; d="four"
A more complex parsing is to use patterns for triggering:
number which specifies an absolute position in string 1 - is the first character in string
=(name) as a position may be a variable enclosed in parenthesis after an equal symbol
[+|-]number signed numbers are used as a relative positioning
1PARSE VALUE "one two three four " WITH 2 a 6 b 2now a="ne t"; b="wo three four " pos=6; 3PARSE VALUE "one two three four " WITH 2 a =(pos) b 4now a="ne t"; b="wo three four " PARSE VALUE "one two three four " WITH 2 a +2 b 5now a="ne"; b=" two three four "
string - may be used as a target position.
1 PARSE VALUE "marmita/bill/vivi' WITH a '/' b '/' c 2 now a="marmita"; b="bill"; c="vivi"
(name) - also as a target may be used a variable encolsed in parenthesis
1 t = "%%" 2 PARSE VALUE "aabbcc%%ddeeff%%gg%%" WITH . (t) middle (t) . now middle="ddeeff"
A comma can be used as a “trigger” to move to the next string when there is more than one to be parsed (e.g. when there is more than one argument string to a routine).
1 CALL MyProc 'Hi',3,4
2 EXIT
3 MyProc:
4 PARSE ARG first, second, third /* now first="Hi" */
5 ... /* second=3 */
6 /* third=4 */