def compile_repl_group(source, pattern):
 source.expect('<')
 name = parse_name(source, True, True)
 source.expect('>')
 if name.isdigit():
  index = int(name)
  if (not (0 <= index <= pattern.groups)):
   raise error('invalid group reference', source.string, source.pos)
  return index
 try:
  return pattern.groupindex[name]
 except KeyError:
  raise IndexError('unknown group')

def compile_repl_group ( source , pattern ) : source . expect ( '<' ) name = parse_name ( source , True , True ) source . expect ( '>' ) if name . isdigit ( ) : index = int ( name ) if ( not ( 0 <= index <= pattern . groups ) ) : raise error ( 'invalid group reference' , source . string , source . pos ) return index try : return pattern . groupindex [ name ] except KeyError : raise IndexError ( 'unknown group' )
compiles a replacement template group reference .