MANAGER@SMITH.BITNET (Mary Malmros) (03/11/88)
I would like some clarification about patterns and pattern operators in TPU; specifically, the | operator. If I am interpreting the TPU manual correctly, the line PAT := ' ' | LINE_BEGIN; ought to make a pattern PAT that will match on either a space or a beginning-of-line. If, however, I follow this line with the lines WORDSTART := SEARCH (PAT, REVERSE); POSITION (WORDSTART); I always go to a space and never to the beginning of a line, even when the beginning of a line is closer. Help please, gurus? Mary Malmros Systems Manager Center for Academic Computing Smith College Northampton, MA 01063 (413) 584-2700 x3073 MANAGER@SMITH.BITNET
carl@CITHEX.CALTECH.EDU (Carl J Lydick) (03/13/88)
> I would like some clarification about patterns and pattern operators in TPU; > specifically, the | operator. If I am interpreting the TPU manual correctly, > the line > > PAT := ' ' | LINE_BEGIN; > > ought to make a pattern PAT that will match on either a space or a > beginning-of-line. If, however, I follow this line with the lines > > WORDSTART := SEARCH (PAT, REVERSE); > POSITION (WORDSTART); > > I always go to a space and never to the beginning of a line, even when > the beginning of a line is closer. You're suffering from one of the wierdnesses of TPU. Given the pattern you've specified, TPU will search that part of the file following your current position for a ' ', and if it doesn't find one, will search it for a LINE_BEGIN. This is definitely NON-INTUITIVE, and therefore, probably a bad default (hey DEC, anybody listening out there [though it's far too late to fix this problem now]). What you need to do is make the pattern: PAT := '' & ( ' ' | LINE_BEGIN ) ; This forces it to find '' every character and look for ( ' ' | LINE_BEGIN ) as the succeeding character in all cases.
EWR@WS001.AMS.COM (Betsy Ramsey) (03/14/88)
I had this problem, too, when I was trying to search for two patterns. You have to anchor the search (see the TPU manual for instructions on how to do this). Otherwise TPU defaults to searching the whole buffer for the first pattern, and then for the second pattern. -------