6.19.10.2.15. 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[20 /42 ] Next Prev First Last
   667: #line 913 "input_frame.ipk"
   668:   def collect_stuff(self,prefix, cont_re, echo):
   669:     saved = prefix
   670:     try:
   671:       file2,count2,line = self.readline()
   672:       match = cont_re.match(line)
   673:       while match:
   674:         if echo:
   675:           print '%s %6s: %s' % (file2,count2,line)
   676:         body = match.group(1)
   677:         if not body: body = ''
   678:         saved = saved+'\n'+body
   679:         file2,count2,line = self.readline()
   680:         match = cont_re.match(line)
   681:       self.enqueue_input(file2,count2,line)
   682:     except eoi:
   683:       pass
   684:     saved = saved + '\n'
   685:     return saved
   686: 
   687:   def collect_lines_upto(self,terminal, keep=0):
   688:     "Collect lines up to marker line"
   689:     term_re = re.compile('^'+terminal+'$')
   690:     saved = []
   691:     file,count,line = self.readline()
   692:     match = term_re.match(line)
   693:     while not match:
   694:       saved.append(line)
   695:       file,count,line = self.readline()
   696:       match = term_re.match(line)
   697:     return saved
   698: 
   699:   def skip_upto(self,terminal):
   700:     "Skip up to marker line"
   701:     term_re = re.compile('^'+terminal+'$')
   702:     file,count,line = self.readline()
   703:     match = term_re.match(line)
   704:     while not match:
   705:       file,count,line = self.readline()
   706:       match = term_re.match(line)
   707: 
   708:   def skip_upto_if(self,terminal,condition):
   709:     "if condition is true, skip up to marker line"
   710:     if condition: self.skip_upto(terminal)
   711: 
   712:   def collect_upto(self,terminal, keep=0):
   713:     "Collect text up to marker line"
   714:     return string.join(self.collect_lines_upto(terminal,keep), '\n')+'\n'
   715: 
End python section to interscript/frames/inputf.py[20]