
    }fS#                    V   d Z ddlmZ ddlZddlZddlZddl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 ddlmZ ddlmZ dZd Zi Z	 	 	 	 d	 ddZ	 	 	 	 	 d	 ddZ	 	 	 d	 ddZ	 	 	 	 d	 ddZ 	 	 	 	 d	 ddZ!ddddedf	 ddZ"d Z#d Z$d Z%e&dk(  r e%        yy) 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                    t        j                  dt        d      } | j                         }|j	                  ddd       |j	                  dd	d
d       |j	                  dddd       |j	                  dddd       |j	                  ddd       | j                  d      }| j	                  ddd       |j	                  dddd       |j	                  dddd       | j                  d      }|j	                  dd d!d"d#d$%       |j	                  d&d'd(d)       |j	                  d*d+d,d-d#d %       |j	                  d.d/d0d1d2       |j	                  d3d4d1d5       |j	                  d6d7d8d9       d: }|j	                  d;d<d=|>       | j                  d?      }|j	                  d@dAdBdC       |j	                  dDdEdFdGt        H       | j                         }|j                  r|j                  s| j                  dI       |S )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                    	 | j                  dd      }t        j                  |d         }t        ||d         S # t        $ r}t        j                  d|        |d }~ww xY w)N.r   r   zCouldn't find class )rsplit	importlibimport_modulegetattr	ExceptionargparseArgumentTypeError)pathspathmodulees       I/var/www/feuerwehr-webapp/venv/lib/python3.12/site-packages/tatsu/tool.pyimport_classz parse_args.<locals>.import_class   sl    	KKQ'E,,U1X6F65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   r2   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.   r8   r8      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                    t         }|| t        |      f}||v r||   }n(t        |fd|i|}	 |	j                  | fd|i|x}||<   |	||_        |S |rt               |_        |S )Nconfig)__compiled_grammar_cacheidr   parse	semanticsr   )
grammarnamerH   asmodelrD   settingscachekeymodelgens
             r.   compilerQ      s     %E"Y-
(C
e|c
t?F?h?&SYYwJvJJJc
# L 
/1LrB   c                R    t        | f||||d|} |j                  |f|||d|S )N)rJ   rH   rK   rD   )startrH   rD   )rQ   rG   )	rI   inputrS   rJ   rH   rK   rD   rL   rO   s	            r.   rG   rG      sX      E 5;;iBJ rB   c                8    t        | f|||d|}t        |      S )NrJ   r   rD   )rQ   
ngpythoncg)rI   rJ   r   rD   rL   rO   s         r.   to_python_sourcecoderX      s2     Xf@HE erB   c                P    t        | f|||d|}t        j                  ||      S )NrV   	base_type)rQ   ngobjectmodelmodelgen)rI   rJ   r   r[   rD   rL   rO   s          r.   to_python_modelr^      s:     Xf@HE !!%9==rB   c                <    |t        d      t        |f| ||d|S )Nzgrammar is None)rJ   rH   rD   )r   rQ   )rJ   rI   rH   rD   rL   s        r.   genmodelr`      s9     .//iBJ rB   c                4    t        |f| |||d|} ||      S )N)rJ   r   tracerD   )rQ   )rJ   rI   rb   r   r	   rD   rL   rO   s           r.   gencoderc     s8      E 5>rB   c                    | r\t        |       } | j                         r| j                          | j                  }|j	                         r|j                  dd       y y y )NT)parentsexist_ok)r   is_fileunlinkparentexistsmkdir)r   dirnames     r.   prepare_for_outputrm     sQ    >OO//>>MM$M6  rB   c                    t        j                  | dd      5 }|j                  |       d d d        y # 1 sw Y   y xY w)Nwutf-8encoding)codecsopenwrite)r   contentfs      r.   saverx   !  s5    	XsW	5 	  s   4=c                    t               } | j                  rt        | j                        | _        | j                  }t	        |       t	        | j
                         t        j                  | j                  d      j                         }	 t        || j                  | j                  | j                  | j                        }| j                  |_        | j                  |_        | j                  |_        | j                   rddlm} |j!                  ||       n| j&                  r|j'                         }nV| j(                  r|j)                         }n9| j*                  r"t-        j.                  || j0                        }nt3        |      }|rt5        ||       nt7        |       | j
                  r5t5        | j
                  t-        j.                  || j0                               t7        dt8        j:                         t7        t=        |j?                               d	d
t8        j:                         t7        t=        |j@                        d	dt8        j:                         t7        |jC                         d	dt8        j:                         y # tD        $ r:}t7        |t8        j:                         t9        jF                  d       Y d }~y d }~ww xY w)Nrp   rq   )rb   r   colorizer   )diagramsrZ   zH------------------------------------------------------------------------)filez12,dz  lines in grammarz  rules in grammarz  nodes in ASTr   )$r8   
whitespacer   r:   rm   object_model_outfilers   rt   r   readrQ   rJ   rb   colorr   r   r9   r   r{   prettypretty_leanobject_modelr\   r]   r[   rW   rx   printsysstderrlensplitrules	nodecountr   exit)rA   r:   rI   rO   r{   resultr-   s          r.   mainr   &  s   <D&t7llGwt001kk$--':??AG.II**]]ZZ
  ??..#2299&MM'5){{!!**,""&//P#E*Wf%f $$))&&uG
 	hSZZ(7==?#D));<3::	
 	U[[!$''9:L"4(7cjjI acjj!s   HJ 	K%0KK__main__)NNFN)rD   zParserConfig | None)NNNFN)NNN)NNNN)'__doc__
__future__r   r(   rs   r$   r   pathlibr   _versionr   
exceptionsr   infosr   	ngcodegenr	   rW   r
   r\   parserr   rH   r   utilr   r4   r8   rE   rQ   rG   rX   r^   r`   rc   rm   rx   r   __name__ rB   r.   <module>r      s'  
 #    
  ! &  , 3 $ , % DN  
 
"&
  8 	"&  2 
"&	
  	
 
"&>
  >  
"&	  	  

"&  (7
:z zF rB   