Read the input stream until the given text is encountered, or until the end of the input stream (EOF) is encountered.
The until command is an important “tokenising” command that converts
blocks of text in the input-stream into
grammar or parse tokens. Other tokenising commands are
while
and whilenot
There are 2 formats of the until command
until 'abcd';
until;
In the 1st version of until the input stream is read until the workspace buffer ends with the text “abcd” . In the 2nd form of the command, the input-stream is read until the workspace buffer ends with the text that is in the current tape cell.
The until command also ignores the end-text in the input stream if it is 'escaped' (that is preceded with '\\'). The following example illustrates parsing quoted text with the until command.
read;
'"' {
a+; until '"'; put; clear; add "quoted*";
push; .reparse
}
clear;
parse>
pop; pop;
"quoted*quoted*" {
clear; get; add "\n"; ++; get; --; put;
clear; add "quoted*"; push; .reparse
}
push; push;
(eof) {
add "Found "; count; add " quoted text blocks \n"; print; clear;
pop; "quoted*" { clear; get; print; }
quit;
}
/</ { until ">"; print; } clear;
r; '"' { until '"'; clip; clop; print; } clear;
r; '/' { until '"'; clip; clop; put; add 'quoted*'; push; } clear;
/"/ { until '"'; print; } clear;
The while and whilenot commands are similar to the until command but they depend on the value of the 'peep' virtual machine buffer (which is a single-character buffer) rather than on the contents of the 'workspace' buffer like the until command.
The 'until' command usually will form part of the 'lexing' phase of a script. That is, the until command permits the script to turn text patterns into 'tokens'. While in traditional parsing tools (such as Lex and Yacc) the lexing and parsing phases are carried out by separate tools, with the 'pep' tool the two functions are combined.
The until command essentially performs multiple read operations or commands and after each read checks to see whether the workspace meets the criteria specified in the argument.