U
    gZ$dC  ã                   @   s4   d dl Z ddlmZ ddlmZ G dd„ deƒZdS )é    Né   )Úlex)ÚTOKENc                   @   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„ ZdZdZi ZeD ]Zeee ¡ < q\eD ](Zeeedd…  ¡ edd…  ¡  < qree d ZdZdZdZdZdZdZde d e d Zd e Zee e Zee e Zd!Zd"Zd#Zd$Z d%Z!d&e d' e d' e  d( Z"d)Z#d*e" d Z$d+e$ d+ Z%d,e% Z&d-e% Z'd.e% Z(d/e% Z)d+e$ d0 Z*d1e$ d2 e$ d3 Z+d1e$ d4 e! d5 Z,d6e# d Z-d7e- d8 Z.d,e. Z/d-e. Z0d.e. Z1d/e. Z2d7e- d9 e! e- d8 Z3d:Z4d;Z5d<e5 d e4 d= e4 d> Z6d?Z7d@e dA e dB e dC Z8dDe dD e d' e8 d e7 dE Z9dFZ:dGdH„ Z;e<e.ƒdIdJ„ ƒZ=e<eƒdKdL„ ƒZ>dMdN„ Z?dOdP„ Z@dQZAdRdS„ ZBdTdU„ ZCdVdW„ ZDdQZEdXdY„ ZFdZd[„ ZGdQZHd\d]„ ZId^ZJd_ZKd`ZLdaZMdbZNdcZOddZPdeZQdfZRdgZSdhZTdiZUdjZVdkZWdlZXdmZYdnZZdoZ[dpZ\dqZ]drZ^dsZ_dtZ`duZadvZbdwZcdxZddyZedzZfd{Zgd|Zhd}Zid~ZjdZkd€ZldZmd‚ZndƒZod„Zpd…Zqd†Zrd‡ZsdˆZtd‰Zue<dŠƒd‹dŒ„ ƒZve<dƒdŽd„ ƒZwe.Zxe<e6ƒdd‘„ ƒZye<e9ƒd’d“„ ƒZze<eƒd”d•„ ƒZ{e<eƒd–d—„ ƒZ|e<eƒd˜d™„ ƒZ}e<eƒdšd›„ ƒZ~e<eƒdœd„ ƒZe<e*ƒdždŸ„ ƒZ€e<e%ƒd d¡„ ƒZe<e&ƒd¢d£„ ƒZ‚e<e'ƒd¤d¥„ ƒZƒe<e(ƒd¦d§„ ƒZ„e<e)ƒd¨d©„ ƒZ…e<e+ƒdªd«„ ƒZ†e<e,ƒd¬d­„ ƒZ‡e<e/ƒd®d¯„ ƒZˆe<e0ƒd°d±„ ƒZ‰e<e1ƒd²d³„ ƒZŠe<e2ƒd´dµ„ ƒZ‹e<e3ƒd¶d·„ ƒZŒe<eƒd¸d¹„ ƒZdºd»„ ZŽdS )¼ÚCLexera   A lexer for the C language. After building it, set the
        input text with input(), and call token() to get new
        tokens.

        The public attribute filename can be set to an initial
        filename, but the lexer will update it upon #line
        directives.
    c                 C   s@   || _ || _|| _|| _d| _d| _t d¡| _t d¡| _	dS )ab   Create a new Lexer.

            error_func:
                An error function. Will be called with an error
                message, line and column as arguments, in case of
                an error during lexing.

            on_lbrace_func, on_rbrace_func:
                Called when an LBRACE or RBRACE is encountered
                (likely to push/pop type_lookup_func's scope)

            type_lookup_func:
                A type lookup function. Given a string, it must
                return True IFF this string is a name of a type
                that was defined with a typedef earlier.
        Ú Nz([ \t]*line\W)|([ \t]*\d+)z[ \t]*pragma\W)
Ú
error_funcÚon_lbrace_funcÚon_rbrace_funcÚtype_lookup_funcÚfilenameÚ
last_tokenÚreÚcompileÚline_patternÚpragma_pattern)Úselfr   r   r	   r
   © r   ú5/tmp/pip-unpacked-wheel-tmpgil2w/pycparser/c_lexer.pyÚ__init__   s    zCLexer.__init__c                 K   s   t j f d| i|—Ž| _dS )zù Builds the lexer from the specification. Must be
            called after the lexer object is created.

            This method exists separately, because the PLY
            manual warns against calling lex.lex inside
            __init__
        ÚobjectN)r   Úlexer)r   Úkwargsr   r   r   Úbuild9   s    zCLexer.buildc                 C   s   d| j _dS )z? Resets the internal line number counter of the lexer.
        r   N)r   Úlineno©r   r   r   r   Úreset_linenoC   s    zCLexer.reset_linenoc                 C   s   | j  |¡ d S ©N)r   Úinput)r   Útextr   r   r   r   H   s    zCLexer.inputc                 C   s   | j  ¡ | _| jS r   )r   Útokenr   r   r   r   r   r   K   s    zCLexer.tokenc                 C   s   | j j dd|j¡}|j| S )z3 Find the column of the token in its line.
        Ú
r   )r   ÚlexdataÚrfindÚlexpos)r   r   Zlast_crr   r   r   Úfind_tok_columnO   s    zCLexer.find_tok_columnc                 C   s0   |   |¡}|  ||d |d ¡ | j d¡ d S )Nr   r   )Ú_make_tok_locationr   r   Úskip)r   Úmsgr   Úlocationr   r   r   Ú_errorZ   s    
zCLexer._errorc                 C   s   |j |  |¡fS r   )r   r$   )r   r   r   r   r   r%   _   s    zCLexer._make_tok_location)$ZAUTOZBREAKZCASEZCHARZCONSTÚCONTINUEÚDEFAULTZDOZDOUBLEÚELSEZENUMZEXTERNÚFLOATZFORZGOTOZIFZINLINEÚINTÚLONGZREGISTERZOFFSETOFZRESTRICTZRETURNZSHORTZSIGNEDZSIZEOFZSTATICZSTRUCTZSWITCHZTYPEDEFZUNIONZUNSIGNEDZVOIDZVOLATILEZWHILEZ__INT128)Z_BOOLZ_COMPLEXZ	_NORETURNZ_THREAD_LOCALZ_STATIC_ASSERTZ_ATOMICZ_ALIGNOFZ_ALIGNASNé   )DÚIDÚTYPEIDZINT_CONST_DECZINT_CONST_OCTZINT_CONST_HEXZINT_CONST_BINZINT_CONST_CHARZFLOAT_CONSTZHEX_FLOAT_CONSTZ
CHAR_CONSTZWCHAR_CONSTZU8CHAR_CONSTZU16CHAR_CONSTZU32CHAR_CONSTZSTRING_LITERALZWSTRING_LITERALZU8STRING_LITERALZU16STRING_LITERALZU32STRING_LITERALÚPLUSÚMINUSZTIMESZDIVIDEZMODÚORÚANDZNOTZXORZLSHIFTZRSHIFTZLORZLANDZLNOTÚLTZLEÚGTZGEZEQZNEZEQUALSZ
TIMESEQUALZDIVEQUALZMODEQUALÚ	PLUSEQUALZ
MINUSEQUALZLSHIFTEQUALZRSHIFTEQUALZANDEQUALZXOREQUALZOREQUALZPLUSPLUSZ
MINUSMINUSZARROWZCONDOPÚLPARENÚRPARENÚLBRACKETÚRBRACKETÚLBRACEÚRBRACEÚCOMMAZPERIODÚSEMIÚCOLONÚELLIPSISÚPPHASHZPPPRAGMAÚPPPRAGMASTRz[a-zA-Z_$][0-9a-zA-Z_$]*z0[xX]z[0-9a-fA-F]+z0[bB]z[01]+zD(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?z(0z)|([1-9][0-9]*ú)z0[0-7]*z0[0-7]*[89]z,([a-wyzA-Z._~!=&\^\-\\?'"]|x(?![0-9a-fA-F]))z(\d+)(?!\d)z(x[0-9a-fA-F]+)(?![0-9a-fA-F])z#([\\][^a-zA-Z._~^!=&\^\-\\?'"x0-9])z(\\(ú|z))z(\\[0-9a-zA-Z._~!=&\^\-\\?'"])z
([^'\\\n]|ú'ÚLÚu8ÚuÚUz{2,4}'z('z*\n)|('z*$)z[^'
]+')|('')|('z	[^'\n]*')z
([^"\\\n]|ú"z*"Ú*z([eE][-+]?[0-9]+)z([0-9]*\.[0-9]+)|([0-9]+\.)z((((z
?)|([0-9]+z
))[FfLl]?)z([pP][+-]?[0-9]+)z(((z)?\.z)|(z\.))ú(z[FfLl]?)))ÚpplineÚ	exclusive)ÚpppragmarQ   c                 C   sf   | j j|jj|jjdr2|j d¡ d | _| _n0| jj|jj|jjdrX|j d¡ n
d|_	|S dS )z[ \t]*\#)ÚposrP   NrR   rD   )
r   Úmatchr   r!   r#   ÚbeginÚpp_lineÚpp_filenamer   Útype©r   Útr   r   r   Út_PPHASH!  s    zCLexer.t_PPHASHc                 C   s0   | j d kr|  d|¡ n|j d¡ d¡| _d S )Nz$filename before line number in #linerM   )rV   r)   ÚvalueÚlstripÚrstriprW   rY   r   r   r   Út_ppline_FILENAME/  s    
zCLexer.t_ppline_FILENAMEc                 C   s   | j d kr|j| _ n d S r   )rV   r\   rY   r   r   r   Út_ppline_LINE_NUMBER6  s    

zCLexer.t_ppline_LINE_NUMBERc                 C   sH   | j dkr|  d|¡ n t| j ƒ| j_| jdk	r8| j| _|j d¡ dS )ú\nNzline number missing in #lineÚINITIAL)rV   r)   Úintr   r   rW   r   rU   rY   r   r   r   Út_ppline_NEWLINE?  s    

zCLexer.t_ppline_NEWLINEc                 C   s   dS )ÚlineNr   rY   r   r   r   Út_ppline_PPLINEK  s    zCLexer.t_ppline_PPLINEz 	c                 C   s   |   d|¡ d S )Nzinvalid #line directive©r)   rY   r   r   r   Út_ppline_errorQ  s    zCLexer.t_ppline_errorc                 C   s    |j  jd7  _|j  d¡ dS )ra   r   rb   N)r   r   rU   rY   r   r   r   Út_pppragma_NEWLINEW  s    zCLexer.t_pppragma_NEWLINEc                 C   s   |S )Zpragmar   rY   r   r   r   Út_pppragma_PPPRAGMA\  s    zCLexer.t_pppragma_PPPRAGMAc                 C   s
   d|_ |S )z.+rE   )rX   rY   r   r   r   Út_pppragma_STRb  s    zCLexer.t_pppragma_STRc                 C   s   |   d|¡ d S )Nzinvalid #pragma directiverg   rY   r   r   r   Út_pppragma_errorg  s    zCLexer.t_pppragma_errorc                 C   s   |j  j|j d¡7  _dS )z\n+r    N)r   r   r\   ÚcountrY   r   r   r   Ú	t_NEWLINEp  s    zCLexer.t_NEWLINEz\+ú-z\*ú/ú%z\|ú&ú~z\^z<<z>>z\|\|z&&ú!ú<ú>z<=z>=z==z!=ú=z\*=z/=z%=z\+=z-=z<<=z>>=z&=z\|=z\^=z\+\+z--z->z\?z\(z\)z\[z\]ú,z\.ú;ú:z\.\.\.z\{c                 C   s   |   ¡  |S r   )r   rY   r   r   r   Út_LBRACE¸  s    zCLexer.t_LBRACEz\}c                 C   s   |   ¡  |S r   )r	   rY   r   r   r   Út_RBRACE¼  s    zCLexer.t_RBRACEc                 C   s   |S r   r   rY   r   r   r   Út_FLOAT_CONSTÈ  s    zCLexer.t_FLOAT_CONSTc                 C   s   |S r   r   rY   r   r   r   Út_HEX_FLOAT_CONSTÌ  s    zCLexer.t_HEX_FLOAT_CONSTc                 C   s   |S r   r   rY   r   r   r   Út_INT_CONST_HEXÐ  s    zCLexer.t_INT_CONST_HEXc                 C   s   |S r   r   rY   r   r   r   Út_INT_CONST_BINÔ  s    zCLexer.t_INT_CONST_BINc                 C   s   d}|   ||¡ d S )NzInvalid octal constantrg   ©r   rZ   r'   r   r   r   Út_BAD_CONST_OCTØ  s    zCLexer.t_BAD_CONST_OCTc                 C   s   |S r   r   rY   r   r   r   Út_INT_CONST_OCTÝ  s    zCLexer.t_INT_CONST_OCTc                 C   s   |S r   r   rY   r   r   r   Út_INT_CONST_DECá  s    zCLexer.t_INT_CONST_DECc                 C   s   |S r   r   rY   r   r   r   Út_INT_CONST_CHARè  s    zCLexer.t_INT_CONST_CHARc                 C   s   |S r   r   rY   r   r   r   Út_CHAR_CONSTì  s    zCLexer.t_CHAR_CONSTc                 C   s   |S r   r   rY   r   r   r   Út_WCHAR_CONSTð  s    zCLexer.t_WCHAR_CONSTc                 C   s   |S r   r   rY   r   r   r   Út_U8CHAR_CONSTô  s    zCLexer.t_U8CHAR_CONSTc                 C   s   |S r   r   rY   r   r   r   Út_U16CHAR_CONSTø  s    zCLexer.t_U16CHAR_CONSTc                 C   s   |S r   r   rY   r   r   r   Út_U32CHAR_CONSTü  s    zCLexer.t_U32CHAR_CONSTc                 C   s   d}|   ||¡ d S )NzUnmatched 'rg   r   r   r   r   Út_UNMATCHED_QUOTE   s    zCLexer.t_UNMATCHED_QUOTEc                 C   s   d|j  }|  ||¡ d S )NzInvalid char constant %s)r\   r)   r   r   r   r   Út_BAD_CHAR_CONST  s    
zCLexer.t_BAD_CHAR_CONSTc                 C   s   |S r   r   rY   r   r   r   Út_WSTRING_LITERAL
  s    zCLexer.t_WSTRING_LITERALc                 C   s   |S r   r   rY   r   r   r   Út_U8STRING_LITERAL  s    zCLexer.t_U8STRING_LITERALc                 C   s   |S r   r   rY   r   r   r   Út_U16STRING_LITERAL  s    zCLexer.t_U16STRING_LITERALc                 C   s   |S r   r   rY   r   r   r   Út_U32STRING_LITERAL  s    zCLexer.t_U32STRING_LITERALc                 C   s   d}|   ||¡ d S )Nz#String contains invalid escape coderg   r   r   r   r   Út_BAD_STRING_LITERAL  s    zCLexer.t_BAD_STRING_LITERALc                 C   s2   | j  |jd¡|_|jdkr.|  |j¡r.d|_|S )Nr1   r2   )Úkeyword_mapÚgetr\   rX   r
   rY   r   r   r   Út_ID!  s    zCLexer.t_IDc                 C   s"   dt |jd ƒ }|  ||¡ d S )NzIllegal character %sr   )Úreprr\   r)   r   r   r   r   Út_error(  s    zCLexer.t_error)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r$   r)   r%   ÚkeywordsZkeywords_newr’   ÚkeywordÚlowerÚupperÚtokensÚ
identifierZ
hex_prefixZ
hex_digitsZ
bin_prefixZ
bin_digitsZinteger_suffix_optZdecimal_constantZoctal_constantZhex_constantZbin_constantZbad_octal_constantZsimple_escapeZdecimal_escapeZ
hex_escapeZ
bad_escapeZescape_sequenceZescape_sequence_start_in_stringZcconst_charZ
char_constZwchar_constZu8char_constZu16char_constZu32char_constZmulticharacter_constantZunmatched_quoteZbad_char_constZstring_charZstring_literalZwstring_literalZu8string_literalZu16string_literalZu32string_literalZbad_string_literalZexponent_partZfractional_constantZfloating_constantZbinary_exponent_partZhex_fractional_constantZhex_floating_constantZstatesr[   r   r_   r`   rd   rf   Zt_ppline_ignorerh   ri   rj   Zt_pppragma_ignorerk   rl   Zt_ignorern   Zt_PLUSZt_MINUSZt_TIMESZt_DIVIDEZt_MODZt_ORZt_ANDZt_NOTZt_XORZt_LSHIFTZt_RSHIFTZt_LORZt_LANDZt_LNOTZt_LTZt_GTZt_LEZt_GEZt_EQZt_NEZt_EQUALSZt_TIMESEQUALZ
t_DIVEQUALZ
t_MODEQUALZt_PLUSEQUALZt_MINUSEQUALZt_LSHIFTEQUALZt_RSHIFTEQUALZ
t_ANDEQUALZ	t_OREQUALZ
t_XOREQUALZ
t_PLUSPLUSZt_MINUSMINUSZt_ARROWZt_CONDOPZt_LPARENZt_RPARENZ
t_LBRACKETZ
t_RBRACKETZt_COMMAZt_PERIODZt_SEMIZt_COLONZ
t_ELLIPSISr{   r|   Zt_STRING_LITERALr}   r~   r   r€   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r   rŽ   r   r   r‘   r”   r–   r   r   r   r   r      sJ  !

&C$

























r   )r   Zplyr   Zply.lexr   r   r   r   r   r   r   Ú<module>	   s   