
    Cj2.                       S SK Jr  S SKrS SKJrJr  S SKrS SKJ	r	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  \(       a  S SKJr   " S S\5      r " S S\5      r\R<                  R>                   " S S5      5       r  " S S\5      r!\R<                  R?                  SS9 " S S\5      5       r" " S S5      r#g)    )annotationsN)TYPE_CHECKING
NamedTuple)GroupRenderableType)ReprHighlighter)Padding)Panel)Text)friendly_list)VALID_PSEUDO_CLASSES)get_suggestion)CSSLocationc                  `   ^  \ rS rSrSr S           SU 4S jjjrS	S jrS
S jrSrU =r	$ )
TokenError   z=Error raised when the CSS cannot be tokenized (syntax error).c                h   > Xl         X l        X0l        U=(       d    UU l        [        TU ]  U5        g)a  
Args:
    read_from: The location where the CSS was read from.
    code: The code being parsed.
    start: Line and column number of the error (1-indexed).
    message: A message associated with the error.
    end: End location of token (1-indexed), or None if not known.
N)	read_fromcodestartendsuper__init__)selfr   r   r   messager   	__class__s         g/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/css/tokenizer.pyr   TokenError.__init__   s,    " #	
<%!    c                4   SSK Jn  U R                  S   nU" U R                  SSSS[	        SUS-
  5      US-   4U1S9nUR                  SU R                  S   U R                  S	   S	-
  4U R                  S   U R                  S	   S	-
  45        [        US
S9$ )zTGet a short snippet of code around a given line number.

Returns:
    A renderable.
r   )Syntaxscss
ansi_lightT   )lexerthemeline_numbersindent_guides
line_rangehighlight_lineszreverse bold   red)border_style)rich.syntaxr!   r   r   maxstylize_ranger   r
   )r   r!   line_nosyntaxs       r   _get_snippetTokenError._get_snippet/   s     	'**Q-IIAw{+Wq[9$I
 	ZZ]DJJqMA-.XXa[$((1+/*	

 V%00r   c           
        [        5       n/ n[        U 5      nUR                  [        SSS95        U R                  u  pEU R
                  u  pgU(       a  SU SU SU SU 3nOSU SU SU 3nUR                  U" U5      5        UR                  U R                  5       5        SR                  S UR                  S	5       5       5      n	UR                  [        U" [        U	S
5      5      SS95        [        U6 $ )Nz Error in stylesheet:zbold red)style z, :
c              3  H   #    U  H  nS UR                  5        3v   M     g7f)u   • N)strip).0message_parts     r   	<genexpr>&TokenError.__rich__.<locals>.<genexpr>Z   s%      "
>Pld<%%'()>Ps    ";r,   )r   r+   )pad)r   strappendr   r   r   r3   joinsplitr	   r   )
r   highlightererrorsr   r1   col_nopathwidget_variablecss_locationfinal_messages
             r   __rich__TokenError.__rich__I   s    %'')d)d2*EF** $tfB&7q	6(KLtfAgYax8Lk,/0d'')*		 "
>EmmC>P"
 
 	. 		
 f~r   )r   r   r   r   N)r   r   r   rB   r   tuple[int, int]r   rB   r   ztuple[int, int] | NonereturnNone)rQ   r
   )rQ   r   )
__name__
__module____qualname____firstlineno____doc__r   r3   rM   __static_attributes____classcell__)r   s   @r   r   r      s^    G '+"" " 	"
 " $" 
" ".14 r   r   c                      \ rS rSrSrSrg)UnexpectedEndi   z:Indicates that the text being tokenized ended prematurely. N)rS   rT   rU   rV   rW   rX   r]   r   r   r[   r[   i   s    Dr   r[   c                  V    \ rS rSrSrS
S jrSSS jjrSSS jjrSSS jjrSS jr	Sr
g	)Expectm   z+Object that describes the format of tokens.c                   SU 3U l         [        UR                  5       5      U l        [        UR	                  5       5      U l        [        R                  " SSR                  S UR                  5        5       5      -   S-   5      U l
        U R                  R                  U l        U R                  R                  U l        SU l        SU l        SU l        g)	zcCreate Expect object.

Args:
    description: Description of this class of tokens, used in errors.
z	Expected (|c              3  8   #    U  H  u  pS U SU S3v   M     g7f)z(?P<>)Nr]   )r<   nameregexs      r   r>   "Expect.__init__.<locals>.<genexpr>|   s!     P+$dV1UG1-s   rf   FTN)descriptionlistkeysnamesvaluesregexesrecompilerD   items_regexmatchsearch_expect_eof_expect_semicolon_extract_text)r   rj   tokenss      r   r   Expect.__init__q   s     '{m4&++-(
FMMO,jjhhPPPQ

 [[&&
kk(( !%"r   c                    Xl         U $ )zExpect an end of file.)rv   )r   eofs     r   
expect_eofExpect.expect_eof   s    r   c                    Xl         U $ )z:Tokenizer expects text to be terminated with a semi-colon.)rw   )r   	semicolons     r   expect_semicolonExpect.expect_semicolon   s    !*r   c                    Xl         U $ rO   )rx   )r   extracts     r   extract_textExpect.extract_text   s    $r   c              #  `   #    [        U R                  U R                  5       S h  vN   g  N7frO   )ziprm   ro   r   s    r   __rich_repr__Expect.__rich_repr__   s     tzz4<<000s   $.,.)	rv   rw   rx   rs   rj   rt   rm   ro   ru   N)rj   rB   ry   rB   rQ   rR   )T)r|   boolrQ   r_   )r   r   rQ   r_   )r   r   rQ   r_   rQ   zrich.repr.Result)rS   rT   rU   rV   rW   r   r}   r   r   r   rX   r]   r   r   r_   r_   m   s    5#(

1r   r_   c                  >    \ rS rSr% S\S'   S\S'   S\S'   S\S'   S	rg
)ReferencedBy   rB   rg   rP   locationintlengthr   r]   N)rS   rT   rU   rV   __annotations__rX   r]   r   r   r   r      s    
IK
Ir   r   T)angularc                      \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S	'    S
rS\S'   \SS j5       r\SS j5       rSS jr	SS jr
SS jrSrg
)Token   rB   rg   valuer   r   r   rP   r   NReferencedBy | Nonereferenced_byc                2    U R                   u  pUS-   US-   4$ )z"Start line and column (1-indexed).r+   )r   r   lineoffsets      r   r   Token.start   s"     }}q&1*%%r   c                ^    U R                   u  pUS-   U[        U R                  5      -   S-   4$ )z End line and column (1-indexed).r+   )r   lenr   r   s      r   r   	Token.end   s0     }}q&3tzz?2Q677r   c           	         [        U R                  U R                  U R                  U R                  U R
                  US9$ )a   Return a copy of the Token, with reference information attached.
This is used for variable substitution, where a variable reference
can refer to tokens which were defined elsewhere. With the additional
ReferencedBy data attached, we can track where the token we are referring
to is used.
)rg   r   r   r   r   r   )r   rg   r   r   r   r   )r   bys     r   with_referenceToken.with_reference   s7     **nn]]
 	
r   c                    U R                   $ rO   )r   r   s    r   __str__Token.__str__   s    zzr   c              #  j  #    SU R                   4v   SU R                  4v   SU R                  S   (       d  U R                  S   OU R                  4v   S[        U R                  5      S:  a  U R                  OU R                  S S S-   4v   S	U R
                  4v   S
U R                  S 4v   g 7f)Nrg   r   r   r+   r   r   (   z...r   r   )rg   r   r   r   r   r   r   r   s    r   r   Token.__rich_repr__   s     diitzz!!%)^^A%6DNN1DNN
 	
 3tyy>B#6diiDIIcrNU<RRR$--''t11477s   B1B3r]   )rQ   rP   )r   r   rQ   z'Token')rQ   rB   r   )rS   rT   rU   rV   r   r   propertyr   r   r   r   r   rX   r]   r   r   r   r      s`    
IJ
I-)-M&-& &
 8 8

 	8r   r   c                  :    \ rS rSrSrSS	S jjrS
S jrS
S jrSrg)	Tokenizer   zTokenizes Textual CSS.c                `    X l         Xl        UR                  SS9U l        SU l        SU l        g)zInitialize the tokenizer.

Args:
    text: String containing CSS.
    read_from: Information regarding where the CSS was read from.
T)keependsr   N)r   r   
splitlineslinesr1   rH   )r   textr   s      r   r   Tokenizer.__init__   s.     #	__d_3
r   c                   U R                   nU R                  nU[        U R                  5      :  aw  UR                  (       a%  [        SSU R                  U R                  X#4S5      $ [        U R                  U R                  US-   US-   4UR                  (       a  S5      eS5      eU R                  U   nSnUR                  (       a  UR                  XC5      nUc+  X@R                  S nU =R                   S-  sl         SU l        O$UR                  5       nX@R                  U nX0l        U(       a%  [        SUU R                  U R                  X#4SS	9nU$ OUR                  XC5      nUc  XCS nUR                   S
UR                  S5      S   < S3n	UR                  (       a  UR!                  S5      (       d  U	S-  n	[#        U R                  U R                  US-   US-   4U	5      e[%        UR&                  UR)                  5       SS 5       H
  u  pUc  M
    O   [+        S5      e[        U
UU R                  U R                  X#4SS	9nUR,                  S:X  a  UR.                  R1                  S5      [2        ;  a  UR.                  R1                  S5      n[5        U[7        [2        5      5      nS[9        [2        5       3nU(       a5  [#        U R                  U R                  US-   US-   4SU< SU< SU 35      e[#        U R                  U R                  US-   US-   4SU< SU 35      eU[        U5      -  nU[        U5      :  a  US-  nSnX l         X0l        U$ )zGet the next token.

Args:
    expect: Expect object which describes which tokens may be read.

Raises:
    UnexpectedEnd: If there is an unexpected end of file.
    TokenError: If there is an error with the token.

Returns:
    A new Token.
r|    Nr+   .Unexpected end of file; did you forget a '}' ?zUnexpected end of textr   r   )r   z (found r@   z).z2; Did you forget a semicolon at the end of a line?zcan't reach herepseudo_classr8   zmust be one of zunknown pseudo-class z; did you mean z?; z; )r1   rH   r   r   rv   r   r   r   r[   rw   rx   ru   r   rt   rj   rE   endswithr   r   rm   groupsAssertionErrorrg   r   r;   r   r   rk   r   )r   expectr1   rH   r   preceding_textrt   token
error_lineerror_messagerg   r   r   
suggestion	all_valids                  r   	get_tokenTokenizer.get_token   sm    ,,c$**o%!!NNII%  $NNIIq[&1*- "33 I	 	 6	 	 zz'" MM$/E}!%kkm!4!!%kkF!;$"NNII%"&   LL.E=gJ%%&hz/?/?/DQ/G.J"M  ''
0C0CC0H0H!UU		GaK!+Dm  v||U\\^AB-?@KD  A
 !!344NNII
 JJ.(!!#&.BB ;;,,S1L'd;O6PQJ)-8L*M)NOI NNIIq[&1*-+L+;?:.X[\e[fg	  !NNIIq[&1*-+L+;2i[I	  	#e*SYqLGFr   c                   U R                   nU R                  n U[        U R                  5      :  a:  [	        U R
                  U R                  X#4UR                  (       a  S5      eS5      eU R                  U   nUR                  XC5      nUc  US-  nSnO0X l         UR                  S5      S   U l        U R                  U5      $ M  )zSkip tokens.

Args:
    expect: Expect object describing the expected token.

Raises:
    UnexpectedEndOfText: If end of file is reached.

Returns:
    A new token.
r   zUnexpected end of markupr+   r   )r1   rH   r   r   r[   r   r   rw   ru   spanr   )r   r   r1   rH   r   rt   s         r   skip_toTokenizer.skip_to\  s     ,,#djj/)#NNII% "33 I	 	 8	 	 ::g&DMM$/E}1&#jjmA.~~f--+ r   )r   rH   r1   r   r   N))r   r   )r   rB   r   r   rQ   rR   )r   r_   rQ   r   )	rS   rT   rU   rV   rW   r   r   r   rX   r]   r   r   r   r      s     wr$.r   r   )$
__future__r   rp   typingr   r   	rich.reprrichrich.consoler   r   rich.highlighterr   rich.paddingr	   
rich.panelr
   	rich.textr   textual.css._error_toolsr   textual.css.constantsr   textual.suggestionsr   textual.css.typesr   	Exceptionr   r[   reprautor_   r   r   r   r]   r   r   <module>r      s    " 	 ,  . ,     2 6 .-Q QhEJ E &1 &1 &1R:  18J 18 18hm. m.r   