
    daf6                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ  ej:                  e      j?                         j@                  Z!ee	e"e#f   e	e#e"f   ee#   f   Z$d
e#de#de
e#   fdZ%d Z&	 	 	 	 	 d'de#dee#   de'de'de'dee#   de#fdZ(	 d(de#de'de'deeeef   fdZ)dee#   de$fdZ*	 	 	 	 d)dede#de#de#de'd e'd!e'd"e'defd#Z+	 d*dede#de#d"e'def
d$Z,	 	 	 	 	 	 d+de#de#de#de'de'de'd e'd!e'd"e'deeeeef   fd%Z-	 	 	 d,de#de#de'de'd"e'deeeeef   fd&Z.y)-    N)IODictListOptionalSetTuple)CParserGenerator)Grammar)GeneratedParser)Parser)ParserGenerator)PythonParserGenerator)	Tokenizercompiler_flagscompiler_py_flags_nodistreturnc                     t        j                  |       }t        j                  |      }||g S | d| j                         S )N )	sysconfigget_config_varsplit)r   r   flagspy_flags_nodists       6/root/Python-3.12.4/Tools/peg_generator/pegen/build.pyget_extra_flagsr      sM    $$^4E../GHO}/	WAo&'--//    c                    t         j                  dk(  r%t        j                  j	                  d      | _        yt        j                  d      rt        j                  d      }|	dg| _        yt        j                  dk(  rg | _        y|j                  d      \  }}}|j                  t         j                        D cg c]  }|s|	 c}| _        yyc c}w )	a  Function needed to make build_ext tests pass.

    When Python was built with --enable-shared on Unix, -L. is not enough to
    find libpython<blah>.so, because regrtest runs in a tempdir, not in the
    source directory where the .so lives.

    When Python was built with in debug mode on Windows, build_ext commands
    need their debug attribute set, and it is not done automatically for
    some reason.

    This function handles both of these things.  Example use:

        cmd = build_ext(dist)
        support.fixup_build_ext(cmd)
        cmd.ensure_finalized()

    Unlike most other Unix platforms, Mac OS X embeds absolute paths
    to shared libraries into executables, so the fixup is not needed there.

    Taken from distutils (was part of the CPython stdlib until Python 3.11)
    ntz_d.exePy_ENABLE_SHARED	RUNSHAREDN.darwin=)osnamesys
executableendswithdebugr   r   library_dirsplatform	partitionr   pathsep)cmd	runsharedr%   equalsvalueds         r   fixup_build_extr3      s    , 
ww$NN++H5			!	!"4	5 ,,[9	 #uC||x'#% &/&9&9#&>#fe/4{{2::/F#L!!A#L  
6 $Ms   ?CCgenerated_source_path	build_dirverbosekeep_assertsdisable_optimizationlibrary_dirc                    ddl }ddlm}m} ddlm}	 ddlm}
 ddlm	} |r9|j                  j                  |j                  j                  j                         t        j                  |       }|j                  }t!        dd      }|j#                  d	       |j#                  d
       t!        dd      }|r|j#                  d       |rpt$        j&                  dk(  r#|j#                  d       |j#                  d       n:|j#                  d       t)        j*                  d      dk(  r|j#                  d       t-        t.        j0                  j0                  j0                  dz  dz        t-        t.        j0                  j0                  j0                  dz  dz        t-        t.        j0                  j0                  j0                  dz  dz        t-        t.        j0                  j0                  j0                  dz  dz        t-        t.        j0                  j0                  j0                  dz  dz        t-        t.        j0                  j0                  j0                  dz  dz        t-        t.        j0                  j0                  j0                  dz  dz        t-        t.        j0                  dz  dz        g}t-        t.        j0                  j0                  j0                  d z  d!z        t-        t.        j0                  j0                  j0                  dz        g} ||| g||"      } |||gd#      }|j3                  d$      }t5        |       t-        |j0                        |_        ||_        |r||_        |j=                           |
       } ||       |j?                  |j8                         |jA                  |jB                         |r|jE                  ||%      } |	||d&      rt$        j&                  dk(  r,|jF                  |d'fz  }d(| d)| g}|jI                  |       n|}|jK                  |||jL                  |*      }|jO                  ||||jL                  +       t$        j&                  dk(  r|jQ                  |       |g|_)        nKt$        j&                  d,k(  r|jU                  d-|g       n$|jU                  d.|d/g       n||jV                  dd |jY                  |      } |	|jV                  |d&      r4|jK                  |jV                  |j:                  |jL                  |*      }n'|j[                  |jV                  |j:                  %      }|j]                  |||j_                  |      ||ja                  |      |jL                  |j:                  0       t        j                  |      S )1a  Compile the generated source for a parser generator into an extension module.

    The extension module will be generated in the same directory as the provided path
    for the generated source, with the same basename (in addition to extension module
    metadata). For example, for the source mydir/parser.c the generated extension
    in a darwin system with python 3.8 will be mydir/parser.cpython-38-darwin.so.

    If *build_dir* is provided, that path will be used as the temporary build directory
    of distutils (this is useful in case you want to use a temporary directory).

    If *library_dir* is provided, that path will be used as the directory for a
    static library of the common parser sources (this is useful in case you are
    creating multiple extensions).
    r   N)	ExtensionDistribution)newer_group)new_compiler)customize_compilerCFLAGSPY_CFLAGS_NODISTz-DPy_BUILD_CORE_MODULEz-D_Py_TEST_PEGENLDFLAGSPY_LDFLAGS_NODISTz-UNDEBUGwin32z/Odz	/LTCG:OFFz-O0GNULDyesz-fno-ltoPythonzPython-ast.czasdl.cr   ztokenizer.czpegen.czpegen_errors.czaction_helpers.czstring_parser.cpeg_extensionzpeg_extension.cIncludeinternal)sourcesextra_compile_argsextra_link_args)r%   ext_modules	build_ext)
output_dirnewerz.pdbz/Fd\)rP   r)   extra_postargs)rP   r)   r"   z-Wl,-force_loadz-Wl,--whole-archivez-Wl,--no-whole-archive)	librariesrS   export_symbolsr)   
build_temp)1setuptools.logging
setuptoolsr;   r<   setuptools._distutils.dep_utilr=   setuptools._distutils.ccompilerr>   setuptools._distutils.sysconfigr?   loggingset_thresholdDEBUGpathlibPathstemr   appendr&   r+   r   r   strMOD_DIRparentget_command_objr3   	build_libinclude_dirsrV   ensure_finalizedset_include_dirsset_library_dirsr*   library_filenamestatic_lib_formatextendcompiler)   create_static_libadd_library_dirrT   set_link_objectsrK   get_ext_fullpathobject_filenameslink_shared_objectget_librariesget_export_symbols)r4   r5   r6   r7   r8   r9   rX   r;   r<   r=   r>   r?   source_file_pathextension_namerL   rM   common_sourcesrh   	extensiondistr.   compilerrl   pdbcompile_optsobjectsext_paths                              r   compile_c_extensionr   G   s   , 2:<B((););)C)C)I)IJ||$9:%**N(3EF6701%i1DEO!!*-<<7"%%e,"";/%%e,''0E9&&z2 	GNN!!((83nDEGNN!!((83h>?GNN!!((83mCDGNN!!((83i?@GNN!!((836FFGGNN!!((836HHIGNN!!((836GGHGNN_,/@@A	N 	GNN!!((94zABGNN!!((834L &'-'	I LMD


{
+CC(//0CM#C"~Hx c../c../#44^@K 5 M~'7A||w&00NF3KK"%k]"SE :;##$671&&~2=-0YY6B ' DG &&w2=-0YY ' 8 <<7"$$[1#1"2I\\X%%%!#3'  %%%'79Q'  "0	!A ##N3H9$$h8""9#4#4/2~~*-))3E # G
 ++I,=,=7:~~ , G ##I.&--i8ii>>   # <<!!r   grammar_fileverbose_tokenizerverbose_parserc                    t        |       5 }t        t        j                  |j                        |      }t        ||      }|j                         }|s|j                  |       	 d d d        fS # 1 sw Y   xY w)N)r6   )openr   tokenizegenerate_tokensreadlineGrammarParserstartmake_syntax_error)r   r   r   file	tokenizerparsergrammars          r   build_parserr      s~     
l	 9th66t}}EO`a	y.A,,.**<88 9 FI%%9 9s   AA55A>tokensc                    i }i }t               }t        j                  d      }| D ]  }|j                         }|r|j	                  d      r'|j                         }t        |      }t        |      dk(  r|\  }|j                  |       |||<   kt        |      dk(  r|\  }}	|||	j                  d      <   |||<   t        d|        |||fS )Nr   #      'z&Unexpected line found in Tokens file: )
set	itertoolscountstrip
startswithr   nextlenadd
ValueError)
r   
all_tokensexact_tokensnon_exact_tokensnumberslinepiecesindextokenops
             r   generate_token_definitionsr      s    JLuooa G Nzz|ts+Wv;!HU  ' %Ju[AIE2*/L#' %JuEdVLMM%N( |%555r   r   tokens_fileoutput_filecompile_extensionverbose_c_extensionkeep_asserts_in_extensionskip_actionsc           	      f   t        |d      5 }t        |      \  }	}
}d d d        t        |d      5 }t        | 	
||      }|j                  |       d d d        |r.t	        j
                         5 }t        ||||       d d d        S S # 1 sw Y   rxY w# 1 sw Y   GxY w# 1 sw Y   S xY w)Nrwr   )r5   r6   r7   )r   r   r	   generatetempfileTemporaryDirectoryr   )r   r   r   r   r   r   r   r   tok_filer   	exact_toknon_exact_tokr   genr5   s                  r   build_c_generatorr      s     
k3	 T8/I(/S,
I}T	k3	 #4/ZM4l 
 	\"	# ((* 	i#+6		 J3J!T T# #	 Js"   B#B2B&BB#&B0c                     t        |d      5 }t        | |      }|j                  |       d d d        |S # 1 sw Y   S xY w)Nr   )r   r   r   )r   r   r   r   r   r   s         r   build_python_generatorr     sF     
k3	 #44WdC\"# J# Js   5?c	           
      V    t        | ||      \  }	}
}t        |	| ||||||      }|	|
||fS )a   Generate rules, C parser, tokenizer, parser generator for a given grammar

    Args:
        grammar_file (string): Path for the grammar file
        tokens_file (string): Path for the tokens file
        output_file (string): Path for the output file
        compile_extension (bool, optional): Whether to compile the C extension.
          Defaults to False.
        verbose_tokenizer (bool, optional): Whether to display additional output
          when generating the tokenizer. Defaults to False.
        verbose_parser (bool, optional): Whether to display additional output
          when generating the parser. Defaults to False.
        verbose_c_extension (bool, optional): Whether to display additional
          output when compiling the C extension . Defaults to False.
        keep_asserts_in_extension (bool, optional): Whether to keep the assert statements
          when compiling the extension module. Defaults to True.
        skip_actions (bool, optional): Whether to pretend no rule has any actions.
    r   )r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   s                r   build_c_parser_and_generatorr   $  sM    : ".l<M~!^GVY
!!	C FIs**r   c                 N    t        | ||      \  }}}t        || ||      }||||fS )a5  Generate rules, python parser, tokenizer, parser generator for a given grammar

    Args:
        grammar_file (string): Path for the grammar file
        output_file (string): Path for the output file
        verbose_tokenizer (bool, optional): Whether to display additional output
          when generating the tokenizer. Defaults to False.
        verbose_parser (bool, optional): Whether to display additional output
          when generating the parser. Defaults to False.
        skip_actions (bool, optional): Whether to pretend no rule has any actions.
    r   )r   r   )	r   r   r   r   r   r   r   r   r   s	            r   !build_python_parser_and_generatorr   P  sA    $ ".l<M~!^GVY
 !	C FIs**r   )NFTFN)FF)FFTF)F)FFFFTF)FFF)/r   r$   r_   r&   r   r   r   typingr   r   r   r   r   r   pegen.c_generatorr	   pegen.grammarr
   pegen.grammar_parserr   r   pegen.parserr   pegen.parser_generatorr   pegen.python_generatorr   pegen.tokenizerr   r`   __file__resolvere   rd   intrc   TokenDefinitionsr   r3   boolr   r   r   r   r   r   r    r   r   <module>r      s    	  
    7 7 . ! A  2 8 %
',,x
 
(
(
*
1
1c3hc3hSAB 0C 03 04PS9 0$MT  $!&!%F"F"}F" F" 	F"
 F" #F" 	F"T PU&&*.&HL&
7FI%&&6r#w 63C 6D $ %&*  	
    $  B 				 	 		
 	  $#  %&*)+)+)+ )+ 	)+
 )+ )+ )+  $)+ )+ 7FI67)+^ $ +++ + 	+
 + 7FI67+r   