
    }fs>                       d Z ddlm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mZ dd	lmZmZmZmZmZmZ d
dlmZmZ  G d de      Zd Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d d e!      Z" G d! d"e      Z# G d# d$e      Z$ G d% d&e      Z% G d' d(e      Z& G d) d*e!      Z' G d+ d,e!      Z( G d- d.e      Z) G d/ d0e      Z* G d1 d2e!      Z+ G d3 d4e!      Z, G d5 d6e,      Z- G d7 d8e!      Z. G d9 d:e.      Z/ G d; d<e.      Z0 G d= d>e.      Z1 G d? d@e/      Z2 G dA dBe/      Z3 G dC dDe      Z4 G dE dFe,      Z5 G dG dHe!      Z6 G dI dJe      Z7 G dK dLe!      Z8 G dM dNe8      Z9 G dO dPe8      Z: G dQ dRe9      Z; G dS dTe      Z< G dU dVe      Z= G dW dXe!      Z> G dY dZe!      Z? G d[ d\e?      Z@ G d] d^e      ZAy)_z<
Python code generation for models defined with tatsu.model
    )annotationsN   )grammars)
OrderedSet)CodegenError)BASE_CLASS_TOKENNode)RETYPEcompress_seqindent	safe_name	timestamptrim   )CodeGeneratorModelRendererc                      e Zd Zd Zy)PythonCodeGeneratorc                    t        |t              sy |j                  j                  }t	               j                  |      }|rt        |t              st        d| d      |S )NzRenderer for z
 not found)	
isinstancer	   	__class____name__globalsget
issubclassBaser   )selfnodenamerenderers       S/var/www/feuerwehr-webapp/venv/lib/python3.12/site-packages/tatsu/codegen/python.py_find_renderer_classz(PythonCodeGenerator._find_renderer_class   sS    $%~~&&9==&z(D9tfJ?@@    N)r   
__module____qualname__r"    r#   r!   r   r      s    r#   r   c                4    t               j                  |       S N)r   render)models    r!   codegenr+      s     ''..r#   c                      e Zd Zd Zd ZdZy)r   c                6    | j                   j                         S r(   )r   definesr   s    r!   r.   zBase.defines!   s    yy  ""r#   c                   t        | j                               }t        d |D              t        fd|D              }|ssydj                  dj	                  t        d |D                          }dj                  dj	                  t        d D                          s	d| d d	S d
t        | j                  |fz        z   S )Nc              3  >   K   | ]  \  }}|s	t        |        y wr(   r   ).0dvalues      r!   	<genexpr>z0Base.make_defines_declaration.<locals>.<genexpr>&   s     ChaUYq\Cs   
c              3  F   K   | ]  \  }}|s|vrt        |        y wr(   r2   )r3   r4   r5   ldefss      r!   r6   z0Base.make_defines_declaration.<locals>.<genexpr>'   s*      
5Qe^ aL
s   ! z[{}], c              3  2   K   | ]  }t        |        y wr(   reprr3   r4   s     r!   r6   z0Base.make_defines_declaration.<locals>.<genexpr>0        2Jq472J   c              3  2   K   | ]  }t        |        y wr(   r<   r>   s     r!   r6   z0Base.make_defines_declaration.<locals>.<genexpr>1   r?   r@   z

    self._define()
)r   r.   osetformatjoinsortedr   define_template)r   r.   sdefsr8   s      @r!   make_defines_declarationzBase.make_defines_declaration$   s    t||~.C'CC 
#
 
 MM$))F2JE2J,J"KLEMM$))F2JE2J,J"KLE.ugRwa@@d4#7#75%.#HIIIr#   zW            self._define(
                %s,
                %s,
            )        N)r   r$   r%   r.   rJ   rH   r&   r#   r!   r   r       s    #J&Or#   r   c                      e Zd ZdZy)Voidzself._void()Nr   r$   r%   templater&   r#   r!   rL   rL   ?       Hr#   rL   c                      e Zd ZdZy)Anyzself._any()NrM   r&   r#   r!   rQ   rQ   C       Hr#   rQ   c                      e Zd ZdZy)Failzself._fail()NrM   r&   r#   r!   rT   rT   G   rO   r#   rT   c                      e Zd Zd ZdZy)Commentc                    dj                  d | j                  j                  j                         D              }|j	                  |       y )NrC   c              3  &   K   | ]	  }d |  yw)z# Nr&   )r3   cs     r!   r6   z(Comment.render_fields.<locals>.<genexpr>M   s      
bJ
s   )lines)rF   r   comment
splitlinesupdate)r   fieldsrZ   s      r!   render_fieldszComment.render_fieldsL   s@    		 
 $		 1 1 < < >
 
 	E"r#   z	
{lines}
Nr   r$   r%   r_   rN   r&   r#   r!   rV   rV   K   s    # Hr#   rV   c                      e Zd Zy)
EOLCommentNr   r$   r%   r&   r#   r!   rb   rb   U       r#   rb   c                      e Zd ZdZy)EOFzself._check_eof()NrM   r&   r#   r!   rf   rf   Y   s    "Hr#   rf   c                      e Zd ZdZy)
_Decoratorz{exp}NrM   r&   r#   r!   rh   rh   ]   s    Hr#   rh   c                      e Zd ZdZy)GroupzM                with self._group():
                {exp:1::}                NrM   r&   r#   r!   rj   rj   a   	    Hr#   rj   c                      e Zd Zd ZdZy)Tokenc                b    |j                  t        | j                  j                               y )N)token)r]   r=   r   ro   r   r^   s     r!   r_   zToken.render_fieldsi   s    D12r#   zself._token({token})Nr`   r&   r#   r!   rm   rm   h   s    3 &Hr#   rm   c                      e Zd Zd ZdZy)Constantc                b    |j                  t        | j                  j                               y )N)constant)r]   r=   r   literalrp   s     r!   r_   zConstant.render_fieldsp   s    tDII$5$567r#   zself._constant({constant})Nr`   r&   r#   r!   rr   rr   o   s    8 ,Hr#   rr   c                      e Zd Zd ZdZy)Alertc                    |j                  t        | j                  j                        | j                  j                         y )N)ru   level)r]   r=   r   ru   ry   rp   s     r!   r_   zAlert.render_fieldsw   s)    d499#4#45TYY__Mr#   zself._alert({literal}, {level})Nr`   r&   r#   r!   rw   rw   v   s    N 1Hr#   rw   c                      e Zd Zd ZdZy)Patternc                f    t        | j                  j                        }|j                  |       y )N)pattern)r=   r   r}   r]   )r   r^   raw_reprs      r!   r_   zPattern.render_fields~   s$    		))*h'r#   zself._pattern({pattern})Nr`   r&   r#   r!   r{   r{   }   s    ( *Hr#   r{   c                      e Zd ZdZy)	LookaheadzJ                with self._if():
                {exp:1::}                NrM   r&   r#   r!   r   r      rk   r#   r   c                      e Zd ZdZy)NegativeLookaheadzM                with self._ifnot():
                {exp:1::}                NrM   r&   r#   r!   r   r      rk   r#   r   c                      e Zd Zd ZdZy)Sequencec                     |j                  dj                   fd j                  j                  D                      j	                         }|j                  |       y )NrC   c              3  @   K   | ]  }j                  |        y wr(   rend)r3   sr   s     r!   r6   z)Sequence.render_fields.<locals>.<genexpr>   s     #MQDIIaL#M   )seqr.   )r]   rF   r   sequencerJ   r   r^   r.   s   `  r!   r_   zSequence.render_fields   sF    $))#M$)):L:L#MMN//1g&r#   z/{seq}
                {defines}                Nr`   r&   r#   r!   r   r      s    '
Hr#   r   c                  (     e Zd Zd Z fdZdZ xZS )Choicec                v     j                   j                         }|rt        j                  |d      }dg|}ndg}|D cg c]  }t	        |       }}|j                   j                         |       |j                  dj                   fd j                   j                  D                     y c c}w )	N(   )widthzexpecting one of: zno available options)nerrorrC   c              3  @   K   | ]  }j                  |        y wr(   r   )r3   or   s     r!   r6   z'Choice.render_fields.<locals>.<genexpr>   s     FqdiilFr   )options)	r   lookahead_strtextwrapwrapr=   r]   counterrF   r   )r   r^   firstsetmsglinesr   es   `     r!   r_   zChoice.render_fields   s    99**,}}XR8H)5H5E+,E"'(Qa((e4IIFDII4E4EFF 	 	
 )s   B6c                    t        | j                  j                        dk(  r  | j                  | j                  d   fi |S t	        |   di |S )Nr   r   r&   )lenr   r   r   superr)   r   r^   r   s     r!   r)   zChoice.render   sJ    tyy  !Q&499T\\!_7777>+F++r#   z                with self._choice():
                {options:1::}
                    self._error(
                {error:2:\n:}  # noqa: COM812
                    )                r   r$   r%   r_   r)   rN   __classcell__r   s   @r!   r   r      s    
,Hr#   r   c                      e Zd Zd ZdZy)Optionc                H    | j                         }|j                  |       y )Nr   )rJ   r]   r   s      r!   r_   zOption.render_fields   s    //1g&r#   zN                with self._option():
                {exp:1::}                Nr`   r&   r#   r!   r   r      s    'Hr#   r   c                  (     e Zd Zd Z fdZdZ xZS )Closurec                D    |j                  | j                                y N)r   r]   r   rp   s     r!   r_   zClosure.render_fields       'r#   c                    d| j                   j                  j                         v rt        | j                    d      dt	        |   di |z   S )Nr&   z may repeat empty sequencerC   r   exp	lookaheadr   r   r)   r   s     r!   r)   zClosure.render   sJ    ((**$)),FGHHegn.v...r#   zq                def block{n}():
                {exp:1::}
                self._closure(block{n})                r   r   s   @r!   r   r      s    (/
Hr#   r   c                      e Zd ZdZy)PositiveClosurezz                def block{n}():
                {exp:1::}
                self._positive_closure(block{n})                NrM   r&   r#   r!   r   r      s	    Hr#   r   c                  (     e Zd Zd Z fdZdZ xZS )Joinc                D    |j                  | j                                y r   r   rp   s     r!   r_   zJoin.render_fields   r   r#   c                    d| j                   j                  j                         v rt        d      dt	        |   di |z   S )Nr&   zmay repeat empty sequencerC   r   r   s     r!   r)   zJoin.render   s?    ((**:;;egn.v...r#   z                def sep{n}():
                {sep:1::}

                def block{n}():
                {exp:1::}
                self._join(block{n}, sep{n})                r   r   s   @r!   r   r      s    (/
Hr#   r   c                      e Zd ZdZy)PositiveJoinz                def sep{n}():
                {sep:1::}

                def block{n}():
                {exp:1::}
                self._positive_join(block{n}, sep{n})                NrM   r&   r#   r!   r   r      	    Hr#   r   c                      e Zd ZdZy)Gatherz                def sep{n}():
                {sep:1::}

                def block{n}():
                {exp:1::}
                self._gather(block{n}, sep{n})                NrM   r&   r#   r!   r   r      r   r#   r   c                      e Zd ZdZy)PositiveGatherz                def sep{n}():
                {sep:1::}

                def block{n}():
                {exp:1::}
                self._positive_gather(block{n}, sep{n})                NrM   r&   r#   r!   r   r     r   r#   r   c                      e Zd ZdZy)LeftJoinz                def sep{n}():
                {sep:1::}

                def block{n}():
                {exp:1::}
                self._left_join(block{n}, sep{n})                NrM   r&   r#   r!   r   r     r   r#   r   c                      e Zd ZdZy)	RightJoinz                def sep{n}():
                {sep:1::}

                def block{n}():
                {exp:1::}
                self._right_join(block{n}, sep{n})                NrM   r&   r#   r!   r   r     r   r#   r   c                      e Zd ZdZy)EmptyClosurezself._empty_closure()NrM   r&   r#   r!   r   r   (  s    &Hr#   r   c                      e Zd ZdZy)SkipToze                def block{n}():
                {exp:1::}
                self._skip_to(block{n})    NrM   r&   r#   r!   r   r   ,  s	    Hr#   r   c                      e Zd ZdZy)OptionalzP                with self._optional():
                {exp:1::}                NrM   r&   r#   r!   r   r   4  rk   r#   r   c                      e Zd ZdZy)Cutzself._cut()NrM   r&   r#   r!   r   r   ;  rR   r#   r   c                      e Zd Zd Zd ZdZy)Namedc                V    | j                    d| j                  | j                         S )N:)r   r   r   r/   s    r!   __str__zNamed.__str__@  s%    ))Adii1233r#   c                    |j                  | j                         t        | j                  j                               y )N)r   r   )r]   r   r   r   r   rp   s     r!   r_   zNamed.render_fieldsC  s%    Ytyy~~-FGr#   zT
                {exp}
                self.name_last_node('{name}')                N)r   r$   r%   r   r_   rN   r&   r#   r!   r   r   ?  s    4HHr#   r   c                      e Zd ZdZy)	NamedListz[
                {exp}
                self.add_last_node_to_name('{name}')                NrM   r&   r#   r!   r   r   L  rk   r#   r   c                      e Zd Zy)OverrideNrc   r&   r#   r!   r   r   S  rd   r#   r   c                      e Zd Zy)OverrideListNrc   r&   r#   r!   r   r   W  rd   r#   r   c                      e Zd Zy)SpecialNrc   r&   r#   r!   r   r   [  rd   r#   r   c                      e Zd ZdZy)RuleRefzself._{name}_()NrM   r&   r#   r!   r   r   _  s     Hr#   r   c                  "     e Zd Z fdZdZ xZS )RuleIncludec                    t         |   |       |j                  | j                  | j                  j
                  j                               y N)r   )r   r_   r]   r   r   ruler   r   s     r!   r_   zRuleInclude.render_fieldsd  s5    f%$))DIINN$6$678r#   z'
                {exp}
                )r   r$   r%   r_   rN   r   r   s   @r!   r   r   c  s    9Hr#   r   c                  <     e Zd Zed        Z fdZd ZdZdZ xZ	S )Rulec                    t        | t        t        z        rt        |       S t	        | j                  t              d         S )Nr   )r   intfloatstrr=   splitr   )ps    r!   
param_reprzRule.param_reprn  s3    au%q6M 01!455r#   c                    	 t        |   di |S # t        $ r*}t        | j                  j                   d|       |d }~ww xY w)N=r&   )r   r)   r   r   r   )r   r^   r   r   s      r!   r)   zRule.renderu  sK    	?7>+F++ 	?$))..!11#67Q>	?s    	A%A  Ac                ,     j                          dx}} j                  j                  r.dj                   fd j                  j                  D              } j                  j                  r2dj                   fd j                  j                         D              }|r|r	|dz   |z   }n|r|}|j                  |       d}t         j                  t        j                        s j                         }|j                  |        j                  j                  }|j                  |rdnd       |j                   j                  j                  s|sd	nd
       |j                   j                  j                  rd       y d       y )Nr9   r:   c              3  ^   K   | ]$  }j                  j                  |             & y wr(   r   r   )r3   r   r   s     r!   r6   z%Rule.render_fields.<locals>.<genexpr>  s'      23		!-s   *-c              3  n   K   | ],  \  }}| d j                  j                  |              . yw)r   Nr   )r3   kvr   s      r!   r6   z%Rule.render_fields.<locals>.<genexpr>  s:      !Aq #Qttyy|456!s   25)paramsr   z	
@leftrec)leftrecz
@nomemo)nomemoz
@isname)isname)reset_counterr   r   rF   kwparamsitemsr]   r   r   r   rJ   
is_leftrecis_memoizableis_name)r   r^   r   r   sdefinesr   s   `     r!   r_   zRule.render_fields{  sL   99YY 7;yy7G7G F 99yy ! MM//1! H
 hd]X-FFV$$))X__5446Hh'))&&gl2>99**7  	 	

 	DII,=,=[F2Fr#   z
        @tatsumasu({params})        {leftrec}        {nomemo}        {isname}
        def _{name}_(self):
        {exp:1::}
        zV            self._define(
                %s,
                %s
            )        )
r   r$   r%   staticmethodr   r)   r_   rN   rH   r   r   s   @r!   r   r   m  s/    6 6? GDHOr#   r   c                  $     e Zd Zd Z fdZ xZS )	BasedRulec                6    | j                   j                         S r(   )rhsr.   r/   s    r!   r.   zBasedRule.defines  s    xx!!r#   c                \    t         |   |       |j                  | j                         y r   )r   r_   r]   r  r   s     r!   r_   zBasedRule.render_fields  s"    f%$((#r#   )r   r$   r%   r.   r_   r   r   s   @r!   r   r     s    "$ $r#   r   c                      e Zd Zd ZdZdZy)Grammarc                    t        | j                        }| j                  j                  D cg c]'  }|j	                  t        |j                              ) }}t        dj                  |            }| j                  j                  j                  }|sd}n"t        |t              rt        |      }nd| d}| j                  j                  j                  *t        | j                  j                  j                        }nd}| j                  j                  j                  }| j                  j                  j                   }| j                  j                  j"                  }	t        | j                  j                  j$                  xs d      }
t        | j                  j                  j&                        }t        | j                  j                  j(                        }dj                  | j                  j                  D cg c]!  }| j+                  |      j-                         # c}      }t/        t1        d t/        t3                     j5                  d      D                    }| j6                  D cg c]  }|t/        |       }}dj                  d	 |D              }|rd
| d}|j9                  t        |      | j                  j                  d   j                  |||||||	||
||       y c c}w c c}w c c}w )N)r   rC   Nonezre.compile(r"z")r9   c              3  2   K   | ]  }t        |        y wr(   )r   )r3   r   s     r!   r6   z(Grammar.render_fields.<locals>.<genexpr>  s     HqCFHr@   .c              3  (   K   | ]
  }d |d  yw)z    ,Nr&   )r3   r   s     r!   r6   z(Grammar.render_fields.<locals>.<genexpr>  s     =qtA5]=s   z(
z
)r   )rulesstartabstract_rulesversion
whitespace	nameguard
ignorecaseleft_recursion	parseinfokeywords	namecharscomments_reeol_comments_re)r   abstract_rule_templater   r  rE   r   r   r   rF   configr  r   r
   r=   r  r  r  r  r  r  r  get_rendererr)   r   tupler   r   r  r]   )r   r^   abstract_templater   r  r  r  r  r  r  r  r  r  r  r  r   r  s                    r!   r_   zGrammar.render_fields  sr    !<!<= 		
 $$)DII*>$?
 
  		. 9:YY%%00
J
F+j)J(B7J99%%1TYY--778IIYY%%00
))88II$$..	))339r:	499++778tyy//??@		:>))//J$Tt$++-J
 eHC	,<,B,B3,GHHI$(MMCqQ]CFCC99=H==XJc*H-))//!$)))!!)#+ 	 	
K
6 K
 Ds   ,L&LL	LzK
            def {name}(self, ast):
                return ast
            a                  #!/usr/bin/env python3

                # WARNING: CAVEAT UTILITOR
                #
                # This file was automatically generated by TatSu.
                #
                #    https://pypi.python.org/pypi/tatsu/
                #
                # Any changes you make to it will be overwritten the next time
                # the file is generated.

                # ruff: noqa: C405, I001, F401, SIM117

                import sys
                from pathlib import Path

                from tatsu.buffering import Buffer
                from tatsu.parsing import Parser
                from tatsu.parsing import tatsumasu
                from tatsu.parsing import leftrec, nomemo, isname
                from tatsu.infos import ParserConfig
                from tatsu.util import re, generic_main


                KEYWORDS: set[str] = set({keywords})


                class {name}Buffer(Buffer):
                    def __init__(self, text, /, config: ParserConfig | None = None, **settings):
                        config = ParserConfig.new(
                            config,
                            owner=self,
                            whitespace={whitespace},
                            nameguard={nameguard},
                            ignorecase={ignorecase},
                            namechars={namechars},
                            parseinfo={parseinfo},
                            comments_re={comments_re},
                            eol_comments_re={eol_comments_re},
                            keywords=KEYWORDS,
                            start={start!r},
                        )
                        config = config.replace(**settings)
                        super().__init__(text, config=config)


                class {name}Parser(Parser):
                    def __init__(self, /, config: ParserConfig | None = None, **settings):
                        config = ParserConfig.new(
                            config,
                            owner=self,
                            whitespace={whitespace},
                            nameguard={nameguard},
                            ignorecase={ignorecase},
                            namechars={namechars},
                            parseinfo={parseinfo},
                            comments_re={comments_re},
                            eol_comments_re={eol_comments_re},
                            left_recursion={left_recursion},
                            keywords=KEYWORDS,
                            start={start!r},
                        )
                        config = config.replace(**settings)
                        super().__init__(config=config)

                {rules}


                class {name}Semantics:
                {abstract_rules}


                def main(filename, **kwargs):
                    if not filename or filename == '-':
                        text = sys.stdin.read()
                    else:
                        text = Path(filename).read_text()
                    parser = {name}Parser()
                    return parser.parse(
                        text,
                        filename=filename,
                        **kwargs,
                    )


                if __name__ == '__main__':
                    import json
                    from tatsu.util import asjson

                    ast = generic_main(main, {name}Parser, name='{name}')
                    data = asjson(ast)
                    print(json.dumps(data, indent=2))
                N)r   r$   r%   r_   r  rN   r&   r#   r!   r  r    s    5
n
]Hr#   r  )B__doc__
__future__r   r   r9   r   collectionsr   rD   
exceptionsr   objectmodelr   r	   utilr
   r   r   r   r   r   cgbaser   r   r   r+   r   rL   rQ   rT   rV   rb   rf   rh   rj   rm   rr   rw   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   r   r  r&   r#   r!   <module>r%     s   #   , % 0 K K 0	- 	/= >4 $ 4 d 	 	#$ # J &D &,t ,1D 1*d *
 
 t T :Z j  g : &4 T T |  '4 'W z $ 
J 
 	u 		9 		d 	!d !* >: >B$ $Zd Zr#   