def read_regexp_block(stream, start_re, end_re=None):
 while True:
  line = stream.readline()
  if (not line):
   return []
  if re.match(start_re, line):
   break
 lines = [line]
 while True:
  oldpos = stream.tell()
  line = stream.readline()
  if (not line):
   return [''.join(lines)]
  if ((end_re is not None) and re.match(end_re, line)):
   return [''.join(lines)]
  if ((end_re is None) and re.match(start_re, line)):
   stream.seek(oldpos)
   return [''.join(lines)]
  lines.append(line)

def read_regexp_block ( stream , start_re , end_re = None ) : while True : line = stream . readline ( ) if ( not line ) : return [ ] if re . match ( start_re , line ) : break lines = [ line ] while True : oldpos = stream . tell ( ) line = stream . readline ( ) if ( not line ) : return [ '' . join ( lines ) ] if ( ( end_re is not None ) and re . match ( end_re , line ) ) : return [ '' . join ( lines ) ] if ( ( end_re is None ) and re . match ( start_re , line ) ) : stream . seek ( oldpos ) return [ '' . join ( lines ) ] lines . append ( line )
read a sequence of tokens from a stream .