+
    =iM                    f   ^ RI Ht ^ RIt^ RIHt ^ RIHtHtHt ^ RI	H
t
 ^ RIHt . ROt ! R R]
4      t ! R	 R
]
4      t] ! R R4      4       t ! R R]
4      t] ! R R4      4       t ! R R4      t]P(                  ! R4      t]P(                  ! R4      tR R ltR R ltR tRR ltRR ltR# )    )annotationsN)defaultdict)	dataclassfieldreplace)IntEnum)OPERATOR_PRECEDENCEc                  "    ] tR t^tRt^t^tRtR# )	TableAxisz1Indicates whether a cache is for rows or columns. N)__name__
__module____qualname____firstlineno____doc__ROWCOLUMN__static_attributes__r       w/Users/tonyclaw/.openclaw/workspace/scripts/youtube-playlists/venv/lib/python3.14/site-packages/numbers_parser/xrefs.pyr   r      s    ;
CFr   r   c                  2    ] tR t^tRt ^t ^t ^t ^tRt	R# )RefScopez6The required scope for a name reference in a document.r   N)
r   r   r   r   r   DOCUMENTSHEETTABLENONEr   r   r   r   r   r      s%    @)H$EEEDr   r   c                  n    ] tR t^!t$ R]R&   RtR]R&   RtR]R&   RtR]R&   ]P                  t
R	]R
&   RtR# )ScopedNameRefstrnameNintoffsetr   axistable_idr   scoper   )r   r   r   r   __annotations__r"   r#   r$   r   r   r%   r   r   r   r   r   r   !   s3    
IFCD)HcmmE8#r   r   c                  .    ] tR t^*t^t^t^t^t^t^t	Rt
R# )CellRangeTyper   N)r   r   r   r   	ROW_RANGE	COL_RANGERANGENAMED_RANGECELLNAMED_ROW_COLUMNr   r   r   r   r(   r(   *   s!    IIEKDr   r(   c                  F   ] tR t^3t$ RtR]R&   RtR]R&   RtR]R&   RtR]R&   Rt	R]R	&   R
t
R]R&   R
tR]R&   R
tR]R&   R
tR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   ]! R
RR
R7      tR]R&   R tR tR tR(R R lltR tR tR  tR! tR" tR# tR$ tR% tR& t R't!R# ))	CellRangeNobjectmodelz	int | str	row_startr!   row_end	col_startcol_endFboolrow_start_is_absrow_end_is_abscol_start_is_abscol_end_is_absfrom_table_idto_table_idr(   
range_typeT_do_init)initdefaultreprz	list[str]_table_namesc                	    V P                  4        V P                  P                  P                  4        V P	                  4        R # N)_initialize_table_datar2   name_ref_cacherefresh_set_sheet_idsselfs   &r   __post_init__CellRange.__post_init__D   s0    ##%

!!))+r   c                	    V P                   P                  4       V n        V P                   Uu/ uF!  qV P                  P                  V4      ^8H  bK#  	  upV n        R# u upi    N)r2   table_namesrC   counttable_name_unique)rK   r    s   & r   rF    CellRange._initialize_table_dataI   sX     JJ224AEARAR"
AR$##))$/144AR"
 "
s   'Ac                    V P                   f   V P                  V n         V P                  P                  V P                  4      V n        V P                  P                  V P                   4      V n        R# )z2Determine the sheet IDs for the referenced tables.N)r=   r<   r2   table_id_to_sheet_idfrom_sheet_idto_sheet_idrJ   s   &r   rI   CellRange._set_sheet_idsO   sV    ##11D!ZZ<<T=O=OP::::4;K;KLr   c               $    V ^8  d   QhRRRRRR/# )   refr   is_absr7   returnr   )formats   "r   __annotate__CellRange.__annotate__V   s!     !8 !8c !84 !8S !8r   c                	  a	 V P                   P                  P                  4        \        V\        4      '       d   VP
                  \        P                  8H  MR p\        V\        4      '       d   VP
                  \        P                  8H  MR p\        V\        4      '       d   VP
                  \        P                  8H  MR p\        V\        4      '       d%   V'       d   RVP                   2MVP                  o	MV'       d   RV 2MTo	\        ;QJ d#    V	3R l\         4       F  '       g   K   RM	  R M! V	3R l\         4       4      '       d   RS	 R2o	MRS	9   d   S	P                  RR4      o	V'       g	   V'       d   S	# V P                  V P                  8X  d   S	# V P                   P!                  V P                  4      pV P"                  V P$                  8X  d   V'       d   V'       d   V RS	 2# S	# W`P&                  V,          ,          pV P"                  V P$                  8X  g	   V'       d   V RS	 2# V P                   P)                  V P$                  4      pV RV RS	 2# )F$c              3  ,   <"   T F	  qS9   x  K  	  R # 5irE   r   ).0xref_strs   & r   	<genexpr>'CellRange.expand_ref.<locals>.<genexpr>b   s     9%8G|%8s   T'z'''z::)r2   rG   rH   
isinstancer   r%   r   r   r   r   r    anyr	   r   r<   r=   
table_namerW   rX   rS   
sheet_name)
rK   r\   r]   	no_prefixis_document_uniqueis_sheet_uniqueis_table_uniquerm   rn   rg   s
   &&&&     @r   
expand_refCellRange.expand_refV   s   

!!))+.8m.L.LCII***RW 	 :DC9W9W#))x~~5]b9CC9W9W#))x~~5]bc=))(.#((nCHHG#)#isG39%893339%8999'!nGG^ooc51G*N!1!11NZZ**4+;+;<
!1!11o17j\G9-DWD11*==!1!11_ \G9--ZZ**4+;+;<
R
|2gY77r   c                	Z   V P                   P                  P                  4        V P                  fY   V P                   P                  P                  V P
                  ,          pV P                  V P                  V P                  V4      # V P                  fY   V P                   P                  P                  V P
                  ,          pV P                  V P                  V P                  V4      # V P                  V P                  V P                  V P                  V P                  4      # rE   )r2   rG   rH   r5   
row_rangesr=   _format_row_ranger3   r4   
col_ranges_format_col_ranger6   _format_cell_range)rK   	row_range	col_ranges   &  r   __str__CellRange.__str__y   s    

!!))+>>!

11<<T=M=MNI))$..$,,	RR >>!

11<<T=M=MNI))$..$,,	RR &&t~~t~~t||UYUaUabbr   c                P    Vf   V P                  W4      # V P                  WV4      # )zFormats a row-only range.)_format_single_row_format_row_spanrK   r3   r4   r{   s   &&&&r   rw   CellRange._format_row_range   s+    ?**9@@$$YCCr   c                |    W!,          f   V P                  V4      # V P                  W!,          V P                  4      # )z.Formats a single row, either numeric or named.)_format_numeric_rowrs   r8   )rK   r3   r{   s   &&&r   r   CellRange._format_single_row   s6    '++I66y3T5J5JKKr   c           	         RP                  V P                  \        V^,           4      V P                  4      V P                  \        V^,           4      V P                  RR7      .4      # )zFormats a single numeric row.:Tro   )joinrs   r   r8   )rK   r3   s   &&r   r   CellRange._format_numeric_row   sW    xxIM 2D4I4IJIM 2D4I4IUYZ
 	
r   c           	     .   W1,          fj   RP                  V P                  \        V^,           4      V P                  4      V P                  \        V^,           4      V P                  RR7      .4      # RP                  T P                  W1,          V P                  W1,          P
                  \        P                  8H  ;'       g$    W2,          P
                  \        P                  8H  R7      V P                  W2,          V P                  RR7      .4      # )zFormats a range of rows.r   Tr   )r   rs   r   r8   r9   r%   r   r   r   s   &&&&r   r   CellRange._format_row_span   s    '88OOC	A$68M8MNOOC!$4d6I6IUYOZ  xx())'288H<M<MM E E )//83D3DD	    	 2D4G4GSWX

 
	
r   c                P    Vf   V P                  W4      # V P                  WV4      # )zFormats a column-only range.)_format_single_column_format_column_spanrK   r5   r6   r|   s   &&&&r   ry   CellRange._format_col_range   s+    ?--iCC''	IFFr   c                    W!,          f&   V P                  \        WP                  R7      4      # V P                  W!,          V P                  4      # )z1Formats a single column, either numeric or named.col_abs)rs   xl_col_to_namer:   )rK   r5   r|   s   &&&r   r   CellRange._format_single_column   s?    '??>)EZEZ#[\\y3T5J5JKKr   c           	        W1,          fP   V P                  \        WP                  R7      4       RV P                  \        W P                  R7      RR7       2# RP	                  T P                  W1,          V P                  W1,          P
                  \        P                  8H  ;'       g$    W2,          P
                  \        P                  8H  R7      V P                  W2,          V P                  RR7      .4      # )zFormats a range of columns.r   r   Tr   )rs   r   r:   r;   r   r%   r   r   r   s   &&&&r   r   CellRange._format_column_span   s   'oonYH]H]&^_``abfbqbq  sA  BI  Sf  Sf  sg  swbq  cx  by  z  zxx())'288H<M<MM E E )//83D3DD	    	 2D4G4GSWX

 
	
r   c                `   Ve   Vf3   V P                  \        VVV P                  V P                  R7      4      # RP	                  V P                  \        VVV P                  V P                  R7      4      V P                  \        VVV P
                  V P                  R7      RR7      .4      # )zFormats a full cell range.)row_absr   r   Tr   )rs   xl_rowcol_to_cellr8   r:   r   r9   r;   )rK   r3   r5   r4   r6   s   &&&&&r   rz   CellRange._format_cell_range   s    ?go??! 11 11	  xx%!! $ 5 5 $ 5 5	 % $ 3 3 $ 3 3	 #   
 	
r   )rC   rW   rS   rX   r=   FF)"r   r   r   r   r2   r&   r3   r4   r5   r6   r8   r9   r:   r;   r<   r=   r>   r?   r   rC   rL   rF   rI   rs   r}   rw   r   r   r   ry   r   r   rz   r   r   r   r   r0   r0   3   s    E6IyGSIyGS"d" ND "d" ND M3K $J$Hd#5IL)I

M!8FcDL

*GL
 
r   r0   c                      ] tR t^tR tR tR t]R R l4       tR R lt	R R	 lt
R
 R ltR R ltR R ltR tRtR# )ScopedNameRefCachec                	t    Wn         / V n        / V n        / V n        / V n        / V n        R V n        . V n        R# TN)r2   doc_name_refssheet_name_refstable_name_refsrv   rx   _dirty_cacherQ   )rK   r2   s   &&r   __init__ScopedNameRefCache.__init__   s=    
!! r   c                	    R V n         R# r   )r   rJ   s   &r   
mark_dirtyScopedNameRefCache.mark_dirty   s
     r   c                	\    V P                   '       d   V P                  4        R V n         R# R# )FN)r   calculate_named_rangesrJ   s   &r   rH   ScopedNameRefCache.refresh   s'    '') %D r   c                    V ^8  d   QhRRRR/# )r[   poollistvaluezint | str | boolr   )r_   s   "r   r`   ScopedNameRefCache.__annotate__  s     M M4 M(8 Mr   c                	.   a \        V3R  lV  4       4      # )c              3  n   <"   T F*  p\        V4      \        S4      J g   K  VS8X  g   K&  ^x  K,  	  R# 5irO   )type)re   rf   r   s   & r   rh   2ScopedNameRefCache._exact_count.<locals>.<genexpr>  s*     Ldd1ge&<1e11ds   55
5)sum)r   r   s   &fr   _exact_countScopedNameRefCache._exact_count  s    LdLLLr   c               $    V ^8  d   QhRRRRRR/# )r[   r$   r!   rowr^   int | str | bool | Noner   )r_   s   "r   r`   r     s'     Z Z# ZC Z4K Zr   c                	    V P                   P                  V4      pV P                   P                  V,          V,          V^,
          ,          P                  # rP   )r2   num_header_cols_table_dataformatted_value)rK   r$   r   r   s   &&& r   	_row_dataScopedNameRefCache._row_data  s@    **44X>zz%%h/4_q5HIYYYr   c               $    V ^8  d   QhRRRRRR/# )r[   r$   r!   colr^   r   r   )r_   s   "r   r`   r     s'     Z ZS Zs Z7N Zr   c                	    V P                   P                  V4      pV P                   P                  V,          V^,
          ,          V,          P                  # r   )r2   num_header_rowsr   r   )rK   r$   r   r   s   &&& r   _column_dataScopedNameRefCache._column_data  s@    **44X>zz%%h/!0CDSIYYYr   c               (    V ^8  d   QhRRRRRRRR/# )r[   sheet_idr!   r$   r#   r   r^   zdict[int, str | None]r   )r_   s   "r   r`   r     s2     - -- - 	-
 
-r   c                	   V P                   P                  V4      pV P                   P                  V4      pV\        P                  8X  d-   V P
                  pTpV P                   P                  V4      pTp	M+V P                  pTpV P                   P                  V4      pTp	V\        P                  8X  d   V^ 8X  g   V\        P                  8X  d&   V^ 8X  d   \        P                  \        V4      4      # / p
. p\        Wx4       Uu. uF
  q! W,4      NK  	  pp\        V4       Fj  pW8  d   VP                  R4       RW&   K   V! W,4      pV P                  W4      ^8  d   VP                  R4       RW&   KU  VP                  V4       WV&   Kl  	  V FH  pV P                  V;;,          ^,          uu&   V P                   V,          V;;,          ^,          uu&   KJ  	  V
# u upi )r   N)r2   r   r   r   r   r   number_of_rowsr   number_of_columnsr   dictfromkeysrangeappendr   r   r   )rK   r   r$   r#   r   r   data_lookuprange_start	range_endfirst_offsetscopesnamesidx	all_namesr    s   &&&&           r   _calculate_name_scopes)ScopedNameRefCache._calculate_name_scopes  s    **44X>**44X>9== ..K)K

11(;I*L++K)K

44X>I*LIMM!o&:I$$$A)===y!122;@;XY;XC[/;X	Y#C!T"""81$$Y59LL&"&FKLL&"&3K $ Dt$)$  *40A50  % Zs   
G%c               (    V ^8  d   QhRRRRRRRR/# )r[   r   r!   r$   r#   r   r   zdict[int, CellRange | None]r   )r_   s   "r   r`   r   >  s8     #C #C#C #C 	#C
 ,#Cr   c                F   V\         P                  8X  d&   \        V P                  P	                  V4      4      pM$\        V P                  P                  V4      4      pV P                  P                  V4      pV EF   pWG,          p\        WW'R7      p	Vf   K  WP                  9   d5   \        V	\        P                  R7      WG&   WG,          V P                  V&   Kc  WP                  V,          9   d<   \        V	\        P                  R7      WG&   WG,          V P                  V,          V&   K  V P                  V P                  V4      ^8X  d   \        P                   M\        P"                  p
\        WR7      WG&   WG,          V P$                  V,          V&   EK#  	  R# )zt
For any locally unique row/column names, tag whether they are table-unique,
sheet-unique or document-unique names.
)r#   r$   r"   N)r%   )r   r   r   r2   r   r   rm   r   r   r   r   r   r   r   r   rQ   r   r   r   )rK   r   r$   r#   r   
axis_rangerm   r   r    r%   
scope_types   &&&&&      r   _calculate_scope_types)ScopedNameRefCache._calculate_scope_types>  s>    9== tzz88BCJtzz;;HEFJZZ**84
C;D!$HQE|)))%e83D3DE+1;""4(--h77%e8>>B7={$$X.t4 (()9)9:F!K NN! 
 &e>7={$$X.t4% r   c                   V ^8  d   QhRR/# )r[   r^   zdict[str, int]r   )r_   s   "r   r`   r   c  s     
 
N 
r   c                	|   V P                   P                  4        Uu/ uF  qP                   P                  V4      VbK   	  upV n        V P                   P                  4        Uu/ uF  qV P                   P                  V4      bK   	  upV n        V P                   P                  4        Uu/ uFZ  pV P                  P                  V P                   P                  V4      4      ^8X  g   K>  V P                   P                  V4      VbK\  	  upV n	        V P                   P                  4        UUu/ uFa  pV P                   P                  V4      V P                   P                  V4       Uu/ uF  q P                   P                  V4      VbK   	  upbKc  	  uppV n
        R# u upi u upi u upi u upi u uppi rO   )r2   	sheet_idsrn   sheet_name_to_idsheet_id_to_name	table_idsrQ   rR   rm   unique_table_name_to_idsheet_table_name_to_id)rK   sidtids   &  r   _calculate_table_name_maps-ScopedNameRefCache._calculate_table_name_mapsc  sx   LPJJL`L`Lb cLbS!6!6s!;S!@Lb cLPJJL`L`Lb cLbSdjj&;&;C&@!@Lb c zz++-(
-%%djj&;&;C&@AQF ,DJJ!!#&+-(
$ zz++-	'
 . JJ!!#&;?::;O;OPS;T);TC

%%c*C/;T)  .	'
# !d c(
)'
s/   $F$%$F)-;F.- F.2<F8.$F3F83F8c           	        \        \        4      V n        / V n        V P                  P                  4       V n        V P                  4        / V n        / V n        V P                  P                  4        F  p\        \        4      V P                  V&   V P                  P                  V4       F{  p\        \        4      V P                  V&   V P                  VV\        P                  4      V P                  V&   V P                  VV\        P                  4      V P                  V&   K}  	  K  	  V P                  P!                  4        UUu/ uF  w  r4V^8X  g   K  VRbK  	  uppV n        V P                  P                  4        F  pV P                  V,          P!                  4        UUu/ uF  w  r4V^8X  g   K  VRbK  	  uppV P                  V&   V P                  P                  V4       Fi  pV P#                  VV\        P                  V P                  V,          4       V P#                  VV\        P                  V P                  V,          4       Kk  	  K  	  R# u uppi u uppi )z
Find the globally unique row and column headers and the table unique
row and column headers for use in range references. Returns a dict
mapping table ID to lists of rows and columns and their names if
they are unique.
N)r   r!   r   r   r2   rQ   r   rv   rx   r   r   r   r   r   r   r   itemsr   )rK   r   r$   r    rR   s   &    r   r   )ScopedNameRefCache.calculate_named_rangesr  s    )-!::113'')

,,.H-8-=D  * JJ00:1<S1A$$X.,0,G,GMM-)
 -1,G,G$$-) ; /" +/*<*<*B*B*D
*D;4QR
JD$J*D
 

,,.H /3.B.B8.L.R.R.T..T{tX]abXb
d
.T.D  * !JJ00:++MMOOH-	 ++$$OOH-	 ; /	
.s   I$I$.I*>I*)r   rx   r   r2   rv   r   r   r   r   r   rQ   r   N)r   r   r   r   r   r   rH   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r      sJ    !&
 M MZZ-^#CJ
4r   r   z(\$?)([A-Z]{1,3})(\$?)(\d+)z(\$?)([A-Z]{1,3})c                    V ^8  d   QhRRRR/# )r[   col_strr   r^   r!   r   )r_   s   "r   r`   r`     s     ! !c !c !r   c                r   V '       g   ^ # \         P                  V 4      pV'       g   RV  2p\        V4      hVP                  ^4      p ^ p\	        \        VP                  ^4      4      4       F<  w  rEV\        V4      \        R4      ,
          ^,           ^V,          ,          ,          pK>  	  V^,          pV# )z
Convert a column reference in A1 notation to a zero indexed column.

Parameters
----------
col_str:  str
    A1 notation column reference

Returns
-------
col: int
    Column numbers (zero indexed).

invalid cell reference A)	col_partsmatch
IndexErrorgroup	enumeratereversedord)r   r   msgr   expnchars   &     r   xl_col_to_offsetr    s     OOG$E'y1okk!nG CQ 89
D	CH$q(RX66 : 1HCJr   c                    V ^8  d   QhRRRR/# )r[   cell_strr   r^   tupler   )r_   s   "r   r`   r`     s     # # # #r   c                   V '       g   R# \         P                  V 4      pV'       g   RV  2p\        V4      hVP                  ^4      pVP                  ^4      p^ p\	        \        V4      4       F<  w  rgV\        V4      \        R4      ,
          ^,           ^V,          ,          ,          pK>  	  \        V4      ^,
          pV^,          pW3# )z
Convert a cell reference in A1 notation to a zero indexed row and column.

Parameters
----------
cell_str:  str
    A1 notation cell reference

Returns
-------
row, col: int, int
    Cell row and column numbers (zero indexed).

r   r   )r   r   )range_partsr   r   r   r   r   r   r!   )	r  r   r   r   row_strr   r  r  r   s	   &        r   xl_cell_to_rowcolr
    s     h'E'z2okk!nGkk!nG C 12
D	CH$q(RX66 3 g,
C1HC8Or   c                ^    \        W4      p\        W#4      pWE8X  d   V# VR,           V,           # )a5  
Convert zero indexed row and col cell references to a A1:B1 range string.

Parameters
----------
first_row: int
    The first cell row.
first_col: int
    The first cell column.
last_row: int
    The last cell row.
last_col: int
    The last cell column.

Returns
-------
str:
    A1:B1 style range string.

r   )r   )	first_row	first_collast_rowlast_colrange1range2s   &&&&  r   xl_ranger    s2    * y4Fx2FC<&  r   c                    V ^ 8  d   RV  R2p\        V4      hV^ 8  d   RV R2p\        V4      hV ^,          p V'       d   RMRp\        W4      pWR,           \        V 4      ,           # )a8  
Convert a zero indexed row and column cell reference to a A1 style string.

Parameters
----------
row: int
     The cell row.
col: int
    The cell column.
row_abs: bool
    If ``True``, make the row absolute.
col_abs: bool
    If ``True``, make the column absolute.

Returns
-------
str:
    A1 style string.

zrow reference  below zerocolumn reference rc    )r   r   r   )r   r   r   r   r   r   s   &&&&  r   r   r     sp    * Qwse;/o
Qw!#k2o1HCc"GS*Gs3x''r   c                .   V ^ 8  d   RV  R2p\        V4      hV ^,          p RpV'       d   RMRpV '       dX   V ^,          pV^ 8X  d   ^p\        \        R4      V,           ^,
          4      pWS,           p\        V ^,
          ^,          4      p K_  W,           # )a  
Convert a zero indexed column cell reference to a string.

Parameters
----------
col: int
    The column number (zero indexed).
col_abs: bool, default: False
    If ``True``, make the column absolute.

Returns
-------
    str:
        Column in A1 notation.

r  r  r  rc   r   )r   chrr   r!   )r   r   r   r   	remainder
col_letters   &&    r   r   r   <  s    " Qw!#k2o1HCGc"G
"H	>I SI-12
 & 37b.!r   )r
  r   r  r   r   )F)
__future__r   recollectionsr   dataclassesr   r   r   enumr   numbers_parser.constantsr	   __all__r   r   r   r(   r0   r   compiler  r   r  r
  r  r   r   r   r   r   <module>r#     s    " 	 # 1 1  8
R 
w 
 $ $ $G  y
 y
 y
xv vv jj78JJ+,	!H#L!:"(J)r   