import re


def _parse_variable_arguments(args, prefix='-'):
    """
    Parse an argument list with keyword argument identified as having a single
    or double dash as prefix (-, --) or other character defined by the `prefix`
    argument.
    All non-keyword arguments following a keyword are assigned values to the
    keyword. If there are no values, the keyword is treated as boolean argument.

    :param args:   argument list to parse
    :type args:    :py:list
    :param prefix: prefix character used to identify keyword arguments
    :type prefix:  :py:str

    :return:       variable name/arguments dictionary
    :rtype:        :py:dict
    """

    # Keyword positions, discard negative numbers
    positions = [e for e, n in enumerate(args) if n.startswith(prefix) and not re.match('^[-+]?[0-9]+$', n)]

    # Split the argument list based on keyword positions
    method_args = {}
    length = len(positions) - 1
    for i, kwp in enumerate(positions):
        if i < length:
            argument = args[kwp: positions[i + 1]]
        else:
            argument = args[kwp:]

        # Check for double declaration of keywords, not allowed
        var_name = argument[0].strip(prefix)
        if var_name in method_args:
            raise AttributeError('Variable declared twice: {0}'.format(var_name))
        
        # Format boolean argument
        if len(argument) == 1:
            method_args[var_name] = True
        elif len(argument) == 2:
            method_args[var_name] = argument[1]
        else:
            method_args[var_name] = argument[1:]

    return method_args