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 _interpret_prefixed(text, function, declare, filename=None, lineno=None):
	split = text.split(' ', 1)
	invalid = 'Missing content for @{} function comment'.format(split[0])

	if split[0] == 'arg':
		split = split[1].split(' ', 1)

		if len(split) < 2:
			warn(invalid, filename=filename, lineno=lineno)
			return

		for argument in function.args:
			if argument['name'] == split[0]:
				if 'desc' in argument and argument['desc']:
					argument['desc'] += '\n' + split[1]
				else:
					argument['desc'] = split[1]

				function.described_args = True
				break
		else:
			warn('Unknown argument for @arg function comment', filename=filename, lineno=lineno)

	elif split[0] == 'field':
		split = split[1].split(' ', 1)

		if len(split) < 2:
			warn(invalid, filename=filename, lineno=lineno)
			return

		for field in function.fields:
			if field['name'] == split[0]:
				field['desc'] += '\n' + split[1]
				break
		else:
			function.fields.append({'name': split[0], 'desc': split[1]})

	elif split[0] == 'see':
		if len(split) < 2:
			warn(invalid, filename=filename, lineno=lineno)
			return

		function.see.append(split[1])

	elif split[0] == 'abstract':
		function.abstract = True
	elif split[0] == 'private':
		function.private = True
	elif split[0] == 'deprecated':
		function.deprecated = True