/* ParseTest.rexx Parse experiments */ start: /* a label clause for use by SIGNAL start*/ /* default test line */ line='This is a line of text. No.123456 #98765. The last sentence!' SAY 'NOTE: In this program, =varpos and (varpos) are used instead of' SAY '=position and (position) in the Cookbook for more clarity.' SAY 'You should NOT use varpos as an ordinary template target name.' SAY SAY 'Enter PARSE OPTION: 1=NUMERIC 2=SOURCE 3=VAR 4=VERSION' PARSE PULL option SAY 'Parse UPPER? Y/N' PULL uo IF uo='Y' THEN uo='UPPER';ELSE uo='' name=' ' SELECT WHEN option=1 THEN DO PARSE NUMERIC line option='NUMERIC' END WHEN option=2 THEN DO PARSE SOURCE line option='SOURCE' END WHEN option=4 THEN DO PARSE VERSION line option='VERSION' END OTHERWISE DO option='VAR' SAY 'Enter test parse source string or [Rtn] to use built-in test.' PARSE PULL input IF input='' THEN input=line; ELSE line=input name=' line ' END END mid: /* label for SIGNAL mid */ varpos='' CALL PU.rexx line SAY SAY 'Use: =varpos for variable representing the column POSITION number.' SAY 'Use: (varpos) for variable PATTERN to MATCH & FIND column position.' SAY 'You will be prompted for value of =varpos or (varpos) afterwards.' SAY 'Enter PARSE Template (template string ONLY).' PARSE PULL template /* get only alphabetic targets and not markers */ temp=template n=1 DO WHILE temp ~='' PARSE VAR temp tar.n temp /* take off the commas, keep the targets */ IF RIGHT(tar.n,1)=',' THEN tar.n=LEFT(tar.n,LENGTH(tar.n)-1) IF LEFT(tar.n,1)=',' THEN tar.n=RIGHT(tar.n,LENGTH(tar.n)-1) /* get rid of non alpha stuff */ IF ~DATATYPE(tar.n,MIXED) THEN ITERATE n=n+1 END n=n-1 pat=0 /* set default flag for column number */ /* the expression we wish to execute */ template='PARSE' uo option||name||template pos: /* label for SIGNAL pos */ /* if we find "varpos" used in the template string, ask for value */ /* depending upon whether it is a pattern or a column number */ IF FIND(template,'=varpos')~=0|FIND(template,'(varpos)')~=0, THEN DO /* pattern */ IF FIND(template,'(varpos)')~=0 THEN DO pat=1 /* set flag for pattern */ SAY 'Enter EXACT PATTERN to match in finding column number.' PARSE PULL varpos SAY 'Variable pattern to match is >'varpos'<' SIGNAL out /* get out of here! skip the rest. */ END /* a column number */ SAY 'Enter COLUMN NUMBER assigned to varpos' PARSE PULL varpos /* check for valid column number */ IF ~DATATYPE(varpos,WHOLE) THEN DO SAY 'Not a valid column varpos. Try again.' SIGNAL pos /* do over again */ END SAY 'Variable column postion is now at column >'varpos'<' END out: /* display stuff */ SAY CALL PU.rexx line SAY SAY template SAY /* the heart of the matter. execute the code we built */ INTERPRET template /* display the targets and their values */ DO i=1 TO n SAY tar.i'==>'VALUE(tar.i)'<' SAY END /* if we use varpos, display its value depending on flag pat...*/ IF varpos~='' THEN DO IF pat=0 THEN SAY 'Column Position='varpos' Value of =varpos is 'varpos IF pat=1 THEN SAY "Pattern="varpos" (varpos) matches pattern '"varpos"'." SAY END /* control options */ SAY 'Enter S=start over; N=new template; P=new pattern/position; Q=quit.' PARSE UPPER PULL in SELECT WHEN in='Q' THEN EXIT WHEN in='S' THEN SIGNAL start WHEN in='N' THEN SIGNAL mid WHEN in='P' THEN SIGNAL pos OTHERWISE SIGNAL START END EXIT 0