B
    0ªaŒ ã               @   s6  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	m
Z
 ddlmZmZmZ d	d
l	mZmZ d	dlmZmZmZ dZd	ZdZdZdZdZdZdZeeeegZdZdZeegZdZ dZ!e e!gZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,e#e$e%e&e'e(e)e*e+e,g
Z-ee e" e- Z.d Z/d!Z0d"Z1d#Z2dZ3d$Z4d%Z5d&Z6d'Z7d(Z8d)Z9d*Z:d+Z;d,Z<d-Z=d.Z>d/Z?d0Z@d1ZAd2ZBd3ZCd4ZDd5ZEdZFdZGd6ZHdZIdZJe1e=e>e?e2e3e4e5e6e7e8e9e:e;e<e@eAeBeCeDeEeFeGeHeIeJgZKd7ZLd8ZMeLeMgZNeKeN ZOe2e3gZPd9d:„ eOD ƒZQd;ZRd<ZSd=ZTeReSeTgZUd>ZVd?ZWeVeWgZXd-ZYeYgZZd@Z[dAZ\dBZ]e[e\e]gZ^dCZ_dDZ`dEZadFZbe_e`eaebgZce ddGeje¡Zfe ddHejeejgB ¡Zhe ddIejeejgB ¡Zie ddJejeejgB ¡Zje ddKejeejgB ¡Zke ddLejeejgB ¡Zle ddMejeejgB ¡Zme ddNejeejgB ¡Zne ddOejeejgB ¡Zoe ddPejeejgB ¡Zpe ddQejeejgB ¡ZqdR re.¡ sdSdT¡Zte ddUet dV ejeejgB ejuB ¡Zve ddWejeejgB ¡Zwe ddXejeejgB ejuB ¡ZxG dYdZ„ dZeƒZyG d[d\„ d\ezƒZ{G d]d^„ d^e{ƒZ|G d_d`„ d`e{ƒZ}G dadb„ dbe{ƒZ~e
dcdddedfdgdhgƒZe
dcdddedfdgƒZ€G didj„ djezƒZG dkdl„ dlezƒZ‚dS )mu  
GTK-Doc comment block format
----------------------------

A GTK-Doc comment block is built out of multiple parts. Each part can be further
divided into fields which are separated by a colon ("``:``") delimiter.

Known parts and the fields they are constructed from look like the following
(optional fields are enclosed in square brackets)::

    â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
    â”‚ /**                                                       â”‚ â”€â–· start token
    â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    â”‚  * identifier_name â”‚ [: annotations]                      â”‚ â”€â–· identifier part
    â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¼â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    â”‚  * @parameter_name â”‚ [: annotations] â”‚ : description      â”‚ â”€â–· parameter part
    â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    â”‚  *                                                        â”‚ â”€â–· comment block description
    â”‚  * comment_block_description                              â”‚
    â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    â”‚  * tag_name â”‚ [: annotations] â”‚ [: value] â”‚ : description â”‚ â”€â–· tag part
    â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    â”‚  */                                                       â”‚ â”€â–· end token
    â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

There are two conditions that must be met before a comment block is recognized
as a GTK-Doc comment block:

#. The comment block is opened with a GTK-Doc start token ("``/**``")
#. The first line following the start token contains a valid identifier part

Once a GTK-Doc comment block has been identified as such and has been stripped
from its start and end tokens the remaining parts have to be written in a
specific order:

#. There must be exactly 1 `identifier` part on the first line of the
   comment block which consists of:

   * a required `identifier_name` field
   * an optional `annotations` field, optionally spanning multiple lines

#. Zero or more `parameter` parts, each consisting of:

   * a required `parameter_name` field
   * an optional `annotations` field, optionally spanning multiple lines
   * a required `description` field (can be the empty string)

#. One optional `comment block description` part which must begin with at
   least 1 empty line signaling the start of this part.

#. Zero or more `tag` parts, each consisting of:

   * a required `tag_name` field
   * an optional `annotations` field, optionally spanning multiple lines
   * an optional `value` field
   * a required `description` field (can be the empty string)

Additionally, the following restrictions are in effect:

#. Separating parts with an empty line:

   * `identifier` and `parameter` parts cannot be separated from each other by
     an empty line as this would signal the start of the
     `comment block description` part (see above).
   * it is required to separate the `comment block description` part from the
     `identifier` or `parameter` parts with an empty line (see above)
   * `comment block description` and `tag` parts can optionally be separated
     by an empty line

#. Parts and fields cannot span multiple lines, except for:

   * the `comment_block_description` part
   * `parameter description` and `tag description` fields
   * `identifier`, `parameter` and `tag` part `annotations` fields

#. Taking the above restrictions into account, spanning multiple paragraphs is
   limited to the `comment block description` part and `tag description` fields.

Refer to the `GTK-Doc manual`_ for more detailed usage information.

.. _GTK-Doc manual:
        http://developer.gnome.org/gtk-doc-manual/1.18/documenting.html.en
é    )Úabsolute_import)Údivision)Úprint_function)Úunicode_literalsN)Ú
namedtuple)ÚneÚgtÚlté   )ÚCounterÚOrderedDict)ÚPositionÚwarnÚerroré   é   Z
deprecatedZreturnsZsinceZ	stabilityÚdescriptionzreturn valueÚreturnzreturns valueÚ
attributeszget value funczref funcz	rename tozset value funcZtransferÚtypez
unref funcÚvalueZvirtualú(ú)z
allow-noneZarrayZclosureÚconstructorZdestroyzelement-typeZforeignzget-value-funcÚinZinoutÚmethodZnullableZoptionalÚnotÚoutzref-funcz	rename-toZscopezset-value-funcÚskipz
unref-funcZ	attributezin-outc             C   s   g | ]}|t kr|‘qS © )ÚDICT_ANNOTATIONS)Ú.0Úannr   r   ú</usr/lib/gobject-introspection/giscanner/annotationparser.pyú
<listcomp>  s    r$   z
fixed-sizeÚlengthzzero-terminatedzcallee-allocateszcaller-allocatesÚasyncZcallZnotifiedZ	containerZfloatingZfullÚnonez
\r\n|\r|\naV  
    ^                                                    # start
    (?P<code>.*?)                                        # whitespace, code, ...
    \s*                                                  # 0 or more whitespace characters
    (?P<token>/\*{2}(?![\*/]))                           # 1 forward slash character followed
                                                         #   by exactly 2 asterisk characters
                                                         #   and not followed by a slash character
    \s*                                                  # 0 or more whitespace characters
    (?P<comment>.*?)                                     # GTK-Doc comment text
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    aû  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    (?P<comment>.*?)                                     # GTK-Doc comment text
    \s*                                                  # 0 or more whitespace characters
    (?P<token>\*+/)                                      # 1 or more asterisk characters followed
                                                         #   by exactly 1 forward slash character
    (?P<code>.*?)                                        # whitespace, code, ...
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    a
  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    (?P<comment>.*?)                                     # invalid comment text
    \s*                                                  # 0 or more whitespace characters
    \*                                                   # 1 asterisk character
    \s?                                                  # 0 or 1 whitespace characters
                                                         #   WARNING: removing more than 1
                                                         #   whitespace character breaks
                                                         #   embedded example program indentation
    zs
    ^
    (?P<indentation>\s*)                                 # 0 or more whitespace characters
    .*
    $
    zà
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    a0  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    SECTION                                              # SECTION
    \s*                                                  # 0 or more whitespace characters
    (?P<delimiter>:?)                                    # delimiter
    \s*                                                  # 0 or more whitespace characters
    (?P<section_name>\w\S+?)                             # section name
    \s*                                                  # 0 or more whitespace characters
    :?                                                   # invalid delimiter
    \s*                                                  # 0 or more whitespace characters
    $
    az  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    (?P<symbol_name>[\w-]*\w)                            # symbol name
    \s*                                                  # 0 or more whitespace characters
    (?P<delimiter>:?)                                    # delimiter
    \s*                                                  # 0 or more whitespace characters
    (?P<fields>.*?)                                      # annotations + description
    \s*                                                  # 0 or more whitespace characters
    :?                                                   # invalid delimiter
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    aÄ  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    (?P<class_name>[\w]+)                                # class name
    \s*                                                  # 0 or more whitespace characters
    :{1}                                                 # 1 required colon
    \s*                                                  # 0 or more whitespace characters
    (?P<property_name>[\w-]*\w)                          # property name
    \s*                                                  # 0 or more whitespace characters
    (?P<delimiter>:?)                                    # delimiter
    \s*                                                  # 0 or more whitespace characters
    (?P<fields>.*?)                                      # annotations + description
    \s*                                                  # 0 or more whitespace characters
    :?                                                   # invalid delimiter
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    aÃ  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    (?P<class_name>[\w]+)                                # class name
    \s*                                                  # 0 or more whitespace characters
    :{2}                                                 # 2 required colons
    \s*                                                  # 0 or more whitespace characters
    (?P<signal_name>[\w-]*\w)                            # signal name
    \s*                                                  # 0 or more whitespace characters
    (?P<delimiter>:?)                                    # delimiter
    \s*                                                  # 0 or more whitespace characters
    (?P<fields>.*?)                                      # annotations + description
    \s*                                                  # 0 or more whitespace characters
    :?                                                   # invalid delimiter
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    a'  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    @                                                    # @ character
    (?P<parameter_name>[\w-]*\w|.*?\.\.\.)               # parameter name
    \s*                                                  # 0 or more whitespace characters
    :{1}                                                 # 1 required delimiter
    \s*                                                  # 0 or more whitespace characters
    (?P<fields>.*?)                                      # annotations + description
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    ú|ú z\sz®
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    (?P<tag_name>a  )                 # tag name
    \s*                                                  # 0 or more whitespace characters
    :{1}                                                 # 1 required delimiter
    \s*                                                  # 0 or more whitespace characters
    (?P<fields>.*?)                                      # annotations + value + description
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    a¾  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    (?P<value>([0-9\.])*)                                # value
    \s*                                                  # 0 or more whitespace characters
    (?P<delimiter>:?)                                    # delimiter
    \s*                                                  # 0 or more whitespace characters
    (?P<description>.*?)                                 # description
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    a¾  
    ^                                                    # start
    \s*                                                  # 0 or more whitespace characters
    (?P<value>(stable|unstable|private|internal)?)       # value
    \s*                                                  # 0 or more whitespace characters
    (?P<delimiter>:?)                                    # delimiter
    \s*                                                  # 0 or more whitespace characters
    (?P<description>.*?)                                 # description
    \s*                                                  # 0 or more whitespace characters
    $                                                    # end
    c               @   s&   e Zd ZdZdZddd„Zdd„ ZdS )	ÚGtkDocAnnotationszó
    An ordered dictionary mapping annotation names to annotation options (if any). Annotation
    options can be either a :class:`list`, a :class:`giscanner.collections.OrderedDict`
    (depending on the annotation name)or :const:`None`.
    ÚpositionNc             C   s   t  | |¡ || _d S )N)r   Ú__init__r+   )Úselfr+   Zsequencer   r   r#   r,   
  s    zGtkDocAnnotations.__init__c             C   s   t | j| ƒS )N)r*   r+   )r-   r   r   r#   Ú__copy__  s    zGtkDocAnnotations.__copy__)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r,   r.   r   r   r   r#   r*     s   
r*   c               @   s  e Zd ZdZdZdZdCdd„Zdd„ Zd	d
„ Zdd„ Z	dDdd„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Z d;d<„ Z!d=d>„ Z"d?d@„ Z#dAdB„ Z$dS )EÚGtkDocAnnotatablezK
    Base class for GTK-Doc comment block parts that can be annotated.
    )r+   Úannotationsr   Nc             C   s   || _ tƒ | _d S )N)r+   r*   r5   )r-   r+   r   r   r#   r,   !  s    zGtkDocAnnotatable.__init__c             C   s   d| j f S )Nz<GtkDocAnnotatable '%s' %r>)r5   )r-   r   r   r#   Ú__repr__*  s    zGtkDocAnnotatable.__repr__c             C   sÚ   | j rÖ| j j}xÆ| j  ¡ D ]¸\}}|| jkrPt| d| dd¡ ƒ}||||ƒ n*|tkrjtd|f |ƒ ntd|f |ƒ |tkrt	|krt
| j kr®tdtd t	 t
f |ƒ t| j krtdtd t	 tf |ƒ qW dS )	za
        Validate annotations stored by the :class:`GtkDocAnnotatable` instance, if any.
        Z_do_validate_ú-Ú_zunexpected annotation: %szunknown annotation: %sz&cannot have both "%s" and "%s" presentr)   N)r5   r+   ÚitemsÚvalid_annotationsÚgetattrÚreplaceÚALL_ANNOTATIONSr   ÚANN_NOTÚOPT_NOT_NULLABLEÚANN_NULLABLEÚANN_ALLOW_NONE)r-   r+   Úann_nameÚoptionsÚvalidater   r   r#   rD   -  s$    


zGtkDocAnnotatable.validatec       	      C   sb   |dkrd}n
d|f }|dkr&d}n|dkr4d}n
d|f }|||ƒr^t d||||f |ƒ d	S )
a,  
        Validate the number of options held by an annotation according to the test
        ``operator(n_options, expected_n_options)``.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param n_options: number of options held by the annotation
        :param expected_n_options: number of expected options
        :param operator: an operator function from python's :mod:`operator` module, for example
                         :func:`operator.ne` or :func:`operator.lt`
        :param message: warning message used when the test
                        ``operator(n_options, expected_n_options)`` fails.
        r   r'   z%dz
no optionsr
   z
one optionz
%d optionsz"%s" annotation %s %s, %s givenN)r   )	r-   r+   rB   Ú	n_optionsZexpected_n_optionsÚoperatorÚmessageÚtÚsr   r   r#   Ú_validate_optionsN  s    


z#GtkDocAnnotatable._validate_optionsc       
      C   sŽ   t |ƒ}|dk	r$|  ||||td¡ |dk	r@|  ||||td¡ |dk	r\|  ||||td¡ |rŠ|dk	rŠ|d }	|	|krŠtd||	f |ƒ dS )aß  
        Validate an annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to be validated
        :param choices: an iterable of allowed option names or :const:`None` to skip this test
        :param exact_n_options: exact number of expected options or :const:`None` to skip this test
        :param min_n_options: minimum number of expected options or :const:`None` to skip this test
        :param max_n_options: maximum number of expected options or :const:`None` to skip this test
        NZneedsztakes at leastztakes at mostr   z$invalid "%s" annotation option: "%s")ÚlenrJ   r   r	   r   r   )
r-   r+   rB   rC   ÚchoicesÚexact_n_optionsÚmin_n_optionsÚmax_n_optionsrE   Úoptionr   r   r#   Ú_validate_annotationn  s    z&GtkDocAnnotatable._validate_annotationc             C   s   | j |||dd dS )am  
        Validate the ``(allow-none)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options held by the annotation
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_allow_none  s    
z)GtkDocAnnotatable._do_validate_allow_nonec          
   C   sì   t |ƒdkrdS xÖ| ¡ D ]Ê\}}|tkr‚yt|ƒ W qä ttfk
r~   |dkrftd||f |ƒ ntd|||f |ƒ Y qäX q|tkr°|dk	rä|dkrätd|||f |ƒ q|tkrÒ|dkrätd|f |ƒ qtd||f |ƒ qW dS )	ah  
        Validate the ``(array)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options held by the annotation
        r   Nz)"%s" annotation option "%s" needs a valuezBinvalid "%s" annotation option "%s" value "%s", must be an integer)Ú0Ú1z>invalid "%s" annotation option "%s" value "%s", must be 0 or 1z-"%s" annotation option "length" needs a valuez$invalid "%s" annotation option: "%s")	rK   r9   ÚOPT_ARRAY_FIXED_SIZEÚintÚ	TypeErrorÚ
ValueErrorr   ÚOPT_ARRAY_ZERO_TERMINATEDÚOPT_ARRAY_LENGTH)r-   r+   rB   rC   rP   r   r   r   r#   Ú_do_validate_arrayœ  s0    



z$GtkDocAnnotatable._do_validate_arrayc             C   s   dS )ab  
        Validate the ``(attributes)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        Nr   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_attributesÂ  s    z)GtkDocAnnotatable._do_validate_attributesc             C   s   | j |||dd dS )a_  
        Validate the ``(closure)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rO   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_closureÏ  s    
z&GtkDocAnnotatable._do_validate_closurec             C   s   | j |||dd dS )ac  
        Validate the ``(constructor)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_constructorÛ  s    
z*GtkDocAnnotatable._do_validate_constructorc             C   s   | j |||dd dS )a_  
        Validate the ``(destroy)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_destroyç  s    
z&GtkDocAnnotatable._do_validate_destroyc             C   s   | j |||ddd dS )a_  
        Validate the ``(element)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   r   )rN   rO   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_element_typeó  s    
z+GtkDocAnnotatable._do_validate_element_typec             C   s   | j |||dd dS )a_  
        Validate the ``(foreign)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_foreignÿ  s    
z&GtkDocAnnotatable._do_validate_foreignc             C   s   | j |||dd dS )ab  
        Validate the ``(value-func)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_get_value_func  s    
z-GtkDocAnnotatable._do_validate_get_value_funcc             C   s   | j |||dd dS )aZ  
        Validate the ``(in)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_in  s    
z!GtkDocAnnotatable._do_validate_inc             C   s   | j |||dd dS )a^  
        Validate the ``(in-out)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_inout#  s    
z$GtkDocAnnotatable._do_validate_inoutc             C   s   | j |||dd dS )a^  
        Validate the ``(method)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_method/  s    
z%GtkDocAnnotatable._do_validate_methodc             C   s   | j |||dd dS )ak  
        Validate the ``(nullable)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options held by the annotation
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_nullable;  s    
z'GtkDocAnnotatable._do_validate_nullablec             C   s   | j |||dd dS )ak  
        Validate the ``(optional)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options held by the annotation
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_optionalG  s    
z'GtkDocAnnotatable._do_validate_optionalc             C   s   | j |||dtd dS )af  
        Validate the ``(not)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options held by the annotation
        r
   )rM   rL   N)rQ   ÚNOT_OPTIONS)r-   r+   rB   rC   r   r   r#   Ú_do_validate_notS  s    
z"GtkDocAnnotatable._do_validate_notc             C   s   | j |||dtd dS )a[  
        Validate the ``(out)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rO   rL   N)rQ   ÚOUT_OPTIONS)r-   r+   rB   rC   r   r   r#   Ú_do_validate_out`  s    
z"GtkDocAnnotatable._do_validate_outc             C   s   | j |||dd dS )a`  
        Validate the ``(ref-func)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_ref_funcm  s    
z'GtkDocAnnotatable._do_validate_ref_funcc             C   s   | j |||dd dS )aa  
        Validate the ``(rename-to)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_rename_toy  s    
z(GtkDocAnnotatable._do_validate_rename_toc             C   s   | j |||dtd dS )a]  
        Validate the ``(scope)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   rL   N)rQ   ÚSCOPE_OPTIONS)r-   r+   rB   rC   r   r   r#   Ú_do_validate_scope…  s    
z$GtkDocAnnotatable._do_validate_scopec             C   s   | j |||dd dS )ab  
        Validate the ``(value-func)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_set_value_func’  s    
z-GtkDocAnnotatable._do_validate_set_value_funcc             C   s   | j |||dd dS )a\  
        Validate the ``(skip)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_skipž  s    
z#GtkDocAnnotatable._do_validate_skipc             C   s   | j |||dtd dS )a`  
        Validate the ``(transfer)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   rL   N)rQ   ÚTRANSFER_OPTIONS)r-   r+   rB   rC   r   r   r#   Ú_do_validate_transferª  s    
z'GtkDocAnnotatable._do_validate_transferc             C   s   | j |||dd dS )a\  
        Validate the ``(type)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_type·  s    
z#GtkDocAnnotatable._do_validate_typec             C   s   | j |||dd dS )ab  
        Validate the ``(unref-func)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_unref_funcÃ  s    
z)GtkDocAnnotatable._do_validate_unref_funcc             C   s   | j |||dd dS )a]  
        Validate the ``(value)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_valueÏ  s    
z$GtkDocAnnotatable._do_validate_valuec             C   s   | j |||dd dS )a_  
        Validate the ``(virtual)`` annotation.

        :param position: :class:`giscanner.message.Position` of the line in the source file
                         containing the annotation to be validated
        :param ann_name: name of the annotation holding the options to validate
        :param options: annotation options to validate
        r
   )rM   N)rQ   )r-   r+   rB   rC   r   r   r#   Ú_do_validate_virtualÛ  s    
z&GtkDocAnnotatable._do_validate_virtual)N)NNNN)%r/   r0   r1   r2   r3   r:   r,   r6   rD   rJ   rQ   rR   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   ri   rk   rl   rm   ro   rp   rq   rs   rt   ru   rv   rw   r   r   r   r#   r4     sF   
	!  
!&r4   c               @   sJ   e Zd ZdZdZeeeee	e
eeeeeeeeeefZddd„Zdd„ ZdS )	ÚGtkDocParameterz.
    Represents a GTK-Doc parameter part.
    )Únamer   Nc             C   s   t  | |¡ || _d | _d S )N)r4   r,   ry   r   )r-   ry   r+   r   r   r#   r,   ó  s    zGtkDocParameter.__init__c             C   s   d| j | jf S )Nz<GtkDocParameter '%s' %r>)ry   r5   )r-   r   r   r#   r6   ü  s    zGtkDocParameter.__repr__)N)r/   r0   r1   r2   r3   rA   Ú	ANN_ARRAYÚANN_ATTRIBUTESÚANN_CLOSUREÚANN_DESTROYÚANN_ELEMENT_TYPEÚANN_INÚ	ANN_INOUTÚANN_OUTÚ	ANN_SCOPEÚANN_SKIPÚANN_TRANSFERÚANN_TYPEÚANN_OPTIONALr@   r>   r:   r,   r6   r   r   r   r#   rx   è  s   

	rx   c            
   @   s>   e Zd ZdZdZeeeee	e
eeeef
Zddd„Zdd„ ZdS )	Ú	GtkDocTagz(
    Represents a GTK-Doc tag part.
    )ry   r   r   Nc             C   s"   t  | |¡ || _d | _d | _d S )N)r4   r,   ry   r   r   )r-   ry   r+   r   r   r#   r,   
  s    zGtkDocTag.__init__c             C   s   d| j | jf S )Nz<GtkDocTag '%s' %r>)ry   r5   )r-   r   r   r#   r6     s    zGtkDocTag.__repr__)N)r/   r0   r1   r2   r3   rA   rz   r{   r~   rƒ   r„   r…   r@   r†   r>   r:   r,   r6   r   r   r   r#   r‡      s   

r‡   c               @   sŽ   e Zd ZdZdZeeeee	e
eeeeeeeefZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚGtkDocCommentBlockz-
    Represents a GTK-Doc comment block.
    )Úcode_beforeÚ
code_afterÚindentationry   Úparamsr   ÚtagsNc             C   s>   t  | |¡ d | _d | _g | _|| _tƒ | _d | _tƒ | _	d S )N)
r4   r,   r‰   rŠ   r‹   ry   r   rŒ   r   r   )r-   ry   r+   r   r   r#   r,   '  s    zGtkDocCommentBlock.__init__c             C   s   || j |j ƒS )N)ry   )r-   ÚotherÚopr   r   r#   Ú_compareB  s    zGtkDocCommentBlock._comparec             C   s   |   |tj¡S )N)r   rF   r	   )r-   rŽ   r   r   r#   Ú__lt__H  s    zGtkDocCommentBlock.__lt__c             C   s   |   |tj¡S )N)r   rF   r   )r-   rŽ   r   r   r#   Ú__gt__K  s    zGtkDocCommentBlock.__gt__c             C   s   |   |tj¡S )N)r   rF   Úge)r-   rŽ   r   r   r#   Ú__ge__N  s    zGtkDocCommentBlock.__ge__c             C   s   |   |tj¡S )N)r   rF   Úle)r-   rŽ   r   r   r#   Ú__le__Q  s    zGtkDocCommentBlock.__le__c             C   s   |   |tj¡S )N)r   rF   Úeq)r-   rŽ   r   r   r#   Ú__eq__T  s    zGtkDocCommentBlock.__eq__c             C   s   |   |tj¡S )N)r   rF   r   )r-   rŽ   r   r   r#   Ú__ne__W  s    zGtkDocCommentBlock.__ne__c             C   s
   t | jƒS )N)Úhashry   )r-   r   r   r#   Ú__hash__Z  s    zGtkDocCommentBlock.__hash__c             C   s   d| j | jf S )Nz<GtkDocCommentBlock '%s' %r>)ry   r5   )r-   r   r   r#   r6   ]  s    zGtkDocCommentBlock.__repr__c             C   sF   t  | ¡ x| j ¡ D ]}| ¡  qW x| j ¡ D ]}| ¡  q2W dS )zz
        Validate annotations applied to the :class:`GtkDocCommentBlock` identifier, parameters
        and tags.
        N)r4   rD   rŒ   Úvaluesr   )r-   ÚparamÚtagr   r   r#   rD   `  s
    
zGtkDocCommentBlock.validate)N)r/   r0   r1   r2   r3   r{   ÚANN_CONSTRUCTORÚANN_FOREIGNÚANN_GET_VALUE_FUNCÚ
ANN_METHODÚANN_REF_FUNCÚANN_RENAME_TOÚANN_SET_VALUE_FUNCrƒ   r„   r…   ÚANN_UNREF_FUNCÚ	ANN_VALUEÚ	ANN_VFUNCr:   r,   r   r‘   r’   r”   r–   r˜   r™   r›   r6   rD   r   r   r   r#   rˆ     s    
rˆ   ZResultÚsuccessr5   Úannotations_changedÚ	start_posÚend_posc               @   s\   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
ddd„Zddd„ZdS )ÚGtkDocCommentBlockParseraþ  
    Parse GTK-Doc comment blocks into a parse tree built out of :class:`GtkDocCommentBlock`,
    :class:`GtkDocParameter`, :class:`GtkDocTag` and :class:`GtkDocAnnotations`
    objects. This parser tries to accept malformed input whenever possible and does
    not cause the process to exit on syntax errors. It does however emit:

        * warning messages at the slightest indication of recoverable malformed input and
        * error messages for unrecoverable malformed input

    whenever possible. Recoverable, in this context, means that we can serialize the
    :class:`GtkDocCommentBlock` instance using a :class:`GtkDocCommentBlockWriter` without
    information being lost. It is usually a good idea to heed these warning and error messages
    as malformed input can result in both:

        * invalid GTK-Doc output (HTML, pdf, ...) when the comment blocks are parsed
          with GTK-Doc's gtkdoc-mkdb
        * unexpected introspection behavior, for example missing parameters in the
          generated .gir and .typelib files

    .. NOTE:: :class:`GtkDocCommentBlockParser` functionality is based on gtkdoc-mkdb's
        `ScanSourceFile()`_ function.

    .. _ScanSourceFile():
           http://git.gnome.org/browse/gtk-doc/tree/gtkdoc-mkdb.in#n3722
    c       
      C   sÀ   i }x¶|D ]®\}}}y|   |||¡}W n< tk
rb } ztdt|ƒ t||ƒƒ w
W dd}~X Y nX |dk	r
|j|kr®||j }tj |j	j
¡}	td|j|j	 |	¡f |j	ƒ |||j< q
W |S )zç
        Parse multiple GTK-Doc comment blocks.

        :param comments: an iterable of ``(comment, filename, lineno)`` tuples
        :returns: a dictionary mapping identifier names to :class:`GtkDocCommentBlock` objects
        z‹unrecoverable parse error, please file a GObject-Introspection bugreport including the complete comment block at the indicated location. %sNzJmultiple comment blocks documenting '%s:' identifier (already seen at %s).)Úparse_comment_blockÚ	Exceptionr   Ústrr   ry   ÚosÚpathÚdirnamer+   Úfilenamer   Úformat)
r-   ZcommentsZcomment_blocksÚcommentr´   ÚlinenoÚcomment_blockÚeZ	firstseenr²   r   r   r#   Úparse_comment_blocks’  s$    

z-GtkDocCommentBlockParser.parse_comment_blocksc       0   
   C   sN  d}d}t ||ƒ}t td|¡ d¡}t|ƒ}t |d ¡}	|	ræ|dkrpt ||ƒ}
td|
d|	 	d¡|d ƒ dS |	 
d¡}|	 
d¡}|r¬t ||ƒ}
td	|
d|	 	d¡|d ƒ |rÞt ||ƒ}
td
|
d|	 d¡|d ƒ ||d< qê|d= ndS t |d ¡}	|	rˆ|	 
d¡}|	 
d¡}|rDt ||| d ƒ}
td|
d|	 	d¡|d ƒ |r€t ||| d ƒ}
td|
d|	 	d¡|d ƒ ||d< n|d= ndS d}d}g }d}d}d}d}d}	x*|D 	] }|d7 }t ||ƒ}
|}d}t |¡}	| |	 
d¡¡ t |¡}	|	r@|	 
d¡}|r$td|
d|	 d¡|ƒ |	 	d¡}||	 	d¡d… }t |¡}	t|	 
d¡ dd¡ƒ}|dkr4t |¡}	|	r˜d|	 
d¡f }d}d}d}nÎt |¡}	|	ràd|	 
d¡|	 
d¡f }|	 
d¡}|	 
d¡}|	 d¡}n†t |¡}	|	r(d|	 
d¡|	 
d¡f }|	 
d¡}|	 
d¡}|	 d¡}n>t |¡}	|	rfd|	 
d¡f }|	 
d¡}|	 
d¡}|	 d¡}|	rt}|}t||ƒ}||_||_|r|  |
|| ||¡}|jr||jd…  ¡ rÒd}	d}d}d}n>|j|_|s|jr||	 d¡ }td|d f |
d||ƒ |	s´|s´d}td |
d||ƒ q´t |¡}	|	rÒ|}|	 
d!¡}|  ¡ }|	 
d¡}|	 d¡}|	 d!¡| }|tt!gkr td"|f |
d||ƒ t!}|t"kr t"}|s¾d}ntd#|j#f |
ƒ t$t"|
ƒ} |r|  %|
|| ||¡}	|	jr|	j| _|	j&| _&| |j't"< | }q´n:|d$ks@| (d%¡rZ|d%krZtd&|f |
d||ƒ d%}||j) *¡ kr„td'||j#f |
d||ƒ t+||
ƒ}!|rÀ|  %|
|| ||¡}	|	jrÀ|	j|!_|	j&|!_&|!|j)|< |!}q´t, |¡rø|tt!gkrøt-}|}q´t. |¡}	|		rÈ||k	rÈ|}|	 
d(¡}"|"  ¡ }#|	 
d¡}$|	 d¡}%|	 d(¡| }|#t/krºtd)|"f |
d||ƒ |# d*d+¡}&|#t0krŠd}'|  %|
|	 d(¡| ||$ ¡ ddd¡}	|	jr´xz|	jD ]p}(|  1|
|||(¡})t|)ƒ}*|*dkrðd,|'|)d f }'n6|*d-krd.|'|)d |)d f }'ntd/|
d||ƒ d}'q¸W |'r´d,|&|' ¡ f }'|  2|
||% ||'¡\}&}+|j 3d0¡},|,r~td1|
d||ƒ n
|+|j|&< n*|  2|
||% |d,|&|$f ¡\}&}-|-|j|&< q´nJ|#t4krtd2|
d||ƒ t-}|j&dkrì|$|_&n| j&d3|$f 7  _&q´|t-ks:|t!kr |j&r:|tkr>|j)s>|j&s>t5}|t5krbt5}td4|"f |
d||ƒ |#t6t"t7t8gkrâ|s€d}ntd5|j#f |
ƒ t$t"|
ƒ} |$rÎ|  %|
||% ||$¡}	|	jrÎ|	j| _|	j&| _&| |j't"< | }q´næ|#|j' *¡ k	rtd6|"|j#f |
d||ƒ t$|#|
ƒ} |$	r¶|  %|
||% ||$¡}	|	j	r¶|	j	rPtd7|"f |
ƒ |#t9t:gk	r„t; |	j&¡}	|	 
d8¡| _<|	 
d9¡| _&n2|#t=k	r¶t> |	j&¡}	|	 
d8¡ ?¡ | _<|	 
d9¡| _&| |j'|#< | }q´t, |¡dk	rà| @¡ }|tt-gk
r\|j&
s0|tk
r0|  |
||||j¡}.|.j
r0|.jA
r0|.j|_q´|j&dk
rD||_&n| j&d| 7  _&q´nx|t!t5gkr´|j&
sª|  %|
||||j¡}.|.j
rª|.jA
rª|.j|_|.j&|_&q´|j&dk
r¾||_&n| j&d| 7  _&q´q´W |rF|j&
rô|j& ¡ |_&x|j' B¡ D ]} |  C| ¡ q W x|j) B¡ D ]}/|  C|/¡ q W ||_D| E¡  |S dS dS ):a¼  
        Parse a single GTK-Doc comment block.

        :param comment: string representing the GTK-Doc comment block including it's
                        start ("``/**``") and end ("``*/``") tokens.
        :param filename: source file name where the comment block originated from
        :param lineno: line number in the source file where the comment block starts
        :returns: a :class:`GtkDocCommentBlock` object or ``None``
        Ú Ú
r   r
   z'Skipping invalid GTK-Doc comment block:NÚcoder¶   zGGTK-Doc comment block start token "/**" should not be preceded by code:zOGTK-Doc comment block start token "/**" should not be followed by comment text:éÿÿÿÿzDGTK-Doc comment block end token "*/" should not be followed by code:zLGTK-Doc comment block end token "*/" should not be preceded by comment text:Fr‹   zinvalid comment text:ú	z  z
SECTION:%sZsection_namez%s:%sÚ
class_nameZproperty_nameZ	delimiterÚfieldsz%s::%sZsignal_namez%sZsymbol_namezmissing ":" at column %s:Tz'identifier not found on the first line:Zparameter_namez,"@%s" parameter unexpected at this location:z;encountered multiple "Returns" parameters or tags for "%s".ZVarargsz...z9"@%s" parameter is deprecated, please use "@..." instead:z.multiple "@%s" parameters for identifier "%s":Útag_namezvGObject-Introspection specific GTK-Doc tag "%s" has been deprecated, please use annotations on the identifier instead:r)   r7   z%s %sr   z%s %s=%sz,malformed "Attributes:" tag will be ignored:r   z3Duplicate "Attributes:" annotation will be ignored:z/GTK-Doc tag "Description:" has been deprecated:z
%sz&"%s:" tag unexpected at this location:z>encountered multiple return value parameters or tags for "%s".z(multiple "%s:" tags for identifier "%s":z(annotations not supported for tag "%s:".r   r   )Fr   ÚreÚsubÚLINE_BREAK_REÚsplitrK   ÚCOMMENT_BLOCK_START_REÚmatchr   ÚendÚgroupr   ÚstartÚCOMMENT_BLOCK_END_REÚINDENTATION_REÚappendÚCOMMENT_ASTERISK_REr<   Ú
SECTION_REÚPROPERTY_REÚ	SIGNAL_REÚ	SYMBOL_REÚPART_IDENTIFIERrˆ   r‰   rŠ   Ú_parse_annotationsr©   r¬   Ústripr5   ÚPARAMETER_REÚlowerÚPART_PARAMETERSÚTAG_RETURNSry   r‡   Ú_parse_fieldsr   r   ÚendswithrŒ   Úkeysrx   ÚEMPTY_LINE_REÚPART_DESCRIPTIONÚTAG_REÚDEPRECATED_GI_ANN_TAGSÚTAG_ATTRIBUTESÚ_parse_annotation_options_listÚ_parse_annotationÚgetÚTAG_DESCRIPTIONÚ	PART_TAGSÚ
TAG_RETURNÚTAG_RETURN_VALUEÚTAG_RETURNS_VALUEÚTAG_DEPRECATEDÚ	TAG_SINCEÚTAG_VALUE_VERSION_REr   ÚTAG_STABILITYÚTAG_VALUE_STABILITY_REÚ
capitalizeÚrstriprª   rœ   Ú_clean_description_fieldr‹   rD   )0r-   r¶   r´   r·   r‰   rŠ   Zcomment_block_posZcomment_linesZcomment_lines_lenÚresultr+   r¸   Zidentifier_warnedZblock_indentÚline_indentZpart_indentZin_partZcurrent_partZreturns_seenÚlineZoriginal_lineZcolumn_offsetZidentifier_nameZidentifier_delimiterZidentifier_fieldsZidentifier_fields_startZresÚ
marker_posZ
param_nameZparam_name_lowerZparam_fieldsZparam_fields_startrž   Ú	parameterrÂ   Ztag_name_lowerZ
tag_fieldsZtag_fields_startrB   ZtransformedÚ
annotationÚann_optionsrE   ZdocannotationZstored_annotationrC   Úrr   r   r   r#   r®   ·  s”   



































































z,GtkDocCommentBlockParser.parse_comment_blockc             C   sR   |j rN|j  ¡ dkrd|_ n2t |j  dd¡d ¡rB|j  ¡ |_ n|j  ¡ |_ dS )zª
        Remove extraneous leading and trailing whitespace from description fields.

        :param part: a GTK-Doc comment block part having a description field
        r»   Nr¼   r
   r   )r   rÖ   rÞ   rÈ   rÆ   rñ   )r-   Úpartr   r   r#   rò   ˜  s    z1GtkDocCommentBlockParser._clean_description_fieldc             C   sN   g }|rJ|  d¡}|dkr@td|d|| |ƒ |  ||||¡}n
| d¡}|S )u£  
        Parse annotation options into a list. For example::

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ 'option1 option2 option3'                                    â”‚ â”€â–· source
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ ['option1', 'option2', 'option3']                            â”‚ â—â”€ parsed options
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        :param position: :class:`giscanner.message.Position` of `line` in the source file
        :param column: start column of the `options` in the source file
        :param line: complete source line
        :param options: annotation options to parse
        :returns: a list of annotation options
        ú=r   zMinvalid annotation options: expected a "list" but received "key=value pairs":Nr)   )Úfindr   Ú!_parse_annotation_options_unknownrÆ   )r-   r+   Úcolumnrõ   rC   Úparsedró   r   r   r#   rã   ¨  s    

z7GtkDocCommentBlockParser._parse_annotation_options_listc       
      C   sV   t ƒ }|rRxF| d¡D ]8}| dd¡}|d }t|ƒdkrB|d nd}	|	||< qW |S )u²  
        Parse annotation options into a dict. For example::

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ 'option1=value1 option2 option3=value2'                      â”‚ â”€â–· source
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ {'option1': 'value1', 'option2': None, 'option3': 'value2'}  â”‚ â—â”€ parsed options
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        :param position: :class:`giscanner.message.Position` of `line` in the source file
        :param column: start column of the `options` in the source file
        :param line: complete source line
        :param options: annotation options to parse
        :returns: an ordered dictionary of annotation options
        r)   rü   r
   r   r   N)r   rÆ   rK   )
r-   r+   rÿ   rõ   rC   r   ÚpÚpartsÚkeyr   r   r   r#   Ú_parse_annotation_options_dictÇ  s    z7GtkDocCommentBlockParser._parse_annotation_options_dictc             C   s   |r|  ¡ gS dS )u  
        Parse annotation options into a list holding a single item. This is used when the
        annotation options to parse in not known to be a list nor dict. For example::

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ '   option1 option2   option3=value1   '                     â”‚ â”€â–· source
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ ['option1 option2   option3=value1']                         â”‚ â—â”€ parsed options
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        :param position: :class:`giscanner.message.Position` of `line` in the source file
        :param column: start column of the `options` in the source file
        :param line: complete source line
        :param options: annotation options to parse
        :returns: a list of annotation options
        N)rÖ   )r-   r+   rÿ   rõ   rC   r   r   r#   rþ   ã  s    z:GtkDocCommentBlockParser._parse_annotation_options_unknownc       	      C   sJ  |  dt¡  dt¡}| dd¡}|d  ¡ }t|ƒdkr@|d nd}|tkrjtdttf |d||ƒ t}n€|t	krêtdt	t
f |d||ƒ t
}|  ||||¡}t|ƒ}|dkr¸|d }n2|dkrÖd	|d |d f }ntd
|d||ƒ dS |t|ƒd 7 }|tkr|  ||||¡}n,|tkr2|  ||||¡}n|  ||||¡}||fS )u}  
        Parse an annotation into the annotation name and a list or dict (depending on the
        name of the annotation) holding the options. For example::

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ 'name opt1=value1 opt2=value2 opt3'                          â”‚ â”€â–· source
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ 'name', {'opt1': 'value1', 'opt2':'value2', 'opt3':None}     â”‚ â—â”€ parsed annotation
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ 'name   opt1 opt2'                                           â”‚ â”€â–· source
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ 'name', ['opt1', 'opt2']                                     â”‚ â—â”€ parsed annotation
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ 'unkownname   unknown list of options'                       â”‚ â”€â–· source
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ 'unkownname', ['unknown list of options']                    â”‚ â—â”€ parsed annotation
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        :param position: :class:`giscanner.message.Position` of `line` in the source file
        :param column: start column of the `annotation` in the source file
        :param line: complete source line
        :param annotation: annotation to parse
        :returns: a tuple containing the annotation name and options
        ú<ú>r)   r
   r   r   Nz="%s" annotation has been deprecated, please use "%s" instead:z%s=%sz3malformed "(attribute)" annotation will be ignored:)NN)r<   ÚANN_LPARÚANN_RPARrÆ   rØ   rK   ÚANN_INOUT_ALTr   r€   ÚANN_ATTRIBUTEr{   rã   r   ÚLIST_ANNOTATIONSr    r  rþ   )	r-   r+   rÿ   rõ   rø   r  rB   rù   rE   r   r   r#   rä   ø  s>    



z*GtkDocCommentBlockParser._parse_annotationNTc          	   C   sJ  |r |dkrt |ƒ}q$| ¡ }ng }d}d}	d}
d}g }d}d}xÄt|ƒD ]¶\}	}| ¡ }|tkr¼|
d7 }
|
dkrz|	}|tkr¦td|d||	 |ƒ tdddddƒS |
dkr¸| |¡ nD|tkrÌ|
d8 }
|tkrútd|d||	 |ƒ tdddddƒS |
dk r(td|d||	 |ƒ tdddddƒS |
dkrÀ|	d }|dkr¢|  	||| |d 
|¡ ¡ ¡\}}|dk	rº||kr”td	|f |d||	 |ƒ |||< d}n| d 
|¡ ¡ ¡ d}g }n
| |¡ n4|rè|
dkr | |¡ n|
dkröP n
| |¡ |}qLW |
dkr6td|d||	 |ƒ tdddddƒS td||||ƒS dS )
a  
        Parse annotations into a :class:`GtkDocAnnotations` object.

        :param position: :class:`giscanner.message.Position` of `line` in the source file
        :param column: start column of the `annotations` in the source file
        :param line: complete source line
        :param fields: string containing the fields to parse
        :param annotations: a :class:`GtkDocAnnotations` object
        :param parse_options: whether options will be parsed into a :class:`GtkDocAnnotations`
                              object or into a :class:`list`
        :returns: if `parse_options` evaluates to True a :class:`GtkDocAnnotations` object,
                  a :class:`list` otherwise. If `line` does not contain any annotations,
                  :const:`None`
        NFr   r»   r
   z4unexpected parentheses, annotations will be ignored:z4unbalanced parentheses, annotations will be ignored:Tzmultiple "%s" annotations:)r*   ÚcopyÚ	enumerateÚisspacer  r   Ú_ParseAnnotationsResultrÎ   r  rä   ÚjoinrÖ   )r-   r+   rÿ   rõ   rÁ   r5   Úparse_optionsZparsed_annotationsZparsed_annotations_changedÚiZparens_levelZ	prev_charZchar_bufferr«   r¬   Zcur_charZcur_char_is_spacery   rC   r   r   r#   rÕ   @  s€    












z+GtkDocCommentBlockParser._parse_annotationsc             C   s’   d}|   ||||||¡}	|	jr~||	jd…  ¡ }|r~|r~| d¡rP|dd… }n.|	jdkr~||	j }
td|
d f |d|
|ƒ t|	j|	j|	j|ƒS )u‚  
        Parse annotations out of field data. For example::

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ '(skip): description of some parameter'                      â”‚ â”€â–· source
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ ({'skip': []}, 'description of some parameter')              â”‚ â—â”€ annotations and
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜    remaining fields

        :param position: :class:`giscanner.message.Position` of `line` in the source file
        :param column: start column of `fields` in the source file
        :param line: complete source line
        :param fields: string containing the fields to parse
        :param parse_options: whether options will be parsed into a :class:`GtkDocAnnotations`
                              object or into a :class:`list`
        :param validate_description_field: :const:`True` to validate the description field
        :returns: if `parse_options` evaluates to True a :class:`GtkDocAnnotations` object,
                  a :class:`list` otherwise. If `line` does not contain any annotations,
                  :const:`None` and a string holding the remaining fields
        r»   Nú:r
   r   zmissing ":" at column %s:)	rÕ   r©   r¬   rÖ   Ú
startswithr   Ú_ParseFieldsResultr5   rª   )r-   r+   rÿ   rõ   rÁ   r5   r  Zvalidate_description_fieldZdescription_fieldró   rö   r   r   r#   rÛ   ¤  s    


z&GtkDocCommentBlockParser._parse_fields)NT)NTT)r/   r0   r1   r2   rº   r®   rò   rã   r  rþ   rä   rÕ   rÛ   r   r   r   r#   r­   w  s   %   dI
c r­   c               @   s:   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚGtkDocCommentBlockWriterzU
    Serialized :class:`GtkDocCommentBlock` objects into GTK-Doc comment blocks.
    Tc             C   s
   || _ d S )N)Úindent)r-   r  r   r   r#   r,   Ò  s    z!GtkDocCommentBlockWriter.__init__c             C   s¨   g }x˜|  ¡ D ]Œ\}}|rŠt|tƒr0d |¡}nFd}x8|  ¡ D ],\}}|r\|d||f 7 }q>|d|f 7 }q>W | ¡ }| d||f ¡ q| d|f ¡ qW d |¡S )uA
  
        Serialize an annotation field. For example::

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ {'name': {'opt1': 'value1', 'opt2':'value2', 'opt3':None}    â”‚ â—â”€ GtkDocAnnotations
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ '(name opt1=value1 opt2=value2 opt3)'                        â”‚ â”€â–· serialized
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ {'name': ['opt1', 'opt2']}                                   â”‚ â—â”€ GtkDocAnnotations
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ '(name opt1 opt2)'                                           â”‚ â”€â–· serialized
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

            â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
            â”‚ {'unkownname': ['unknown list of options']}                  â”‚ â—â”€ GtkDocAnnotations
            â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
            â”‚ '(unkownname unknown list of options)'                       â”‚ â”€â–· serialized
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        :param annotations: :class:`GtkDocAnnotations` to be serialized
        :returns: a string
        r)   r»   z%s=%s z%s z(%s %s)z(%s))r9   Ú
isinstanceÚlistr  rÖ   rÎ   )r-   r5   Ú
serializedrB   rC   Zserialize_optionsr  r   r   r   r#   Ú_serialize_annotations×  s    
z/GtkDocCommentBlockWriter._serialize_annotationsc             C   sj   d|j f }|jr&|d|  |j¡ 7 }|jrX|j d¡rH|d|j 7 }q`|d|j 7 }n|d7 }| d¡S )zˆ
        Serialize a parameter.

        :param parameter: :class:`GtkDocParameter` to be serialized
        :returns: a string
        z@%sz: r¼   r  )ry   r5   r  r   r  rÆ   )r-   r÷   r  r   r   r#   Ú_serialize_parameter  s    	z-GtkDocCommentBlockWriter._serialize_parameterc             C   s†   |j  ¡ }|jr$|d|  |j¡ 7 }|jr8|d|j 7 }|jrh|j d¡rZ|d|j 7 }n|d|j 7 }|js||js||d7 }| d¡S )zv
        Serialize a tag.

        :param tag: :class:`GtkDocTag` to be serialized
        :returns: a string
        z: r¼   r  )ry   rð   r5   r  r   r   r  rÆ   )r-   rž   r  r   r   r#   Ú_serialize_tag"  s    	
z'GtkDocCommentBlockWriter._serialize_tagc             C   sü  |dkrdS g }|j  d¡r*| |j ¡ n:|jrR|  |j¡}| d|j |f ¡ n| d|j f ¡ x"|j ¡ D ]}| |  |¡¡ qpW |j	r¸| d¡ x|j	 
d¡D ]}| |¡ q¦W |jrì| d¡ x"|j ¡ D ]}| |  |¡¡ qÔW | jr>t|jƒ d¡d d pd	}| d
¡r,|}|d	 }	n|dd… }|}	nd}d	}	d}
xJ|
t|ƒk r”||
 }|rzd|	|f ||
< nd|	f ||
< |
d7 }
qLW | dd|f ¡ | d|	f ¡ |jrÔ| dd|jf ¡ |jrî| d|jf ¡ d |¡S dS )z 
        Serialize a :class:`GtkDocCommentBlock` object.

        :param block: :class:`GtkDocCommentBlock` to be serialized
        :returns: a string
        Nr»   ZSECTIONz%s: %sz%s:r¼   r
   r   r)   r¿   r¾   z%s* %s
z%s*
z%s/**
z%s*/
z%s
)ry   r  rÎ   r5   r  rŒ   rœ   Úextendr  r   rÆ   r   r  r  r   r‹   Úmost_commonrÜ   rK   Úinsertr‰   rŠ   r  )r-   ÚblockÚlinesr5   r   Úlrž   r  Zstart_indentrô   r  rõ   r   r   r#   ÚwriteA  sT    


zGtkDocCommentBlockWriter.writeN)T)	r/   r0   r1   r2   r,   r  r  r  r$  r   r   r   r#   r  Í  s   
1r  )ƒr2   Z
__future__r   r   r   r   r±   rÃ   rF   Úcollectionsr   r   r   r	   r   r   rG   r   r   r   rÔ   rÙ   rß   rç   rë   rÚ   rì   rî   ZGTKDOC_TAGSræ   ré   ZDEPRECATED_GTKDOC_TAGSrè   rê   ZDEPRECATED_GI_TAGSrâ   ZTAG_GET_VALUE_FUNCZTAG_REF_FUNCZTAG_RENAME_TOZTAG_SET_VALUE_FUNCZTAG_TRANSFERZTAG_TYPEZTAG_UNREF_FUNCZ	TAG_VALUEZ	TAG_VFUNCrá   ZALL_TAGSr  r  rA   rz   r{   r|   rŸ   r}   r~   r    r¡   r   r€   r¢   r@   r†   r>   r   r£   r¤   r‚   r¥   rƒ   r„   r…   r¦   r¨   r§   ZGI_ANNSr
  r	  ZDEPRECATED_GI_ANNSr=   r    r  rU   rZ   rY   ZARRAY_OPTIONSZOPT_OUT_CALLEE_ALLOCATESZOPT_OUT_CALLER_ALLOCATESrj   r?   rh   ZOPT_SCOPE_ASYNCZOPT_SCOPE_CALLZOPT_SCOPE_NOTIFIEDrn   ZOPT_TRANSFER_CONTAINERZOPT_TRANSFER_FLOATINGZOPT_TRANSFER_FULLZOPT_TRANSFER_NONErr   ÚcompileÚUNICODErÅ   ÚVERBOSErÇ   rÌ   rÏ   rÍ   rÞ   rÐ   rÓ   rÑ   rÒ   r×   r  r<   Z	_all_tagsÚ
IGNORECASErà   rí   rï   r*   Úobjectr4   rx   r‡   rˆ   r  r  r­   r  r   r   r   r#   Ú<module>k   s’     VU


      \