a
    còf  ã                   @   sT   d dl Z G dd„ deƒZG dd„ deƒZG dd„ deƒZdd	„ Zd
d„ Zdd„ ZdS )é    Nc                   @   s&   e Zd ZdZdZddd„Zdd„ ZdS )	ÚCoordzž Coordinates of a syntactic element. Consists of:
            - File name
            - Line number
            - (optional) column number, for the Lexer
    )ÚfileÚlineÚcolumnÚ__weakref__Nc                 C   s   || _ || _|| _d S ©N©r   r   r   )Úselfr   r   r   © r
   úP/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pycparser/plyparser.pyÚ__init__   s    zCoord.__init__c                 C   s(   d| j | jf }| jr$|d| j 7 }|S )Nz%s:%sz:%sr   )r	   Ústrr
   r
   r   Ú__str__   s    zCoord.__str__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r
   r
   r
   r   r      s   
r   c                   @   s   e Zd ZdS )Ú
ParseErrorN)r   r   r   r
   r
   r
   r   r      ó    r   c                   @   s.   e Zd Zdd„ Zd
dd„Zdd„ Zdd	„ ZdS )Ú	PLYParserc                 C   s<   |d }dd„ }d||f |_ d| |_t| j|j|ƒ dS )zŽ Given a rule name, creates an optional ply.yacc rule
            for it. The name of the optional rule is
            <rulename>_opt
        Z_optc                 S   s   |d |d< d S )Né   r   r
   ©r	   Úpr
   r
   r   Úoptrule*   s    z+PLYParser._create_opt_rule.<locals>.optrulez%s : empty
| %szp_%sN)r   r   ÚsetattrÚ	__class__)r	   ZrulenameÚoptnamer   r
   r
   r   Ú_create_opt_rule#   s
    
zPLYParser._create_opt_ruleNc                 C   s   t | jj||d�S )Nr   )r   ZclexÚfilename)r	   Úlinenor   r
   r
   r   Ú_coord1   s
    ýzPLYParser._coordc                 C   sF   |j j j dd| |¡¡}|dk r&d}| |¡| }|  | |¡|¡S )z× Returns the coordinates for the YaccProduction object 'p' indexed
            with 'token_idx'. The coordinate includes the 'lineno' and
            'column'. Both follow the lex semantic, starting from 1.
        Ú
r   éÿÿÿÿ)ÚlexerZlexdataÚrfindZlexposr!   r    )r	   r   Z	token_idxÚlast_crr   r
   r
   r   Ú_token_coord7   s
    zPLYParser._token_coordc                 C   s   t d||f ƒ‚d S )Nz%s: %s)r   )r	   ÚmsgZcoordr
   r
   r   Ú_parse_errorB   s    zPLYParser._parse_error)N)r   r   r   r   r!   r'   r)   r
   r
   r
   r   r   "   s   
r   c                     s   ‡ fdd„}|S )aÞ   Decorator to create parameterized rules.

    Parameterized rule methods must be named starting with 'p_' and contain
    'xxx', and their docstrings may contain 'xxx' and 'yyy'. These will be
    replaced by the given parameter tuples. For example, ``p_xxx_rule()`` with
    docstring 'xxx_rule  : yyy' when decorated with
    ``@parameterized(('id', 'ID'))`` produces ``p_id_rule()`` with the docstring
    'id_rule  : ID'. Using multiple tuples produces multiple rules.
    c                    s
   ˆ | _ | S r   )Ú_params)Z	rule_func©Úparamsr
   r   ÚdecorateP   s    zparameterized.<locals>.decorater
   )r,   r-   r
   r+   r   ÚparameterizedF   s    
r.   c                 C   sl   d}t | ƒD ]Z}| d¡rt| |ƒ}t|dƒrt| |ƒ |jdurNt| |ƒ q|stjdt	dd� d}q| S )	z� Class decorator to generate rules from parameterized rule templates.

    See `parameterized` for more information on parameterized rules.
    FZp_r*   Nz@parsing methods must have __doc__ for pycparser to work properlyé   )Ú
stacklevelT)
ÚdirÚ
startswithÚgetattrÚhasattrÚdelattrr   Ú_create_param_rulesÚwarningsÚwarnÚRuntimeWarning)ÚclsZissued_nodoc_warningÚ	attr_nameÚmethodr
   r
   r   ÚtemplateV   s     




ýr=   c                    sV   ˆ j D ]J\}}‡ fdd„}ˆ j d|¡ d|¡|_ˆ j d|¡|_t| |j|ƒ qdS )a   Create ply.yacc rules based on a parameterized rule function

    Generates new methods (one per each pair of parameters) based on the
    template rule function `func`, and attaches them to `cls`. The rule
    function's parameters must be accessible via its `_params` attribute.
    c                    s   ˆ | |ƒ d S r   r
   r   ©Úfuncr
   r   Ú
param_rule}   s    z'_create_param_rules.<locals>.param_ruleÚxxxÚyyyN)r*   r   Úreplacer   r   )r:   r?   rA   rB   r@   r
   r>   r   r6   t   s
    r6   )	r7   Úobjectr   Ú	Exceptionr   r   r.   r=   r6   r
   r
   r
   r   Ú<module>   s   $