Esempio n. 1
0
	def check_either(self, value, context_mark, data, context, echoerr, start, end):
		'''Check that given value matches one of the given specifications

		:param int start:
			First specification index.
		:param int end:
			Specification index that is greater by 1 then last specification 
			index.

		This method does not give an error if any specification from 
		``self.specs[start:end]`` is matched by the given value.
		'''
		havemarks(value)
		new_echoerr = DelayedEchoErr(echoerr)

		hadproblem = False
		for spec in self.specs[start:end]:
			proceed, hadproblem = spec.match(value, value.mark, data, context, new_echoerr)
			if not proceed:
				break
			if not hadproblem:
				return True, False

		new_echoerr.echo_all()

		return False, hadproblem
Esempio n. 2
0
def check_args(get_functions, args, data, context, echoerr):
	new_echoerr = DelayedEchoErr(echoerr)
	count = 0
	hadproblem = False
	for func in get_functions(data, context, new_echoerr):
		count += 1
		shadproblem = check_args_variant(func, args, data, context, echoerr)
		if shadproblem:
			hadproblem = True

	if not count:
		hadproblem = True
		if new_echoerr:
			new_echoerr.echo_all()
		else:
			echoerr(context='Error while checking segment arguments (key {key})'.format(key=context.key),
			        context_mark=context[-2][1].mark,
			        problem='no suitable segments found')

	return True, False, hadproblem
Esempio n. 3
0
def check_group(group, data, context, echoerr):
    havemarks(group)
    if not isinstance(group, unicode):
        return True, False, False
    colorscheme = data['colorscheme']
    ext = data['ext']
    configs = []
    if ext:
        if colorscheme == '__main__':
            configs.append([
                config
                for config in data['ext_colorscheme_configs'][ext].items()
            ])
            configs.append(
                [config for config in data['top_colorscheme_configs'].items()])
        else:
            try:
                configs.append(
                    [data['ext_colorscheme_configs'][ext][colorscheme]])
            except KeyError:
                pass
            try:
                configs.append(
                    [data['ext_colorscheme_configs'][ext]['__main__']])
            except KeyError:
                pass
            try:
                configs.append([data['top_colorscheme_configs'][colorscheme]])
            except KeyError:
                pass
    else:
        try:
            configs.append([data['top_colorscheme_configs'][colorscheme]])
        except KeyError:
            pass
    new_echoerr = DelayedEchoErr(echoerr)
    hadproblem = False
    for config_lst in configs:
        tofind = len(config_lst)
        not_found = []
        for config in config_lst:
            if isinstance(config, tuple):
                new_colorscheme, config = config
                new_data = data.copy()
                new_data['colorscheme'] = new_colorscheme
            else:
                new_data = data
            havemarks(config)
            try:
                group_data = config['groups'][group]
            except KeyError:
                not_found.append(config.mark.name)
            else:
                proceed, echo, chadproblem = check_group(
                    group_data,
                    new_data,
                    context,
                    echoerr,
                )
                if chadproblem:
                    hadproblem = True
                else:
                    tofind -= 1
                    if not tofind:
                        return proceed, echo, hadproblem
                if not proceed:
                    break
        if not_found:
            new_echoerr(
                context=
                'Error while checking group definition in colorscheme (key {key})'
                .format(key=context.key),
                problem='name {0} is not present in {1} {2} colorschemes: {3}'.
                format(group, tofind, ext, ', '.join(not_found)),
                problem_mark=group.mark)
    new_echoerr.echo_all()
    return True, False, hadproblem