Replacement function with specific scope.

def genrepl(scope):
    """Replacement function with specific scope."""

    def repl(match):
        """Internal replacement function."""

        name = match.group('name')

        value = lookup(name, scope=scope)

        result = name.replace('.', '_')
        scope[result] = value

        return result

    return repl