master_parse/__init__.py
def make_magic(regex_token: str, must_be_word: bool = False) -> Pattern:
    """
    Maps a "magic" regex into one that matches properly and preserves what
    follows the token.

    :param regex_token:   the regular expression text pattern for the token
    :param must_be_word:  whether the token must be a word by itself. This
                          should have been the default, when the tool was
                          originally written, but it wasn't. This option
                          defaults to False to limit possible regression.
                          But, some tokens (especially those with common
                          prefixes, like "%md" and "%md-sandbox") will need
                          to use True here.
    :return: A compiled regex
    """
    if must_be_word:
        # This is complicated. Basically, the constructed regex says, "the
        # token must match at the end of the string (\Z) OR must be followed
        # by a white space character (\s). The (?:...) construct allows the
        # alternation (the OR), without creating a capture group.
        #
        # If you don't understand this, DON'T modify it until you do. It's
        # fragile.
        adj_token = regex_token + r"(?:\Z|\s+)"
    else:
        adj_token = regex_token

    # Allow surrounding white space.
    regex_text = r"\s*" + adj_token + r"\s*(.*)$"
    return re.compile(make_magic_text(regex_text))

    Maps a "magic" regex into one that matches properly and preserves what
    follows the token.

    :param regex_token:   the regular expression text pattern for the token
    :param must_be_word:  whether the token must be a word by itself. This
                          should have been the default, when the tool was
                          originally written, but it wasn't. This option
                          defaults to False to limit possible regression.
                          But, some tokens (especially those with common
                          prefixes, like "%md" and "%md-sandbox") will need
                          to use True here.
    :return: A compiled regex
    
Maps a "magic" regex into one that matches properly and preserves what
follows the token.
Maps a " magic " regex into one that matches properly and preserves what follows the token .
def make_magic(regex_token: str, must_be_word: bool = False) -> Pattern:
    if must_be_word:
         If you don't understand this, DON'T modify it until you do. It's
         fragile.
        adj_token = regex_token + r"(?:\Z|\s+)"
    else:
        adj_token = regex_token
     Allow surrounding white space.
    regex_text = r"\s*" + adj_token + r"\s*(.*)$"
    return re.compile(make_magic_text(regex_text))
def make_magic ( regex_token : str , must_be_word : bool = False ) -> Pattern : if must_be_word : adj_token = regex_token + r"(?:\Z|\s+)" else : adj_token = regex_token regex_text = r"\s*" + adj_token + r"\s*(.*)$" return re . compile ( make_magic_text ( regex_text ) )
Maps a "magic" regex into one that matches properly and preserves what
follows the token.
Maps a " magic " regex into one that matches properly and preserves what follows the token .
"""
    Maps a "magic" regex into one that matches properly and preserves what
    follows the token.

    :param regex_token:   the regular expression text pattern for the token
    :param must_be_word:  whether the token must be a word by itself. This
                          should have been the default, when the tool was
                          originally written, but it wasn't. This option
                          defaults to False to limit possible regression.
                          But, some tokens (especially those with common
                          prefixes, like "%md" and "%md-sandbox") will need
                          to use True here.
    :return: A compiled regex
    """ # This is complicated. Basically, the constructed regex says, "the # token must match at the end of the string (\Z) OR must be followed # by a white space character (\s). The (?:...) construct allows the # alternation (the OR), without creating a capture group. # # If you don't understand this, DON'T modify it until you do. It's # fragile. # Allow surrounding white space.
A compiled regex
A compiled regex
regex_token
str
the regular expression text pattern for the token
the regular expression text pattern for the token
must_be_word
bool
whether the token must be a word by itself. This
should have been the default, when the tool was
originally written, but it wasn't. This option
defaults to False to limit possible regression.
But, some tokens (especially those with common
prefixes, like "%md" and "%md-sandbox") will need
to use True here.
whether the token must be a word by itself . This should have been the default when the tool was originally written but it wasn ' t . This option defaults to False to limit possible regression . But some tokens ( especially those with common prefixes like " %md " and " %md - sandbox " ) will need to use True here .
False to limit possible regression.
But, some tokens (especially those with common
prefixes, like "%md" and "%md-sandbox") will need
to use True here