Beispiel #1
0
def _parse(blob, filename=None, lineno=None):
    size = 0

    p1 = blob.find('(')
    p2 = blob.find(')')
    p3 = blob.find('{')
    p4 = blob.find('\n')

    if p1 == -1 or p2 == -1 or p3 == -1:
        warn('Invalid function declaration - missing tokens', filename=filename, lineno=lineno)
        return

    if p2 < p1 or p3 < p1 or p3 < p2 or (p4 != -1 and p4 < p1):
        warn('Invalid function declaration - wrong token order', filename=filename, lineno=lineno)
        return

    name = blob[9:p1].rstrip()

    if not verify_identifier(name, True):
        warn('Invalid identifier \'{}\''.format(name), filename=filename, lineno=lineno)
        return

    args = _parse_args(blob[p1 + 1:p2])

    if args and '::' in name:
        args = args[1:]

    if args != None:
        return {
            'name': name,
            'args': args,
            'code': blob[:p2 + 1]
        }

    warn('Invalid argument list', filename=filename, lineno=lineno)
Beispiel #2
0
def _parse_args(text):
    if not text.split():
        return []

    split = map(lambda v: v.strip(), text.split(','))

    for item in split:
        if not item or item[0] != '%' or not verify_identifier(item[1:]):
            return

    return map(lambda v: v[1:], split)
Beispiel #3
0
def _parse_args(text):
	if not text.split():
		return [], False

	split = map(lambda v: v.strip(), text.split(','))

	args = []
	mult = False

	for item in split:
		optional = False

		if item == '...':
			mult = True
			continue

		if len(item) > 2 and item[0] == '[' and item[-1] == ']':
			optional = True
			item = item[1:-1]

		split_item = item.split()

		if len(split_item) > 2:
			return None, False

		item_name = split_item[-1]
		item_type = split_item[0] if len(split_item) == 2 else ''

		if not verify_identifier(item_name):
			return None, False

		args.append({
			'name': item_name,
			'type': item_type,
			'optional': optional
		})

	return args, mult