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 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, is_section = \ self.__parse_title_and_parameters(filename, 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 meta = {} tags = [] if len(split) > 1: n_lines = len(comment.split('\n')) description_offset = (title_offset + n_lines - len(split[1].split('\n'))) meta['description'], tags = self.__parse_description_and_tags( split[1]) actual_parameters = OrderedDict({}) for param in parameters: if is_section: if param.name.lower().replace('_', '-') in [ 'symbols', 'private-symbols', 'auto-sort' ]: meta.update(self.__parse_yaml_comment(param, filename)) else: meta[param.name] = param.description 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, tags=tags, raw_comment=raw_comment, meta=meta) block.line_offset = description_offset block.col_offset = column_offset return block
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 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) title_and_params, description = self.__extract_titles_params_and_description(comment) try: block_name, parameters, annotations, is_section = \ self.__parse_title_and_parameters(filename, title_and_params) 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 meta = {} tags = [] if description is not None: n_lines = len(comment.split('\n')) description_offset = (title_offset + n_lines - len(description.split('\n'))) meta['description'], tags = self.__parse_description_and_tags(description) actual_parameters = OrderedDict({}) for param in parameters: if is_section: cleaned_up_name = param.name.lower().replace('_', '-') if cleaned_up_name in ['symbols', 'private-symbols', 'auto-sort', 'sources']: meta.update(self.__parse_yaml_comment(param, filename)) if cleaned_up_name == 'sources': sources_paths = [os.path.abspath(os.path.join(os.path.dirname(filename), path)) for path in meta[cleaned_up_name]] meta[cleaned_up_name] = sources_paths else: meta[param.name] = param.description 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, tags=tags, raw_comment=raw_comment, meta=meta, toplevel=is_section) block.line_offset = description_offset block.col_offset = column_offset return block
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 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(filename, 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 = OrderedDict({}) 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