6.23.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.

Comienzo python section to interscript/frames/inputf.py[19 /41 ] Siguiente Previo Primero Ăšltimo
   594: #line 839 "input_frame.ipk"
   595:   def collect_stuff(self,prefix, cont_re, echo):
   596:     saved = prefix
   597:     try:
   598:       file2,count2,line = self.readline()
   599:       match = cont_re.match(line)
   600:       while match:
   601:         if echo:
   602:           print '%s %6s: %s' % (file2,count2,line)
   603:         body = match.group(1)
   604:         if not body: body = ''
   605:         saved = saved+'\n'+body
   606:         file2,count2,line = self.readline()
   607:         match = cont_re.match(line)
   608:       self.enqueue_input(file2,count2,line)
   609:     except eoi:
   610:       pass
   611:     saved = saved + '\n'
   612:     return saved
   613: 
   614:   def collect_lines_upto(self,terminal, keep=0):
   615:     term_re = re.compile('^'+terminal+'$')
   616:     saved = []
   617:     file,count,line = self.readline()
   618:     match = term_re.match(line)
   619:     while not match:
   620:       saved.append(line)
   621:       file,count,line = self.readline()
   622:       match = term_re.match(line)
   623:     return saved
   624: 
   625:   def skip_upto(self,terminal):
   626:     term_re = re.compile('^'+terminal+'$')
   627:     file,count,line = self.readline()
   628:     match = term_re.match(line)
   629:     while not match:
   630:       file,count,line = self.readline()
   631:       match = term_re.match(line)
   632: 
   633:   def skip_upto_if(self,terminal,condition):
   634:     if condition: self.skip_upto(terminal)
   635: 
   636:   def collect_upto(self,terminal, keep=0):
   637:     return string.join(self.collect_lines_upto(terminal,keep), '\n')+'\n'
   638: 
End python section to interscript/frames/inputf.py[19]