6.13.10.2.14. Collect stuff

This command reads ahead in the input until a line is found that does not match the supplied continuation pattern. It then returns all the input lines as a single string. It can be used to drive user defined parser objects, which process the returned string.

For example, the built-in python suite processes uses this function to collect a multiline python suite before executing it.

Start python section to interscript/frames/inputf.py[19 /40 ] Next Prev Last
   549: #line 805 "input_frame.ipk"
   550:   def collect_stuff(self,prefix, cont_re, echo):
   551:     saved = prefix
   552:     try:
   553:       file2,count2,line = self.readline()
   554:       match = cont_re.match(line)
   555:       while match:
   556:         if echo:
   557:           print '%s %6s: %s' % (file2,count2,line)
   558:         body = match.group(1)
   559:         if not body: body = ''
   560:         saved = saved+'\n'+body
   561:         file2,count2,line = self.readline()
   562:         match = cont_re.match(line)
   563:       self.enqueue_input(file2,count2,line)
   564:     except eoi:
   565:       pass
   566:     saved = saved + '\n'
   567:     return saved
   568: 
   569:   def collect_lines_upto(self,terminal):
   570:     term_re = re.compile('^'+terminal+'$')
   571:     saved = []
   572:     file,count,line = self.readline()
   573:     match = term_re.match(line)
   574:     while not match:
   575:       saved.append(line)
   576:       file,count,line = self.readline()
   577:       match = term_re.match(line)
   578:     return saved
   579: 
   580:   def collect_upto(self,terminal):
   581:     return string.join(self.collect_lines_upto(terminal), '\n')+'\n'
   582: 
End python section to interscript/frames/inputf.py[19]