3
ãde  ã               @   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   úJ/var/www/agendate/envp3/lib/python3.6/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:%s)r   r   r   )r   Ústrr   r   r	   Ú__str__   s     zCoord.__str__)r   r   r   r   )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      s    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 )N)r   r   r   )r   ZclexÚfilename)r   Úlinenor   r   r   r	   Ú_coord1   s    zPLYParser._coordc             C   sF   |j j jjdd|j|ƒƒ}|dk r&d}|j|ƒ| }| j|j|ƒ|ƒ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   r   éÿÿÿÿ)ÚlexerZlexdataÚrfindZlexposr   r   )r   r   Z	token_idxZ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 )N)Ú_params)Z	rule_func)Úparamsr   r	   ÚdecorateP   s    zparameterized.<locals>.decorater   )r&   r'   r   )r&   r	   ÚparameterizedF   s    
r(   c             C   sp   d}xft | ƒD ]Z}|jdƒrt| |ƒ}t|dƒrt| |ƒ |jdk	rPt| |ƒ q|stjdt	dd� d}qW | 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    




r7   c                sZ   xTˆ j D ]J\}}‡ fdd„}ˆ jjd|ƒjd|ƒ|_ˆ jjd|ƒ|_t| |j|ƒ qW 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 )Nr   )r   r   )Úfuncr   r	   Ú
param_rule}   s    z'_create_param_rules.<locals>.param_ruleÚxxxÚyyyN)r%   r   Úreplacer   r   )r4   r8   r:   r;   r9   r   )r8   r	   r0   t   s
    r0   )	r1   Úobjectr   Ú	Exceptionr   r   r(   r7   r0   r   r   r   r	   Ú<module>   s   $