示例#1
0
 def __parse_parameter(self, name, desc):
     name = name.strip()[1:-1].strip()
     desc = desc.strip()
     desc, annotations = self.__extract_annotations(desc)
     annotations = {annotation.name: annotation for annotation in
                    annotations}
     return Comment(name=name, annotations=annotations,
                    description=desc)
def google_doc_to_native(doc):
    if not doc:
        return (None, {})

    doc = trim(doc)

    docstring = MyGoogleDocString(doc, config)
    comment = Comment(description=docstring.__unicode__(),
            raw_comment=doc)

    for field in docstring.param_fields:
        tags = {}
        if field[1]:
            tags['type'] = field[1]

        param_comment = Comment(name=field[0],
                description='\n'.join(field[2]),
                tags=tags)
        comment.params[field[0]] = param_comment

    attr_comments = {}
    for field in docstring.attribute_fields:
        tags = {}
        if field[1]:
            tags['type'] = field[1]
        prop_comment = Comment(name=field[0],
                description='\n'.join(field[2]),
                tags = tags)
        attr_comments[field[0]] = prop_comment

    return_comments = []
    for field in docstring.return_fields:
        tags = {}
        if field[1]:
            tags['type'] = field[1]
        return_comment = Comment(
                description='\n'.join(field[2]),
                tags=tags)
        return_comments.append(return_comment)

    comment.tags['returns'] = return_comments

    return comment, attr_comments
示例#3
0
    def __fetch_comment(self, sym, doc_database):
        old_comment = sym.comment
        new_comment = doc_database.get_comment(sym.unique_name)
        sym.comment = Comment(sym.unique_name)

        if new_comment:
            sym.comment = new_comment
        elif old_comment:
            if not old_comment.filename in (ChangeTracker.all_stale_files |
                                            ChangeTracker.all_unlisted_files):
                sym.comment = old_comment
示例#4
0
    def parse_comment(self, comment, filename, lineno, endlineno,
                      include_paths=None, stripped=False):
        """
        Returns a Comment given a string
        """
        if not stripped and not self.__validate_c_comment(comment.strip()):
            return None

        comment = unicode(comment.decode('utf8'))

        title_offset = 0

        column_offset = 0

        raw_comment = comment
        if not stripped:
            try:
                while comment[column_offset * -1 - 1] != '\n':
                    column_offset += 1
            except IndexError:
                column_offset = 0
            comment, title_offset = self.__strip_comment(comment)

        split = re.split(r'\n[\W]*\n', comment, maxsplit=1)

        try:
            block_name, parameters, annotations = \
                self.__parse_title_and_parameters(split[0])
        except HotdocSourceException as _:
            warn('gtk-doc-bad-syntax',
                 message=_.message,
                 filename=filename,
                 lineno=lineno + title_offset)
            return None

        params_offset = 0
        for param in parameters:
            param.filename = filename
            param.lineno = lineno
            param_offset = param.line_offset
            param.line_offset = title_offset + params_offset + 1
            params_offset += param_offset
            param.col_offset = column_offset

        if not block_name:
            return None

        description_offset = 0
        description = ""
        tags = []
        if len(split) > 1:
            n_lines = len(comment.split('\n'))
            description_offset = (title_offset + n_lines -
                                  len(split[1].split('\n')))
            description, tags = self.__parse_description_and_tags(split[1])

        title = None
        short_description = None
        actual_parameters = {}
        for param in parameters:
            if param.name.lower() == 'short_description':
                short_description = param
            elif param.name.lower() == 'title':
                title = param
            else:
                actual_parameters[param.name] = param

        annotations = {annotation.name: annotation for annotation in
                       annotations}
        tags = {tag.name.lower(): tag for tag in tags}

        block = Comment(name=block_name, filename=filename, lineno=lineno,
                        endlineno=endlineno,
                        annotations=annotations, params=actual_parameters,
                        description=description,
                        short_description=short_description,
                        title=title, tags=tags, raw_comment=raw_comment)
        block.line_offset = description_offset
        block.col_offset = column_offset

        return block