23 lines
1.1 KiB
Text
23 lines
1.1 KiB
Text
( 1:?number
|
|
& 0:?lines
|
|
& whl
|
|
' ( 1+!lines:~>10:?lines
|
|
& :?say { This will accumulate all that has to be said after one iteration. }
|
|
& 0:?begin
|
|
& ( @( !number { Pattern matching. The '@' indicates we're looking in a string rather than a tree structure. }
|
|
: ?
|
|
( [!begin
|
|
%@?digit
|
|
?
|
|
[?end
|
|
( (|(%@:~!digit) ?) { The %@ guarantees we're testing one character - not less (%) and not more (@). The ? takes the rest. }
|
|
& !say !end+-1*!begin !digit:?say
|
|
& !end:?begin { When backtracking, 'begin' advances to the begin of the next sequence, or to the end of the string. }
|
|
)
|
|
& ~ { fail! This forces backtracking. Backtracking stops when all begin positions have been tried. }
|
|
)
|
|
)
|
|
| out$(str$!say:?number) { After backtracking, output string and set number to string for next iteration. }
|
|
)
|
|
)
|
|
);
|