+
     i)@  c                  s   R t ^ RIHt ^ RIt^ RIHtHtHtHtH	t	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHtHt ^ RI H!t! ^ RI"H#t# ^ RI$H%t% ^ RI&H't' ^ RI(H)t) ^ RI*H+t+ ^ RI,H-t- ^ RI.H/t/ ^ RI0H1t1 ^ RI2H3t3 ^ RI4H5t5 ^ RI6H7t7 ^ RI8H9t9 ^ RI:H;t; ^ RI<H=t= ^ RI>H?t? ^ RI@HAtA ]'       d   ^ RIBHCtC ^ R IDHEtE  ! R! R"4      tFR# )#zParse macro code)annotationsN)OptionalAnyTypeTYPE_CHECKINGDictList)
MacroError)Macro)RawValue)Task)AddTask)	EventTask)HoldTask)HoldKeysTask)IfEqTask)IfNumlockTaskIfCapslockTask)IfSingleTask)	IfTapTask)DeprecatedIfEqTask)KeyTask)KeyDownTask)	KeyUpTask)
ModTapTask)
ModifyTask)	MouseTask)ParallelTask)MouseXYTask)
RepeatTask)SetTask)
ToggleTask)WaitTask)	WheelTask)logger)Context)Mappingc                  s   ] tR t^=t$ / R]bR]bR]bR]bR]bR]	bR]
bR]bR	]bR
]bR]bR]bR]bR]bR]bR]bR]bR]R]R]R]R]R]R]R]R]
R]R]R]/CtR]R&   ]R  R! l4       t]R" R# l4       t]R$ 4       t ]R% 4       t!]R& R' l4       t"]R4R) R* ll4       t#]R+ R, l4       t$]R- 4       t%]R5R. l4       t&]R/ 4       t']R0 4       t(]R6R1 R2 ll4       t)R3t*R(# )7ParserZmodifyZrepeatZtogglekeyZkey_downZkey_upZeventZwaitZholdZ	hold_keysZmouseZmouse_xyZwheelZif_eqZ
if_numlockZif_capslockZsetZif_tapZ	if_singleZaddZmod_tapZparallelZmZrZkZeZwZhZifeqzdict[str, type[Task]]TASK_CLASSESc                   V ^8  d   QhRR/# )   outputr    Zformat   "I/usr/lib/python3.14/site-packages/inputremapper/injection/macros/parse.py__annotate__Parser.__annotate__d   s     	D 	D 	D    c                s    \        V \        4      '       g   R# RV P                  4       9   d   R# RV 9   ;'       d    RV 9   ;'       d    \        V 4      ^8  # )zFigure out if this is a macro.F+T())
isinstancestrstriplen)r*      &r.   is_this_a_macroZParser.is_this_a_macroc   sL     &#&&&,,. f}CCCC3v;!3CCr1   c               r(   )r)   innerr6   r+   r,   r-   r.   r/   r0   p   s     % %S %r1   c                s   V P                  4       p ^ p. p^ pRp\        V 4       Fy  w  rVVR8X  d   V'       * pV'       d   K  VR8X  d
   V^,          pVR8X  d
   V^,          pVR8X  g   KF  V^ 8X  g   KO  VP                  WV P                  4       4       V^,           pK{  	  VP                  WR P                  4       4       V# )zExtract parameters from the inner contents of a call.

This does not parse them.

Parameters
----------
inner
    for example '1, r, r(2, k(a))' should result in ['1', 'r', 'r(2, k(a))']
F"r3   r4   ,N)r7   	enumerateappend)r;   bracketsZparamsZstartZstringpositionchars   &      r.   _extract_argsZParser._extract_argso   s     '.NHs{# s{As{As{x1} e(399;< 1# /( 	eFm))+,r1   c                s   V P                  R4      pV P                  R4      pW8w  d   \        V RV RV R24      h^ p^ pV  F:  pV^,          pVR8X  d   V^,          pK  VR8X  g   K'  V^,          pV^ 8X  g   K9   V# 	  V# )z,Find where the first opening bracket closes.r3   r4   zFound z opening and z closing brackets)countr   )macroZopeningsZclosingsr@   rA   rB      &     r.   _count_bracketsZParser._count_brackets   s     ;;s#;;s#zxj@QR  DMHs{As{Aq=  r1   c                s    \         P                  ! RV 4      '       d%   V P                  R^4      pV^ ,          V^,          3# RV 3# )zZSplit "foo=bar" into "foo" and "bar".

If not a keyward param, return None and the param.
z[a-zA-Z_][a-zA-Z_\d]*=.+Z=N)rematchsplit)paramrJ   s   & r.   _split_keyword_argZParser._split_keyword_arg   sC     88/77KKQ'E8U1X%%U{r1   c               $    V ^8  d   QhRRRRRR/# )r)   keyword_argszDict[str, Any]
task_class
Type[Task]returnNoner+   r,   r-   r.   r/   r0      s+     	P 	P$	P	P 
	Pr1   c                	s    V  F7  pVP                    F  pVP                  V8X  g   K   K(  	  \        R V 2R7      h	  R# )zUnknown keyword argument msgN)Zargument_configsZnamer   )rN   rO   Zkeyword_argZarguments   &&  r.    _validate_keyword_argument_namesZ'Parser._validate_keyword_argument_names   sB    
 (K&77==K/ 8 !'@%NOO (r1   Nc               s4    V ^8  d   QhRRRRRRRRR	R
RRRR/# )r)   coder6   contextzOptional[Context]mappingr$   verboseboolmacro_instancezOptional[Macro]depthintrQ   r	   r+   r,   r-   r.   r/   r0      sW     Y. Y.Y."Y. Y. 	Y.
 (Y. Y. 
Y.r1   c           
     s0  a \        V \        4      '       g   Q h\        V\        4      '       g   Q hV3R lpRV,          pV P                  4       p \        P
                  ! RV 4      pV'       d
   V^,          MRp	V	f   V! RWp4       \        V R7      # Vf   \        WV4      pM\        V\        4      '       g   Q h\        P                  P                  V	4      p
V
f   \        V RV	 24      h\        P                  V 4      ^,
          pW P                  R4      ^,           V pV! R	WyV4       \        P                  V4      p. p/ pV F  p\        P                  V4      w  pp\        P!                  VP                  4       VVSRV^,           4      pVf6   \#        V4      ^ 8  d   R
V R2p\        V V4      hVP%                  V4       K  VV9   d   \        V RV R24      hVVV&   K  	  V! RVV	VV4       \        P'                  VV
4       \        P)                  V V	V
V4        V
! VVVV4      pVP+                  V4       \#        T 4      T^,           8  pT'       d   Y^,           ,          pTR8H  pT'       d1   Y^,           R pT! RTT4       \        P!                  TTTSTT4       M6\        P
                  ! RT4      '       d   \        T RT RT^,             24      h\        TR7      #   \,         d   p\        \        T4      R7      ThRp?ii ; i)a_  Handle a subset of the macro, e.g. one parameter or function call.

Not using eval for security reasons.

Parameters
----------
code
    Just like parse. A single parameter or the complete macro as string.
    Comments and redundant whitespace characters are expected to be removed already.
    Example:
    - "parallel(key(a),key(b).key($foo))"
    - "key(a)"
    - "a"
    - "key(b).key($foo)"
    - "b"
    - "key($foo)"
    - "$foo"
context : Context
macro_instance
    A macro instance to add tasks to. This is the output of the parser, and is
    organized like a tree.
depth
    For logging porposes
c                 sH   < S'       d   \         P                  ! V / VB  R # R # )N)r"   debug)ZargsZkwargsrY   s   *,r.   r^   Z$Parser._parse_recurse.<locals>.debug   s    d-f- r1   z  z^(\w+)\(Nz
%svalue %s)valuezUnknown function r3   z%scalls %s with %szPositional argument "z" follows keyword argumentzThe "z" argument was specified twicez%sadd call to %s with %s, %srS   Z.z%sfollowed by %sz	[a-zA-Z_]zExpected a "." to follow after )r5   r6   r]   r7   rH   rI   r	   r   r%   r'   Zgetr   rG   ZindexrC   rL   _parse_recurser8   r?   rU   _validate_num_argsZadd_taskZ	TypeError)rV   rW   rX   rY   r[   r\   r^   ZspaceZtask_call_match	task_namerO   Zclosing_bracket_positionr;   raw_string_argsZpositional_argsrN   rK   r&   r_   ZparsedrT   ZtaskZ	exceptionZmore_code_existsZ	next_charZstatement_closedZchains   &&&f&&                     r.   r`   ZParser._parse_recurse   sB   B $$$$$%%%%%	. uzz| ((;5*9OA&t	
 ,,$''!"4':N ne4444((,,Y7
T%6yk#BCC $*#9#9$#?!#C ZZ_q(+CD"Ee< !..u5 +-,.$E2259JC**	F {|$q(1#6PQC$T3//&&v.,&$TU3%7U+VWW$*S!% %( 	*	
 	//	
 	!!		
		@	D ##D)
 t9'?!'CC9:I(C/9;<(%7%%" ,	22 5959:;=  n--;  	@Y0i?	@s   (K/ /L:LLc          
     s,    V ^8  d   QhRRRRRRRRRR	/# )
r)   rV   r6   rb   rO   rP   rc   z	List[str]rQ   rR   r+   r,   r-   r.   r/   r0   f  s:     ( ((( ( #	(
 
(r1   c                	s    VP                  4       w  rE\        V4      pWd8  g   We8  d,   WE8w  d   V R V RV RV R2pMV RV RV R2p\        W4      hR# )z takes between z and z, not z parametersz takes N)Zget_num_parametersr8   r   )rV   rb   rO   rc   Zmin_argsZmax_argsZnum_provided_argsrT   s   &&&&    r.   ra   ZParser._validate_num_argse  s     (::<0'+<+G# k
%z J,-[:  !k
&9J8K;W  T'' ,Hr1   c                s<   RV 9  d   V # RV 9   g   RV 9   d   \        V RV  R24      hV P                  R4       Uu. uF  qP                  4       NK  	  ppRV9   d   \        RV  R24      hRR	P                  V4       R2p\        P
                  ! R
W4       V# u upi )z(Transform a + b + c to hold_keys(a,b,c).r2   r3   r4   z'Mixing "+" and macros is unsupported: "r<    zInvalid syntax for "z
hold_keys(r=   zTransformed "%s" to "%s")r   rJ   r7   Zjoinr"   r^   )rE   chunkZchunksr*   s   &   r.   handle_plus_syntaxZParser.handle_plus_syntax{  s     eL%<3%<U&MuXUV$WXX-2[[-=>-=E++--=><3E7!<==chhv./q1/? ?s   Bc                s    Rp\        V P                  V4      4       FC  w  r4V^,          ^ 8X  d!   V\        P                  ! RRV4      ,          pMW$,          pW!,          pKE  	  VR\	        V4      )  # )zERemove whitespaces, tabs, newlines and such outside of string quotes.rd   z\sN)r>   rJ   rH   Zsubr8   )rE   Z	delimiterresultire   s   &&   r.   remove_whitespacesZParser.remove_whitespaces  sj     !%++i"89HA1uz"&&E22F : 'Y((r1   c                sh   Rp\        V P                  R4      4       F  w  r#\        VP                  R4      4       FN  w  rEV^ 8  d   RV 2pV^,          ^ 8X  d(   RV9   d!   WP                  R4      ^ ,          ,          p MW,          pKP  	  W P                  R4      8  g   K  VR,          pK  	  V# )z=Remove comments from the macro and return the resulting code.rd   
r<   Z#)r>   rJ   rD   )rE   rg   rh   ZlineZjre   rF   r.   remove_commentsZParser.remove_comments  s      T!23GA%djjo6q5wKE q5A:#,kk#.q11FOF 7 ;;t$$$ 4" r1   c                sT    \         P                  \         P                  V 4      R4      # )z+Remove everything irrelevant for the macro.r<   )r%   ri   rk   )rV   r9   r.   cleanZParser.clean  s(     ((""4(
 	
r1   c               rM   )r)   rE   r6   rY   rZ   rQ   r   r+   r,   r-   r.   r/   r0     s!      S t u r1   c                s0   \         P                  ! RV P                  RR4      4       \        P	                  V 4      p \        P                  V 4      p \        P                  V VVV4      P                  p\        V\        4      '       g   \        V R4      hV# )a  Parse and generate a Macro that can be run as often as you want.

Parameters
----------
macro
    "repeat(3, key(a).wait(10))"
    "repeat(2, key(a).key(KEY_A)).key(b)"
    "wait(1000).modify(Shift_L, repeat(2, k(a))).wait(10, 20).key(b)"
context : Context, or None for use in Frontend
mapping
    the mapping for the macro, or None for use in Frontend
verbose
    log the parsing True by default
zparsing macro %srj   rd   z!The provided code was not a macro)r"   r^   Zreplacer%   rl   rf   r`   r_   r5   r   r   )rE   rW   rX   rY   Z	macro_objs   &&&& r.   parseZParser.parse  s    " 	'tR)@AU#))%0))	

 % 	 )U++U$GHHr1   r+   )Ni    )r<   )NNT)+Z__name__Z
__module__Z__qualname__Z__firstlineno__r   r   r   r   r   r   r   r    r   r   r   r   r!   r   r   r   r   r   r   r   r   r   r   r'   Z__annotations__Zstaticmethodr:   rC   rG   rL   rU   r`   ra   rf   ri   rk   rl   rm   Z__static_attributes__r+   r1   r.   r%   r%   =   s   #+*#+*#+ 	*#+ 	w	#+
 	K#+ 	)#+ 	#+ 	#+ 	#+ 	\#+ 	#+ 	K#+ 	#+ 	#+ 	m#+  	~!#+" 	w##+$ 	)\w:L 	ZZWYXX 	"E#+L' #J 	D 	D % %N  2 	 	 	P 	P Y. Y.v ( (*  $ ) )  0 
 
  r1   r%   )GZ__doc__Z
__future__r    rH   Ztypingr   r   r   r   r   r   Z'inputremapper.configs.validation_errorsr   Z$inputremapper.injection.macros.macror   Z(inputremapper.injection.macros.raw_valuer	   Z#inputremapper.injection.macros.taskr
   Z(inputremapper.injection.macros.tasks.addr   Z*inputremapper.injection.macros.tasks.eventr   Z)inputremapper.injection.macros.tasks.holdr   Z.inputremapper.injection.macros.tasks.hold_keysr   Z*inputremapper.injection.macros.tasks.if_eqr   Z+inputremapper.injection.macros.tasks.if_ledr   r   Z.inputremapper.injection.macros.tasks.if_singler   Z+inputremapper.injection.macros.tasks.if_tapr   Z)inputremapper.injection.macros.tasks.ifeqr   Z(inputremapper.injection.macros.tasks.keyr   Z-inputremapper.injection.macros.tasks.key_downr   Z+inputremapper.injection.macros.tasks.key_upr   Z,inputremapper.injection.macros.tasks.mod_tapr   Z+inputremapper.injection.macros.tasks.modifyr   Z*inputremapper.injection.macros.tasks.mouser   Z-inputremapper.injection.macros.tasks.parallelr   Z-inputremapper.injection.macros.tasks.mouse_xyr   Z+inputremapper.injection.macros.tasks.repeatr   Z(inputremapper.injection.macros.tasks.setr   Z+inputremapper.injection.macros.tasks.toggler   Z)inputremapper.injection.macros.tasks.waitr    Z*inputremapper.injection.macros.tasks.wheelr!   Zinputremapper.logging.loggerr"   Zinputremapper.injection.contextr#   Zinputremapper.configs.mappingr$   r%   r+   r1   r.   <module>rn      s|   *  " 	 A A > 6 = 4 < @ > G ? U G A H < E A C B @ F E B < B > @ /75_ _r1   