from typing import Set
import re


def compile_graphemes(graphemes: Set[str]) -> re.Pattern:
    """
    Compiles the list of graphemes into a regular expression pattern.

    Parameters
    ----------
    graphemes: Set[str]
        Set of characters to treat as orthographic text

    Returns
    -------
    re.Pattern
        Compiled pattern that matches all graphemes
    """
    base = r"^\W*([{}]+)\W*"
    string = re.escape("".join(graphemes))
    try:
        return re.compile(base.format(string))
    except Exception:
        print(graphemes)
        raise