U §Ãq`P?ã@s<ddlZddlZddlmZddlmZGdd„deƒZdS)éNé)Úlex)ÚTOKENc@sReZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dZ iZ e D]4Zedkrnee d<qXedkr€ee d<qXee e ¡<qXe dZdZdZdZdZdZdZdeded Zd!eZeeeZeeeZd"Zd#Zd$Zd%Zd&Zd'ed(ed(ed)Z d*Z!d+e d Z"d,e"d,Z#d-e#Z$d,e"d.Z%d/e"d0e"d1Z&d/e"d2ed3Z'd4e!d Z(d5e(d6Z)d-e)Z*d5e(d7ee(d6Z+d8Z,d9Z-d:e-d e,d;e,d<Z.d=Z/d>ed?ed@edAZ0dBedBed(e0d e/dCZ1dDZ2dEdF„Z3e4e)ƒdGdH„ƒZ5e4eƒdIdJ„ƒZ6dKdL„Z7dMdN„Z8dOZ9dPdQ„Z:dRdS„Z;dTdU„ZdXdY„Z?dOZ@dZd[„ZAd\ZBd]ZCd^ZDd_ZEd`ZFdaZGdbZHdcZIddZJdeZKdfZLdgZMdhZNdiZOdjZPdkZQdlZRdmZSdnZTdoZUdpZVdqZWdrZXdsZYdtZZduZ[dvZ\dwZ]dxZ^dyZ_dzZ`d{Zad|Zbd}Zcd~ZddZed€ZfdZgd‚ZhdƒZid„Zjd…Zkd†Zld‡Zme4dˆƒd‰dŠ„ƒZne4d‹ƒdŒd„ƒZoe)Zpe4e.ƒdŽd„ƒZqe4e1ƒdd‘„ƒZre4eƒd’d“„ƒZse4eƒd”d•„ƒZte4eƒd–d—„ƒZue4eƒd˜d™„ƒZve4eƒdšd›„ƒZwe4e%ƒdœd„ƒZxe4e#ƒdždŸ„ƒZye4e$ƒd d¡„ƒZze4e&ƒd¢d£„ƒZ{e4e'ƒd¤d¥„ƒZ|e4e*ƒd¦d§„ƒZ}e4e+ƒd¨d©„ƒZ~e4eƒ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. cCs@||_||_||_||_d|_d|_t d¡|_t d¡|_ dS)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)Úselfrrr r ©rú8/tmp/pip-target-nv4zd3e_/lib/python/pycparser/c_lexer.pyÚ__init__s zCLexer.__init__cKstjfd|i|—Ž|_dS)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ÚkwargsrrrÚbuild:sz CLexer.buildcCs d|j_dS)z? Resets the internal line number counter of the lexer. rN)rÚlineno©rrrrÚ reset_linenoDszCLexer.reset_linenocCs|j |¡dS©N)rÚinput)rÚtextrrrrIsz CLexer.inputcCs|j ¡|_|jSr)rÚtokenr rrrrrLs z CLexer.tokencCs|jj dd|j¡}|j|S)z3 Find the column of the token in its line. Ú r)rÚlexdataÚrfindÚlexpos)rrZlast_crrrrÚfind_tok_columnPszCLexer.find_tok_columncCs0| |¡}| ||d|d¡|j d¡dS)Nrr)Ú_make_tok_locationrrÚskip)rÚmsgrÚlocationrrrÚ_error[s z CLexer._errorcCs|j| |¡fSr)rr$)rrrrrr%`szCLexer._make_tok_location)&Ú_BOOLÚ_COMPLEXZAUTOZBREAKZCASEZCHARZCONSTÚCONTINUEÚDEFAULTZDOZDOUBLEÚELSEZENUMZEXTERNÚFLOATZFORZGOTOZIFZINLINEÚINTÚLONGZREGISTERZOFFSETOFZRESTRICTZRETURNZSHORTZSIGNEDZSIZEOFZSTATICZSTRUCTZSWITCHZTYPEDEFZUNIONZUNSIGNEDZVOIDZVOLATILEZWHILEZ__INT128r*Z_Boolr+Z_Complex)>ÚIDÚTYPEIDZ INT_CONST_DECZ INT_CONST_OCTZ INT_CONST_HEXZ INT_CONST_BINZINT_CONST_CHARZ FLOAT_CONSTZHEX_FLOAT_CONSTZ CHAR_CONSTZ WCHAR_CONSTZSTRING_LITERALZWSTRING_LITERALÚPLUSÚMINUSZTIMESZDIVIDEZMODÚORÚANDZNOTZXORZLSHIFTZRSHIFTZLORZLANDZLNOTÚLTZLEÚGTZGEZEQZNEZEQUALSZ TIMESEQUALZDIVEQUALZMODEQUALÚ PLUSEQUALZ MINUSEQUALZ LSHIFTEQUALZ RSHIFTEQUALZANDEQUALZXOREQUALZOREQUALZPLUSPLUSZ MINUSMINUSZARROWZCONDOPÚLPARENÚRPARENÚLBRACKETÚRBRACKETÚLBRACEÚRBRACEÚCOMMAZPERIODÚSEMIÚCOLONÚELLIPSISÚPPHASHZPPPRAGMAÚ PPPRAGMASTRz[a-zA-Z_$][0-9a-zA-Z_$]*z0[xX]z [0-9a-fA-F]+z0[bB]z[01]+zD(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?z(0z)|([1-9][0-9]*ú)z0[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]|ú'ÚLz{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)ÚpppragmarOcCsf|jj|jj|jjdr2|j d¡d|_|_n0|jj|jj|jjdrX|j d¡n d|_ |SdS)z[ \t]*\#)ÚposrNNrPrE) rÚmatchrr!r#ÚbeginÚpp_lineÚ pp_filenamerÚtype©rÚtrrrÚt_PPHASHs zCLexer.t_PPHASHcCs0|jdkr| d|¡n|j d¡ d¡|_dS)Nz$filename before line number in #linerK)rTr)ÚvalueÚlstripÚrstriprUrWrrrÚt_ppline_FILENAMEs zCLexer.t_ppline_FILENAMEcCs|jdkr|j|_ndSr)rTrZrWrrrÚt_ppline_LINE_NUMBER&s  zCLexer.t_ppline_LINE_NUMBERcCsH|jdkr| d|¡n t|jƒ|j_|jdk r8|j|_|j d¡dS)ú\nNzline number missing in #lineÚINITIAL)rTr)ÚintrrrUr rSrWrrrÚt_ppline_NEWLINE/s   zCLexer.t_ppline_NEWLINEcCsdS)ÚlineNrrWrrrÚt_ppline_PPLINE;szCLexer.t_ppline_PPLINEz cCs| d|¡dS)Nzinvalid #line directive©r)rWrrrÚt_ppline_errorAszCLexer.t_ppline_errorcCs |jjd7_|j d¡dS)r_rr`N)rrrSrWrrrÚt_pppragma_NEWLINEGszCLexer.t_pppragma_NEWLINEcCs|S)ZpragmarrWrrrÚt_pppragma_PPPRAGMALszCLexer.t_pppragma_PPPRAGMAcCs d|_|S)z.+rF)rVrWrrrÚt_pppragma_STRRszCLexer.t_pppragma_STRcCs| d|¡dS)Nzinvalid #pragma directivererWrrrÚt_pppragma_errorWszCLexer.t_pppragma_errorcCs|jj|j d¡7_dS)z\n+r N)rrrZÚcountrWrrrÚ t_NEWLINE`szCLexer.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\{cCs | ¡|Sr)rrWrrrÚt_LBRACE¨szCLexer.t_LBRACEz\}cCs | ¡|Sr)r rWrrrÚt_RBRACE¬szCLexer.t_RBRACEcCs|SrrrWrrrÚ t_FLOAT_CONST¸szCLexer.t_FLOAT_CONSTcCs|SrrrWrrrÚt_HEX_FLOAT_CONST¼szCLexer.t_HEX_FLOAT_CONSTcCs|SrrrWrrrÚt_INT_CONST_HEXÀszCLexer.t_INT_CONST_HEXcCs|SrrrWrrrÚt_INT_CONST_BINÄszCLexer.t_INT_CONST_BINcCsd}| ||¡dS)NzInvalid octal constantre©rrXr'rrrÚt_BAD_CONST_OCTÈszCLexer.t_BAD_CONST_OCTcCs|SrrrWrrrÚt_INT_CONST_OCTÍszCLexer.t_INT_CONST_OCTcCs|SrrrWrrrÚt_INT_CONST_DECÑszCLexer.t_INT_CONST_DECcCs|SrrrWrrrÚt_INT_CONST_CHARØszCLexer.t_INT_CONST_CHARcCs|SrrrWrrrÚ t_CHAR_CONSTÜszCLexer.t_CHAR_CONSTcCs|SrrrWrrrÚ t_WCHAR_CONSTàszCLexer.t_WCHAR_CONSTcCsd}| ||¡dS)Nz Unmatched 'rerrrrÚt_UNMATCHED_QUOTEäszCLexer.t_UNMATCHED_QUOTEcCsd|j}| ||¡dS)NzInvalid char constant %s)rZr)rrrrÚt_BAD_CHAR_CONSTés zCLexer.t_BAD_CHAR_CONSTcCs|SrrrWrrrÚt_WSTRING_LITERALîszCLexer.t_WSTRING_LITERALcCsd}| ||¡dS)Nz#String contains invalid escape codererrrrÚt_BAD_STRING_LITERALôszCLexer.t_BAD_STRING_LITERALcCs2|j |jd¡|_|jdkr.| |j¡r.d|_|S)Nr2r3)Ú keyword_mapÚgetrZrVr rWrrrÚt_IDùsz CLexer.t_IDcCs"dt|jdƒ}| ||¡dS)NzIllegal character %sr)ÚreprrZr)rrrrÚt_errorszCLexer.t_errorN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrr$r)r%ÚkeywordsrŠÚkeywordÚlowerÚtokensÚ identifierZ hex_prefixZ hex_digitsZ bin_prefixZ bin_digitsZinteger_suffix_optZdecimal_constantZoctal_constantZ hex_constantZ bin_constantZbad_octal_constantZ simple_escapeZdecimal_escapeZ hex_escapeZ bad_escapeZescape_sequenceZescape_sequence_start_in_stringZ cconst_charZ char_constZ wchar_constZmulticharacter_constantZunmatched_quoteZbad_char_constZ string_charZstring_literalZwstring_literalZbad_string_literalZ exponent_partZfractional_constantZfloating_constantZbinary_exponent_partZhex_fractional_constantZhex_floating_constantZstatesrYrr]r^rbrdZt_ppline_ignorerfrgrhZt_pppragma_ignorerirjZt_ignorerlZt_PLUSZt_MINUSZt_TIMESZt_DIVIDEZt_MODZt_ORZt_ANDZt_NOTZt_XORZt_LSHIFTZt_RSHIFTZt_LORZt_LANDZt_LNOTZt_LTZt_GTZt_LEZt_GEZt_EQZt_NEZt_EQUALSZ t_TIMESEQUALZ t_DIVEQUALZ t_MODEQUALZ t_PLUSEQUALZ t_MINUSEQUALZ t_LSHIFTEQUALZ t_RSHIFTEQUALZ t_ANDEQUALZ t_OREQUALZ t_XOREQUALZ t_PLUSPLUSZ t_MINUSMINUSZt_ARROWZt_CONDOPZt_LPARENZt_RPARENZ t_LBRACKETZ t_RBRACKETZt_COMMAZt_PERIODZt_SEMIZt_COLONZ t_ELLIPSISryrzZt_STRING_LITERALr{r|r}r~r€rr‚rƒr„r…r†r‡rˆr‰rŒrŽrrrrrs(!     =       $                     r)r ÚsysZplyrZply.lexrrrrrrrÚ s