src/aoikhotkey/hotkey_parser.py
def hotkey_parse_inner(pattern, vk_ntc, vk_tran, vk_expand):
    """
    Hotkey parse function's inner function.

    :param pattern: Hotkey pattern.

    :param vk_ntc: Name to virtual key function.

    :param vk_tran: Virtual key transform function.

    :param vk_expand: Virtual key expand function.

    :return: Hotkey list. Each hotkey is a virtual key list.
    """
    # Virtual key list
    vk_s = []

    # Get hotkey pattern length
    pattern_len = len(pattern)

    # Pattern character index
    idx = 0

    # Whether last character is left-side marker
    last_is_left = False

    # Whether last character is right-side marker
    last_is_right = False

    # While have unparsed part
    while idx < pattern_len:
        # Get current character
        char = pattern[idx]

        # Increment the character index
        idx += 1

        # Whether the character is left-side marker
        is_left = False

        # Whether the character is right-side marker
        is_right = False

        # Virtual key
        vk = None

        # If the character is `<`
        if char == '<':
            # Set is left-side marker be True
            is_left = True

        # If the character is `>`
        elif char == '>':
            # Set is right-side marker be True
            is_right = True

        # If the character is `}`
        elif char == '}':
            # Get error message
            msg = '"}" has no matching "{" before it.'

            # Raise error
            raise ValueError(msg)

        # If the character is not `<`, `>`, or `}`
        else:
            # If the character is `{`
            if char == '{':
                # Find next `}` character's index.
                #
                # `idx + 1` aims to cover the `{}}` situation.
                idx_end = pattern.find('}', idx + 1)

                # If next `}` character's index is not found
                if idx_end == -1:
                    # Get error message
                    msg = '"{" has no matching "}" after it.'

                    # Raise error
                    raise ValueError(msg)

                # If next `}` character's index is found.

                # Get the name inside the curly braces
                name = pattern[idx:idx_end]

                # Move forward the character index
                idx = idx_end + 1

                # Get the name's virtual key.
                # May be None, which will be handled below.
                vk = vk_ntc(name)

            # If the character is `F`
            elif char == 'F':
                # Get next two characters.
                #
                # E.g. F1 to F24
                next_2chars = pattern[idx:idx + 2]

                # Match the next two characters
                matched = _FUNC_KEY_NAME_REO.match(next_2chars)

                # If not matched
                if not matched:
                    # Get error message
                    msg = 'Met "F" but is not one of F1 to F24.'

                    # Raise error
                    raise ValueError(msg)

                # Get matched text
                matched_text = matched.group()

                # Get matched text length
                matched_text_len = len(matched_text)

                # Move forward the character index
                idx += matched_text_len

                # Get the name
                name = 'F' + matched_text

                # Get the name's virtual key.
                # May be None, which will be handled below.
                vk = vk_ntc(name)

            # If the character is none of above
            else:
                # Use the character as name
                name = char

                # Get the name's virtual key.
                # May be None, which will be handled below.
                vk = vk_ntc(name)

            # If virtual key is not found
            if vk is None:
                # Get error message
                msg = '{name} has no virtual key.'.format(name=repr(name))

                # Raise error
                raise ValueError(msg)

            # If virtual key is found.

            # If the virtual key is virtual key list.
            #
            # This aims to allow `vk_ntc` to return virtual key list,
            # e.g. Map name 'A' to [EVK_SHIFT, VK_KEY_A].
            if isinstance(vk, list):
                # Use the virtual key list
                vk_list = vk

            # If the virtual key is not virtual key list
            else:
                # Create virtual key list containing the virtual key
                vk_list = [vk]

            # If left-side marker is on
            if last_is_left:
                # Set side be left side
                side = VK_TRAN_SIDE_V_LEFT

            # If right-side marker is on
            elif last_is_right:
                # Set side be right side
                side = VK_TRAN_SIDE_V_RIGHT

            # If left-side and right-side are not on
            else:
                # Set side be none side
                side = VK_TRAN_SIDE_V_NONE

            # Transform the virtual key list to sided value
            vk_list = [vk_tran(x, side=side) for x in vk_list]

            # For each transformed virtual key
            for transformed_vk in vk_list:
                # If the transformed virtual key is virtual key list.
                #
                # This aims to allow `vk_tran` to return virtual key list.
                if isinstance(transformed_vk, (list, tuple)):
                    # Add the virtual key list to the result
                    vk_s.extend(transformed_vk)

                # If the transformed virtual key is not virtual key list
                else:
                    # Add the virtual key to the result
                    vk_s.append(transformed_vk)

        # Store whether left-side marker is on
        last_is_left = is_left

        # Store whether right-side marker is on
        last_is_right = is_right

    # Expand the virtual key list to multiple virtual key lists.
    # E.g. [CTRL, A] -> [[LCTRL, A], [RCTRL, A]]
    hotkey_s = _hotkey_expand(vk_s, vk_expand)

    # Return a list of virtual key lists
    return hotkey_s

    Hotkey parse function's inner function.

    :param pattern: Hotkey pattern.

    :param vk_ntc: Name to virtual key function.

    :param vk_tran: Virtual key transform function.

    :param vk_expand: Virtual key expand function.

    :return: Hotkey list. Each hotkey is a virtual key list.
    
Hotkey parse function's inner function.
Hotkey parse function ' s inner function .
def hotkey_parse_inner(pattern, vk_ntc, vk_tran, vk_expand):
    vk_s = []
    pattern_len = len(pattern)
    idx = 0
    last_is_left = False
    last_is_right = False
    while idx < pattern_len:
        char = pattern[idx]
        idx += 1
        is_left = False
        is_right = False
        vk = None
        if char == '<':
            is_left = True
        elif char == '>':
            is_right = True
        elif char == '}':
            msg = '"}" has no matching "{" before it.'
            raise ValueError(msg)
        else:
            if char == '{':
                 `idx + 1` aims to cover the `{}}` situation.
                idx_end = pattern.find('}', idx + 1)
                 If next `}` character's index is not found
                if idx_end == -1:
                    msg = '"{" has no matching "}" after it.'
                    raise ValueError(msg)
                 If next `}` character's index is found.
                 Get the name inside the curly braces
                name = pattern[idx:idx_end]
                 Move forward the character index
                idx = idx_end + 1
                 Get the name's virtual key.
                 May be None, which will be handled below.
                vk = vk_ntc(name)
             If the character is `F`
            elif char == 'F':
                 Get next two characters.
                 E.g. F1 to F24
                next_2chars = pattern[idx:idx + 2]
                 Match the next two characters
                matched = _FUNC_KEY_NAME_REO.match(next_2chars)
                 If not matched
                if not matched:
                    msg = 'Met "F" but is not one of F1 to F24.'
                    raise ValueError(msg)
                 Get matched text
                matched_text = matched.group()
                 Get matched text length
                matched_text_len = len(matched_text)
                 Move forward the character index
                idx += matched_text_len
                 Get the name
                name = 'F' + matched_text
                 Get the name's virtual key.
                 May be None, which will be handled below.
                vk = vk_ntc(name)
             If the character is none of above
            else:
                 Use the character as name
                name = char
                 Get the name's virtual key.
                 May be None, which will be handled below.
                vk = vk_ntc(name)
             If virtual key is not found
            if vk is None:
                msg = '{name} has no virtual key.'.format(name=repr(name))
                raise ValueError(msg)
             If virtual key is found.
             If the virtual key is virtual key list.
             This aims to allow `vk_ntc` to return virtual key list,
             e.g. Map name 'A' to [EVK_SHIFT, VK_KEY_A].
            if isinstance(vk, list):
                 Use the virtual key list
                vk_list = vk
             If the virtual key is not virtual key list
            else:
                 Create virtual key list containing the virtual key
                vk_list = [vk]
             If left-side marker is on
            if last_is_left:
                 Set side be left side
                side = VK_TRAN_SIDE_V_LEFT
             If right-side marker is on
            elif last_is_right:
                 Set side be right side
                side = VK_TRAN_SIDE_V_RIGHT
             If left-side and right-side are not on
            else:
                 Set side be none side
                side = VK_TRAN_SIDE_V_NONE
             Transform the virtual key list to sided value
            vk_list = [vk_tran(x, side=side) for x in vk_list]
             For each transformed virtual key
            for transformed_vk in vk_list:
                 If the transformed virtual key is virtual key list.
                 This aims to allow `vk_tran` to return virtual key list.
                if isinstance(transformed_vk, (list, tuple)):
                     Add the virtual key list to the result
                    vk_s.extend(transformed_vk)
                 If the transformed virtual key is not virtual key list
                else:
                     Add the virtual key to the result
                    vk_s.append(transformed_vk)
         Store whether left-side marker is on
        last_is_left = is_left
         Store whether right-side marker is on
        last_is_right = is_right
     Expand the virtual key list to multiple virtual key lists.
     E.g. [CTRL, A] -> [[LCTRL, A], [RCTRL, A]]
    hotkey_s = _hotkey_expand(vk_s, vk_expand)
     Return a list of virtual key lists
    return hotkey_s
def hotkey_parse_inner ( pattern , vk_ntc , vk_tran , vk_expand ) : vk_s = [ ] pattern_len = len ( pattern ) idx = 0 last_is_left = False last_is_right = False while idx < pattern_len : char = pattern [ idx ] idx += 1 is_left = False is_right = False vk = None if char == '<' : is_left = True elif char == '>' : is_right = True elif char == '}' : msg = '"}" has no matching "{" before it.' raise ValueError ( msg ) else : if char == '{' : idx_end = pattern . find ( '}' , idx + 1 ) if idx_end == - 1 : msg = '"{" has no matching "}" after it.' raise ValueError ( msg ) name = pattern [ idx : idx_end ] idx = idx_end + 1 vk = vk_ntc ( name ) elif char == 'F' : next_2chars = pattern [ idx : idx + 2 ] matched = _FUNC_KEY_NAME_REO . match ( next_2chars ) if not matched : msg = 'Met "F" but is not one of F1 to F24.' raise ValueError ( msg ) matched_text = matched . group ( ) matched_text_len = len ( matched_text ) idx += matched_text_len name = 'F' + matched_text vk = vk_ntc ( name ) else : name = char vk = vk_ntc ( name ) if vk is None : msg = '{name} has no virtual key.' . format ( name = repr ( name ) ) raise ValueError ( msg ) if isinstance ( vk , list ) : vk_list = vk else : vk_list = [ vk ] if last_is_left : side = VK_TRAN_SIDE_V_LEFT elif last_is_right : side = VK_TRAN_SIDE_V_RIGHT else : side = VK_TRAN_SIDE_V_NONE vk_list = [ vk_tran ( x , side = side ) for x in vk_list ] for transformed_vk in vk_list : if isinstance ( transformed_vk , ( list , tuple ) ) : vk_s . extend ( transformed_vk ) else : vk_s . append ( transformed_vk ) last_is_left = is_left last_is_right = is_right hotkey_s = _hotkey_expand ( vk_s , vk_expand ) return hotkey_s
Hotkey parse function's inner function.
Hotkey parse function ' s inner function .
"""
    Hotkey parse function's inner function.

    :param pattern: Hotkey pattern.

    :param vk_ntc: Name to virtual key function.

    :param vk_tran: Virtual key transform function.

    :param vk_expand: Virtual key expand function.

    :return: Hotkey list. Each hotkey is a virtual key list.
    """ # Virtual key list # Get hotkey pattern length # Pattern character index # Whether last character is left-side marker # Whether last character is right-side marker # While have unparsed part # Get current character # Increment the character index # Whether the character is left-side marker # Whether the character is right-side marker # Virtual key # If the character is `<` # Set is left-side marker be True # If the character is `>` # Set is right-side marker be True # If the character is `}` # Get error message # Raise error # If the character is not `<`, `>`, or `}` # If the character is `{` # Find next `}` character's index. # # `idx + 1` aims to cover the `{}}` situation. # If next `}` character's index is not found # Get error message # Raise error # If next `}` character's index is found. # Get the name inside the curly braces # Move forward the character index # Get the name's virtual key. # May be None, which will be handled below. # If the character is `F` # Get next two characters. # # E.g. F1 to F24 # Match the next two characters # If not matched # Get error message # Raise error # Get matched text # Get matched text length # Move forward the character index # Get the name # Get the name's virtual key. # May be None, which will be handled below. # If the character is none of above # Use the character as name # Get the name's virtual key. # May be None, which will be handled below. # If virtual key is not found # Get error message # Raise error # If virtual key is found. # If the virtual key is virtual key list. # # This aims to allow `vk_ntc` to return virtual key list, # e.g. Map name 'A' to [EVK_SHIFT, VK_KEY_A]. # Use the virtual key list # If the virtual key is not virtual key list # Create virtual key list containing the virtual key # If left-side marker is on # Set side be left side # If right-side marker is on # Set side be right side # If left-side and right-side are not on # Set side be none side # Transform the virtual key list to sided value # For each transformed virtual key # If the transformed virtual key is virtual key list. # # This aims to allow `vk_tran` to return virtual key list. # Add the virtual key list to the result # If the transformed virtual key is not virtual key list # Add the virtual key to the result # Store whether left-side marker is on # Store whether right-side marker is on # Expand the virtual key list to multiple virtual key lists. # E.g. [CTRL, A] -> [[LCTRL, A], [RCTRL, A]] # Return a list of virtual key lists
Hotkey list. Each hotkey is a virtual key list.
Hotkey list . Each hotkey is a virtual key list .
pattern
None
vk_ntc
Name to virtual key function.
Name to virtual key function .
vk_tran
Virtual key transform function.
Virtual key transform function .
vk_expand
Virtual key expand function.
Virtual key expand function .