
    #hS#                    p   S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SrS r0 r    S SS jjr     S SS jjr   S SS jjr    S SS jjr     S SS jjr!SSSS\S4 SS jjr"S r#S r$S r%\&S:X  a  \%" 5         gg) zV
Parse and translate an EBNF grammar into a Python parser for
the described language.
    )annotationsN)Path   )__version__)ParseException)ParserConfig)codegen)objectmodel)GrammarGenerator)ModelBuilderSemantics)eval_escapeszlTatSu takes a grammar in a variation of EBNF as input, and outputs a memoizing PEG/Packrat parser in Python.c            	        [         R                  " S[        SS9n U R                  5       nUR	                  SSSS9  UR	                  SS	S
SS9  UR	                  SSSSS9  UR	                  SSSSS9  UR	                  SSSS9  U R                  S5      nU R	                  SSSS9  UR	                  SSSSS9  UR	                  SSSSS9  U R                  S5      nUR	                  SS S!S"S#S$S%9  UR	                  S&S'S(S)S9  UR	                  S*S+S,S-S#S S%9  UR	                  S.S/S0S1S2S9  UR	                  S3S4S1S5S9  UR	                  S6S7S8S9S9  S: nUR	                  S;S<S=US>9  U R                  S?5      nUR	                  S@SASBSCS9  UR	                  SDSESFSG[        SH9  U R                  5       nUR                  (       a"  UR                  (       d  U R                  SI5        U$ )JNtatsuF)progdescriptionadd_helpz--generate-parserz/generate parser code from the grammar (default)
store_true)helpactionz--drawz-dz6generate a diagram of the grammar (requires --outfile)z--object-modelz-gzBgenerate object model from the class names given as rule argumentsz--prettyz-pz2generate a prettified version of the input grammarz--pretty-leanz;like --pretty, but without name: or ::Parameter annotationszparse-time optionsfilenameGRAMMARz*the filename of the TatSu grammar to parse)metavarr   z--colorz-cz3use color in traces (requires the colorama library)z--tracez-tzproduce verbose parsing outputzgeneration optionsz--no-left-recursionz-lz turns left-recursion support offleft_recursionstore_falseT)r   destr   defaultz--namez-mNAMEz4Name for the grammar (defaults to GRAMMAR base name)z--no-nameguardz-nz(allow tokens that are prefixes of others	nameguardz	--outfilez--outputz-oFILEzoutput file (default is stdout)z--object-model-outfilez-Gz&generate object model and save to FILEz--whitespacez-w
CHARACTERSz5characters to skip during parsing (use "" to disable)c                     U R                  SS5      n[        R                  " US   5      n[        X!S   5      $ ! [         a  n[
        R                  " SU  35      UeS nAff = f)N.r   r   zCouldn't find class )rsplit	importlibimport_modulegetattr	ExceptionargparseArgumentTypeError)pathspathmodulees       J/Users/user/Downloads/htwk/venv/lib/python3.13/site-packages/tatsu/tool.pyimport_class parse_args.<locals>.import_class   sj    	KKQ'E,,U1X6F68,, 	,,&tf-	s   8; 
A$AA$z--base-type	CLASSPATHzMclass to use as base type for the object model, for example "mymodule.MyNode")r   r   typezcommon optionsz--helpz-hzshow this help message and exitr   z	--versionz-Vz$provide version information and exitversion)r   r   r3   z--draw requires --outfile)r(   ArgumentParserDESCRIPTIONadd_mutually_exclusive_groupadd_argumentadd_argument_groupr   
parse_argsdrawoutfileerror)	argparser	main_mode	ebnf_optsgeneration_optsr/   std_argsargss          r.   r9   r9      s   ''+I 668I>  
 E	   Q	   A	   J   ,,-ABI9  
 B	   -	    223GHO  / !    C	 !    7 !    . !     5	 !    D	 ! 	   \	 !  ++,<=H$>v   3   !Dyy34K    Fc                    [         nX[        U5      4nXv;   a  Xg   nO'[        U4SU0UD6n	U	R                  " U 4SU0UD6=oU'   Ub  X(l        U$ U(       a  [        5       Ul        U$ )Nconfig)__compiled_grammar_cacheidr   parse	semanticsr   )
grammarnamerI   asmodelrE   settingscachekeymodelgens
             r.   compilerR      s|     %E"Y-
(C
|
t?F?h? YYwJvJJJc
# L 
/1LrC   c                P    [        U 4UUUUS.UD6nUR                  " U4X$US.UD6$ )N)rK   rI   rL   rE   )startrI   rE   )rR   rH   )	rJ   inputrT   rK   rI   rL   rE   rM   rP   s	            r.   rH   rH      sT      E ;;BJ rC   c                6    [        U 4XUS.UD6n[        U5      $ )NrK   r   rE   )rR   
ngpythoncg)rJ   rK   r   rE   rM   rP   s         r.   to_python_sourcecoderY      s0     f@HE erC   c                H    [        U 4XUS.UD6n[        R                  " XcS9$ )NrW   	base_type)rR   ngobjectmodelmodelgen)rJ   rK   r   r\   rE   rM   rP   s          r.   to_python_modelr_      s6     f@HE !!%==rC   c                <    Uc  [        S5      e[        U4XUS.UD6$ )Nzgrammar is None)rK   rI   rE   )r   rR   )rK   rJ   rI   rE   rM   s        r.   genmodelra      s7     .//BJ rC   c                4    [        U4U UUUS.UD6nU" U5      $ )N)rK   r   tracerE   )rR   )rK   rJ   rc   r   r	   rE   rM   rP   s           r.   gencoderd     s8      E 5>rC   c                    U (       ac  [        U 5      n U R                  5       (       a  U R                  5         U R                  nUR	                  5       (       a  UR                  SSS9  g g g )NT)parentsexist_ok)r   is_fileunlinkparentexistsmkdir)r   dirnames     r.   prepare_for_outputrn     sW    >OO//>>MM$M6  rC   c                    [         R                  " U SSS9 nUR                  U5        S S S 5        g ! , (       d  f       g = f)Nwutf-8encoding)codecsopenwrite)r   contentfs      r.   savery   !  s,    	XsW	5	 
6	5	5s	   2
A c                    [        5       n U R                  (       a  [        U R                  5      U l        U R                  n[	        U5        [	        U R
                  5        [        R                  " U R                  SS9R                  5       n [        UU R                  U R                  U R                  U R                  S9nU R                  Ul        U R                  Ul        U R                  Ul        U R                   (       a  SSKJn  UR!                  X5        OU R&                  (       a  UR'                  5       nO]U R(                  (       a  UR)                  5       nO;U R*                  (       a  [,        R.                  " X0R0                  S9nO[3        U5      nU(       a  [5        X5        O[7        U5        U R
                  (       a2  [5        U R
                  [,        R.                  " X0R0                  S95        [7        S[8        R:                  S9  [7        [=        UR?                  5       5      S	 S
3[8        R:                  S9  [7        [=        UR@                  5      S	 S3[8        R:                  S9  [7        URC                  5       S	 S3[8        R:                  S9  g ! [D         a8  n[7        U[8        R:                  S9  [8        RF                  " S5         S nAg S nAff = f)Nrq   rr   )rc   r   colorizer   )diagramsr[   zH------------------------------------------------------------------------)filez12,dz  lines in grammarz  rules in grammarz  nodes in ASTr   )$r9   
whitespacer   r;   rn   object_model_outfilert   ru   r   readrR   rK   rc   colorr   r   r:   r   r|   prettypretty_leanobject_modelr]   r^   r\   rX   ry   printsysstderrlensplitrules	nodecountr   exit)rB   r;   rJ   rP   r|   resultr-   s          r.   mainr   &  s   <D&t7llGwt001kk$--':??AG.II**]]ZZ
  ??..#2299&MM'){{!!**,""&//P#E*W%f $$))&&uG
 	hSZZ(7==?#D));<3::	
 	U[[!$''9:L"4(7cjjI acjj!s   HJ& &
K(0.K##K(__main__)NNFN)rE   zParserConfig | None)NNNFN)NNN)NNNN)'__doc__
__future__r   r(   rt   r$   r   pathlibr   _versionr   
exceptionsr   infosr   	ngcodegenr	   rX   r
   r]   parserr   rI   r   utilr   r5   r9   rF   rR   rH   rY   r_   ra   rd   rn   ry   r   __name__ rC   r.   <module>r      s'  
 #    
  ! &  , 3 $ , % DN  
 
"&
  8 	"&  2 
"&	
  	
 
"&>
  >  
"&	  	  

"&  (7
:z zF rC   