# -*- Mode: Python -*- # GObject-Introspection - a framework for introspecting GObject libraries # Copyright (C) 2008 Johan Dahlin # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # # AnnotationParser - parses gtk-doc annotations import re from .odict import odict # All gtk-doc comments needs to start with this: _COMMENT_HEADER = '*\n ' # Tags - annotations applyed to comment blocks TAG_VFUNC = 'virtual' TAG_SINCE = 'since' TAG_DEPRECATED = 'deprecated' TAG_RETURNS = 'returns' TAG_ATTRIBUTES = 'attributes' TAG_RENAME_TO = 'rename to' TAG_TYPE = 'type' TAG_TRANSFER = 'transfer' TAG_UNREF_FUNC = 'unref func' TAG_REF_FUNC = 'ref func' TAG_SET_VALUE_FUNC = 'set value func' TAG_GET_VALUE_FUNC = 'get value func' # Options - annotations for parameters and return values OPT_ALLOW_NONE = 'allow-none' OPT_ARRAY = 'array' OPT_ELEMENT_TYPE = 'element-type' OPT_IN = 'in' OPT_INOUT = 'inout' OPT_INOUT_ALT = 'in-out' OPT_OUT = 'out' OPT_SCOPE = 'scope' OPT_TRANSFER = 'transfer' OPT_TYPE = 'type' OPT_CLOSURE = 'closure' OPT_DESTROY = 'destroy' OPT_SKIP = 'skip' OPT_FOREIGN = 'foreign' # Array options - array specific annotations OPT_ARRAY_FIXED_SIZE = 'fixed-size' OPT_ARRAY_LENGTH = 'length' OPT_ARRAY_ZERO_TERMINATED = 'zero-terminated' OPT_SCOPE_ASYNC = 'async' OPT_SCOPE_CALL = 'call' OPT_SCOPE_NOTIFIED = 'notified' class DocBlock(object): def __init__(self, name, options): self.name = name self.options = options self.value = None self.tags = odict() self.comment = None def __repr__(self): return '' % (self.name, self.options) def get(self, name): return self.tags.get(name) class DocTag(object): def __init__(self, name): self.name = name self.options = {} self.comment = None self.value = '' def __repr__(self): return '' % (self.name, self.options) class Option(object): def __init__(self, option): self._array = [] self._dict = {} for p in option.split(' '): if '=' in p: name, value = p.split('=', 1) else: name = p value = None self._dict[name] = value if value is None: self._array.append(name) else: self._array.append((name, value)) def __repr__(self): return '