<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_config(cls, path, directory=None):
 """ Instantiate a REPP from a PET-style `.set` configuration file. The *path* parameter points to the configuration file. Submodules are loaded from *directory*. If *directory* is not given, it is the directory part of *path*. Args: path (str):
 the path to the REPP configuration file directory (str, optional):
 the directory in which to search for submodules """

        if not exists(path):
            raise REPPError('REPP config file not found: {}'.format(path))
        confdir = dirname(path)

        # TODO: can TDL parsing be repurposed for this variant?
        conf = io.open(path, encoding='utf-8').read()
        conf = re.sub(r';.*', '', conf).replace('\n',' ')
        m = re.search(
            r'repp-modules\s*:=\s*((?:[-\w]+\s+)*[-\w]+)\s*\.', conf)
        t = re.search(
            r'repp-tokenizer\s*:=\s*([-\w]+)\s*\.', conf)
        a = re.search(
            r'repp-calls\s*:=\s*((?:[-\w]+\s+)*[-\w]+)\s*\.', conf)
        f = re.search(
            r'format\s*:=\s*(\w+)\s*\.', conf)
        d = re.search(
            r'repp-directory\s*:=\s*(.*)\.\s*$', conf)

        if m is None:
            raise REPPError('repp-modules option must be set')
        if t is None:
            raise REPPError('repp-tokenizer option must be set')

        mods = m.group(1).split()
        tok = t.group(1).strip()
        active = a.group(1).split() if a is not None else None
        fmt = f.group(1).strip() if f is not None else None

        if directory is None:
            if d is not None:
                directory = d.group(1).strip(' "')
            elif exists(joinpath(confdir, tok + '.rpp')):
                directory = confdir
            elif exists(joinpath(confdir, 'rpp', tok + '.rpp')):
                directory = joinpath(confdir, 'rpp')
            elif exists(joinpath(confdir, '../rpp', tok + '.rpp')):
                directory = joinpath(confdir, '../rpp')
            else:
                raise REPPError('Could not find a suitable REPP directory.')

        # ignore repp-modules and format?
        return REPP.from_file(
            joinpath(directory, tok + '.rpp'),
            directory=directory,
            active=active
        )