
    Ki
K                         d dl Z e j        j        dk    rd ZeZd Zd ZneZd Zd Z G d d	e	          Z
 G d
 de	          Z G d de
          Z G d de          ZdS )    N   c                     | S N )ss    x/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pylatexenc/macrospec/_argparsers.pyunicoder	   %   s    1H    c                     | S r   r   xs    r   <lambda>r   '       ! r
   c                     | S r   r   r   s    r   r   r   (   r   r
   c                 F    t          |                               d          S Nzutf-8)r	   encoder   s    r   r   r   ,   s    '!**"3"3G"<"< r
   c                 ,    |                      d          S r   )decoder   s    r   r   r   -   s    !((7"3"3 r
   c                   :     e Zd ZdZg df fd	Zd Zd Zd Z xZS )ParsedMacroArgsa  
    Parsed representation of macro arguments.

    The base class provides a simple way of storing the arguments as a list of
    parsed nodes.

    This base class can be subclassed to store additional information and
    provide more advanced APIs to access macro arguments for certain categories
    of macros.

    Arguments:

      - `argnlist` is a list of latexwalker nodes that represent macro
        arguments.  If the macro arguments are too complicated to store in a
        list, leave this as `None`.  (But then code that uses the latexwalker
        must be aware of your own API to access the macro arguments.)

        The difference between `argnlist` and the legacy `nodeargs` is that all
        options, regardless of optional or mandatory, are stored in the list
        `argnlist` with possible `None`\ 's at places where optional arguments
        were not provided.  Previously, whether a first optional argument was
        included in `nodeoptarg` or `nodeargs` depended on how the macro
        specification was given.

      - `argspec` is a string or a list that describes how each corresponding
        argument in `argnlist` represents.  If the macro arguments are too
        complicated to store in a list, leave this as `None`.  For standard
        macros and parsed arguments this is a string with characters '*', '[',
        '{' describing an optional star argument, an optional
        square-bracket-delimited argument, and a mandatory argument.

    Attributes:

    .. py:attribute:: argnlist

       The list of latexwalker nodes that was provided to the constructor

    .. py:attribute:: argspec

       Argument type specification provided to the constructor

    .. py:attribute:: legacy_nodeoptarg_nodeargs

       A tuple `(nodeoptarg, nodeargs)` that should be exposed as properties in
       :py:class:`~pylatexenc.latexwalker.LatexMacroNode` to provide (as best as
       possible) compatibility with pylatexenc < 2.

       This is either `(<1st optional arg node>, <list of remaining args>)` if
       the first argument is optional and all remaining args are mandatory; or
       it is `(None, <list of args>)` for any other argument structure.
     c                      t          t          |           j        di | || _        || _        |                     | j        | j                  | _        d S )Nr   )superr   __init__argnlistargspec_get_legacy_attribslegacy_nodeoptarg_nodeargs)selfr   r   kwargs	__class__s       r   r   zParsedMacroArgs.__init__f   s[    -ot$$-77777  $$T\4=AA 	'''r
   c                    d}|                     d          r$|dd          }|dz  }|                     d          $|dd         dk    r6t          d |dd          D                       r||         ||dz   d          fS d |fS )Nr   *   [c              3   "   K   | ]
}|d k    V  dS ){Nr   .0r   s     r   	<genexpr>z6ParsedMacroArgs._get_legacy_attribs.<locals>.<genexpr>u   s&      &E&EAqCx&E&E&E&E&E&Er
   )
startswithall)r    r   r   nskips       r   r   z#ParsedMacroArgs._get_legacy_attribsp   s      %% 	abbkGQJE   %% 	 1Q3<33&E&E&E&E&E#E#Ee_huQwxx&8::(##r
   c                 8    t          | j        | j                  S )a  
        Called when we export the node structure to JSON when running latexwalker in
        command-line.

        Return a representation of the current parsed arguments in an object,
        typically a dictionary, that can easily be exported to JSON.  The object
        may contain latex nodes and other parsed-argument objects, as we use a
        custom JSON encoder that understands these types.

        Subclasses may
        r   r   )dictr   r   r    s    r   to_json_objectzParsedMacroArgs.to_json_object{   s%     L]
 
 
 	
r
   c                 X    d                     | j        j        | j        | j                  S )Nz{}(argspec={!r}, argnlist={!r}))formatr"   __name__r   r   r2   s    r   __repr__zParsedMacroArgs.__repr__   s*    077N#T\4=
 
 	
r
   )	r6   
__module____qualname____doc__r   r   r3   r7   __classcell__r"   s   @r   r   r   2   s        2 2f !#B B B B B B B$ $ $
 
 
$
 
 
 
 
 
 
r
   r   c                   6     e Zd ZdZ	 	 d fd	ZddZd Z xZS )	MacroStandardArgsParseraX
  
    Parses the arguments to a LaTeX macro.

    This class parses a simple macro argument specification with a specified
    arrangement of optional and mandatory arguments.

    This class also serves as base class for more advanced argument parsers
    (e.g. for a ``\verb+...+`` macro argument parser).  In such cases,
    subclasses should attempt to provide the most suitable `argspec` (and
    `argnlist` for the corresponding :py:class:`ParsedMacroArgs`) for their use,
    if appropriate, or set them to `None`.

    Arguments:

      - `argspec`: must be a string in which each character corresponds to an
        argument.  The character '{' represents a mandatory argument (single
        token or LaTeX group) and the character '[' denotes an optional argument
        delimited by braces.  The character '\*' denotes a possible star char at
        that position in the argument list, a corresponding
        ``latexwalker.LatexCharsNode('*')`` (or `None` if no star) will be
        inserted in the argument node list.  For instance, the string '\*{[[{'
        would be suitable to specify the signature of the '\\newcommand' macro.

        Currently, the argspec string may only contain the characters '\*', '{'
        and '['.

        The `argspec` may also be `None`, which is the same as specifying an
        empty string.

      - `optional_arg_no_space`: If set to `True`, then an optional argument
        cannot have any whitespace between the preceeding tokens and the '['
        character.  Set this to `True` in cases such as for ``\\`` in AMS-math
        environments, where AMS apparently introduced a patch to prevent a
        bracket on a new line after ``\\`` from being interpreted as the
        optional argument to ``\\``.
    
      - `args_math_mode`: Either `None`, or a list of the same length as
        `argspec`.  If a list is given, then each item must be `True`, `False`,
        or `None`.  The corresponding argument (cf. `argspec`) is then
        respectively parsed in math mode (`True`), in text mode (`False`), or
        with the mode unchanged (`None`).  If `args_math_mode` is `None`, then
        all arguments are parsed in the same mode as the current mode.

      - additional unrecognized keyword arguments are passed on to superclasses
        in case of multiple inheritance

    Attributes:

    .. py:attribute:: argspec

       Argument type specification provided to the constructor.

    .. py:attribute:: optional_arg_no_space

       See the corresponding constructor argument.

    .. py:attribute:: args_math_mode

       See the corresponding constructor argument.
    NFc                 F    t          t          |           j        di | |r|nd| _        || _        || _        t          | j        t                    rt          d | j        D                       s't          d
                    | j                            d| _        d S )Nr   c              3      K   | ]}|d v V  	dS )z*[{Nr   r)   s     r   r+   z3MacroStandardArgsParser.__init__.<locals>.<genexpr>   s&      44!1:444444r
   zCargspec must be a string containing chars '*', '[', '{{' only: {!r}Fr   )r   r>   r   r   optional_arg_no_spaceargs_math_mode
isinstance_basestringr-   	TypeErrorr5   &_like_pylatexenc1x_ignore_leading_star)r    r   rA   rB   r!   r"   s        r   r   z MacroStandardArgsParser.__init__   s    5%t,,5?????")1wwr%:",$,44 	44t|44444	U%%   7<333r
   c           
      |    ddl m} |                                g } j        Wt	           j                  t	           j                  k    r-t          d                     j         j                             fd}|} j        r:|	                    |          }|j
        dk    r|j        dk    r|j        |j        z   }t           j                  D ]\  }	}
|
dk    r@|                    |d	 ||	          
          \  }}}||z   }|                    |           L|
dk    r j        rM|t	          |j                  k     r5|j        |                                         r|                    d           |                    | ||	                    }||                    d           |\  }}}||z   }|                    |           |
dk    r|	                    |          }|j
        dk    rf|j                            d          rL|                    |                    |j         ||	          d|j        d                     |j        dz   }|                    d           t/          d                    |
                    t1           j        |          }||||z
  fS )aP  
        Parse the arguments encountered at position `pos` in the
        :py:class:`~pylatexenc.latexwalker.LatexWalker` instance `w`.

        You may override this function to provide custom parsing of complicated
        macro arguments (say, ``\verb+...+``).  The method will be called by
        keyword arguments, so the argument names should not be altered.

        The argument `w` is the :py:class:`pylatexenc.latexwalker.LatexWalker`
        object that is currently parsing LaTeX code.  You can call methods like
        `w.get_goken()`, `w.get_latex_expression()` etc., to parse and read
        arguments.

        The argument `parsing_state` is the current parsing state in the
        :py:class:`~pylatexenc.latexwalker.LatexWalker` (e.g., are we currently
        in math mode?).  See doc for
        :py:class:`~pylatexenc.latexwalker.ParsingState`.

        This function should return a tuple `(argd, pos, len)` where:

        - `argd` is a :py:class:`ParsedMacroArgs` instance, or an instance of a
          subclass of :py:class:`ParsedMacroArgs`.  The base `parse_args()`
          provided here returns a :py:class:`ParsedMacroArgs` instance.

        - `pos` is the position of the first parsed content.  It should be the
          same as the `pos` argument, except if there is whitespace at that
          position in which case the returned `pos` would have to be the
          position where the argument contents start.

        - `len` is the length of the parsed expression.  You will probably want
          to continue parsing stuff at the index `pos+len` in the string.
        r   latexwalkerNz-Invalid args_math_mode={!r} for argspec={!r}!c                     j         S j         |          }||j        k    rS |dk    r                    d          S                     d          S )NT)in_math_modeF)rB   rK   sub_context)jammparsing_stater    s     r   get_inner_parsing_statezCMacroStandardArgsParser.parse_args.<locals>.get_inner_parsing_state  sn    "*$$%a(C{c]%???$$d{{$00d0CCC ,,%,@@@r
   charr$   r(   F)strict_bracesrO   r&   )rO   r%   rO   charsposlenz+Unknown macro argument kind for macro: {!r}r0   )r   rI   make_parsing_staterB   rV   r   
ValueErrorr5   rF   	get_tokentokargrU   	enumerateget_latex_expressionappendrA   r   isspaceget_latex_maybe_optional_argr,   	make_nodeLatexCharsNodeLatexWalkerErrorr   )r    wrU   rO   rI   r   rP   prZ   rM   argtnodenpnloptarginfotupleparseds   `  `            r   
parse_argsz"MacroStandardArgsParser.parse_args   s+   D 	#""""" 0022M*t"##s4<'8'888L$fT%8$,GGI I I	A 	A 	A 	A 	A 	A 6 	&++a..Cw&  SW^^Gcg% .. -	 -	GAts{{!"!7!7"'"9"9!"<"< "8 " "r2
 G%%%%- !c!#hh,,13q6>>CSCS,OOD)))"#"@"@"9"9!"<"< #A # # #*OOD)))!0r2G%%%%kk!nn7f$$););C)@)@$OOK$>2I2I!2L2L*-37 $ C C  
 !AAOOD)))) 'AHHNN   !L
 
 

 QsU##r
   c                 d    d                     | j        j        | j        | j        | j                  S )NzA{}(argspec={!r}, optional_arg_no_space={!r}, args_math_mode={!r}))r5   r"   r6   r   rA   rB   r2   s    r   r7   z MacroStandardArgsParser.__repr__Z  s1    RYYN#T\43M
 
 	
r
   )NFNr   r6   r8   r9   r:   r   rl   r7   r;   r<   s   @r   r>   r>      sy        ; ;x <A $< < < < < <$t$ t$ t$ t$n
 
 
 
 
 
 
r
   r>   c                   *     e Zd ZdZd fd	Zd Z xZS )ParsedVerbatimArgsa  
    Parsed representation of arguments to LaTeX verbatim constructs, such as
    ``\begin{verbatim}...\end{verbatim}`` or ``\verb|...|``.

    Instances of `ParsedVerbatimArgs` are returned by the args parser
    :py:class:`VerbatimArgsParser`.

    Arguments:

      - `verbatim_chars_node` --- a properly initialized
        :py:class:`pylatexenc.latexwalker.LatexCharsNode` that stores the
        verbatim text provided.  It is used to initialize the base class
        :py:class:`ParsedMacroArgs` to expose a single mandatory argument with
        the given verbatim text.  The `verbatim_text` attribute is initialized
        from this node, too.

      - `verbatim_delimiters` --- a 2-item tuple of characters used to delimit
        the verbatim arguemnt (in case of a ``\verb+...+`` macro) or `None`.

    Attributes:

    .. py:attribute:: verbatim_text

       The verbatim text that was provided

    .. py:attribute:: verbatim_delimiters

       If the verbatim text was specified as an argument to ``\verb$...$``, then
       this is set to a 2-item tuple that specifies the begin and end
       delimiters.  Otherwise, the attribute is `None`.
    Nc                 v     t          t          |           j        dd|gd| |j        | _        || _        d S )Nr(   r0   r   )r   rp   r   rT   verbatim_textverbatim_delimiters)r    verbatim_chars_noders   r!   r"   s       r   r   zParsedVerbatimArgs.__init__  s_     	1 $''0 	
)*	
 	
 	
 	
 	
 16#6   r
   c                 X    d                     | j        j        | j        | j                  S )Nz0{}(verbatim_text={!r}, verbatim_delimiters={!r}))r5   r"   r6   rr   rs   r2   s    r   r7   zParsedVerbatimArgs.__repr__  s,    AHHN#T%79Q
 
 	
r
   r   )r6   r8   r9   r:   r   r7   r;   r<   s   @r   rp   rp   c  sV         >7 7 7 7 7 7
 
 
 
 
 
 
r
   rp   c                   0     e Zd ZdZ fdZddZd Z xZS )VerbatimArgsParsera  
    Parses the arguments to various LaTeX "verbatim" constructs such as
    ``\begin{verbatim}...\end{verbatim}`` environment or ``\verb+...+``.

    This class also serves to illustrate how to write custom parsers for
    complicated macro arguments.  See also :py:class:`MacroStandardArgsParser`.

    Arguments:

    .. py:attribute:: verbatim_arg_type

      One of 'verbatim-environment' or 'verb-macro'.
    c                 Z     t          t          |           j        dddi| || _        d S )Nr   r(   r   )r   rw   r   verbatim_arg_type)r    ry   r!   r"   s      r   r   zVerbatimArgsParser.__init__  s:    0 $''0GGGGGG!2r
   Nc           
      t   ddl m} | j        dk    r|j                            d|          }|dk    r|                    |j        |d          ||z
  }t          |                    |j        ||j        |||z            ||          	          }|||fS | j        d
k    r|j        |         	                                rY|dz  }|t          |j                  k    r|                    |j        |d          |j        |         	                                Y|j        |         }|dz   }	|j                            ||	          }
|
dk    r|                    |j        |d          |j        |	|
         }t          |                    |j        |||	|
|	z
            ||f          }|||
dz   |z
  fS d S )Nr   rH   zverbatim-environmentz\end{verbatim}z#Cannot find matching \end{verbatim})r   rU   msgrS   )rt   z
verb-macror%   z!Missing argument to \verb commandz=End of stream reached while reading argument to \verb command)rt   rs   )r   rI   ry   r   findLatexWalkerParseErrorrp   ra   rb   r_   rV   )r    rd   rU   rO   rI   
endverbposlen_argdverbdelimcharbeginposendposverbargs               r   rl   zVerbatimArgsParser.parse_args  s3   """"""!%;;; "3S99JR!77c> 8    c>D%$%KK0J>K67c#c$h,6G4748	 %0 %: %:  D #t$$!\11 #c(""$$ q#ac((??%;;#@ <    #c(""$$  CHM1uHSXXmX66F||!77cX 8    c(6/*G%$%KK0J>K6=4<4:8O	 %0 %E %E
 &3M$B  D #vax|,,A 21r
   c                 L    d                     | j        j        | j                  S )Nz{}(verbatim_arg_type={!r}))r5   r"   r6   ry   r2   s    r   r7   zVerbatimArgsParser.__repr__  s'    +22N#T%;
 
 	
r
   r   rn   r<   s   @r   rw   rw     sf         3 3 3 3 3;- ;- ;- ;-|
 
 
 
 
 
 
r
   rw   )sysversion_infomajorr	   strrD   _str_from_unicode_unicode_from_str
basestringobjectr   r>   rp   rw   r   r
   r   <module>r      s.  @ 


 AK## K<<33
^
 ^
 ^
 ^
 ^
f ^
 ^
 ^
DJ
 J
 J
 J
 J
f J
 J
 J
^2
 2
 2
 2
 2
 2
 2
 2
lS
 S
 S
 S
 S
0 S
 S
 S
 S
 S
r
   