
    Ri(                     ^    d dl ZddlmZ d Zd Zd Zd Zd Zd	 Z	d
 Z
d Z G d de      Zy)    N   )BibDataStringExpressionc                     | j                         }t        |      dkD  r(|d   g|dd D cg c]  }|j                          c}z   }dj                  |      S c c}w )z?Removes leading and trailing whitespaces in all but first line.r   r   N
)
splitlineslenlstripjoin)slinesls      U/home/agent/.friday_env/lib/python3.12/site-packages/bibtexparser/bibtexexpression.py_strip_after_new_linesr      sS    LLNE
5zA~q
%)<Qahhj<<99U =s   Ac                 f    t        | t              r| j                  t               | S t        |       S )zuRemoves leading and trailing whitespaces in all but first line.

    :param s: string or BibDataStringExpression
    )
isinstancer   apply_on_stringsr   )r   s    r   strip_after_new_linesr      s.    
 !,-	12%a((    c                 6      fd} j                  |       y)zDRegister a callback on expression parsing with the adequate message.c                 J     dj                  j                  |             y )NzFound {}: {})formatresultsName)r   r   texprlog_funcs      r   actionz'add_logger_parse_action.<locals>.action   s    &&t'7'7;<r   N)add_parse_action)r   r   r   s   `` r   add_logger_parse_actionr      s    =&!r   c                 ,    t        |      dk(  sJ |d   S )Nr   r   r   string_locationtokens      r   first_tokenr%   '   s    u:??8Or   c                 6    |d   r|d   j                  d      S y )Nr   r   )rstripr!   s      r   remove_trailing_newlinesr(   -   s!    QxQxt$$ r   c                 r    t        |d         dk  ry|d   d   dk(  rdnd}|d   d   dk(  rdnd }|d   || S )Nr   r    {}r    )r"   r#   r$   startends        r   remove_bracesr0   2   sR    
58}q1Xa[C'Q!HRLC'bTQxc""r   c                     |j                  d      }|j                  d      }t        |t        j                        r|d   }|j                  d      t	        |      fS )zO
    Looks for parsed element named 'Field'.

    :returns: (name, value).
    FieldValuer   	FieldName)getr   ppParseResultsr   )r"   r#   r$   fieldvalues        r   field_to_pairr:   ;   sW     IIgEIIgE%) aIIk"!%(* *r   c                     t        j                  d      | z   t        j                  d      z   t        j                  d      | z   t        j                  d      z   z  S )z
    exp -> (exp)|{exp}
    r+   r-   ())r6   Suppress)exps    r   in_braces_or_parsr@   M   sL     [[#bkk#&66[[#bkk#&668 9r   c                   R    e Zd ZdZej
                  Zd Zd Zd Zd Z	d Z
d Zd Zy	)
BibtexExpressionae  Gives access to pyparsing expressions.

    Attributes are pyparsing expressions for the following elements:

    * main_expression: the bibtex file
    * string_def: a string definition
    * preamble_decl: a preamble declaration
    * explicit_comment: an explicit comment
    * entry: an entry definition
    * implicit_comment: an implicit comment

    c           	      \     j                  d        t        j                  d      }t        j                  d      }t        j                  d      } t        j                  t        j                  dz         d      } j                  d        |j                   j                          t        j                  t        j                        d      }t        j                  d	      }t        j                         }| t        j                  d
t        j                  ||z        z   dz         d      z  }|j                  t               t        j                  d
dd       }t        j                  d      }	 t        j                  dt        j                  |	|z        z   dz         d      }
|
j                  t        j                          t        j                   |
|z  |z  d      d      }|j                   j"                          ||z  d      } t        j$                  d      t        j                  t        j&                        z   d      }|j                  t(                t        j*                  d      d      } fd}|j                  |        t        j                  t        j                  dz         d      }|j                  t(                t        j,                  |t        j$                  d      z   |z         d      }|j                  t.                t        j                   |      t        j$                  t        j0                  d            z   d      }|j                  d         |t3        |t        j$                  d      z   |z         z   d        _        t        j6                         t        j8                  d      z   t        j:                         z  } t        j$                  |      t        j                  t        j*                  |      d!"      z   d#       _         j<                  j                  t>                j<                  j                  t               d$ } t        j                  t        j*                  |      j                  |      d!"      d%       _          j@                  j                  t>                t        j$                  |      t3        |t        j$                  d      z    |d&      z         z   d'       _!         t        j$                  |      t3        |      z   d(       _"        t        j                   jB                   jD                  z   j<                  z   j4                  z   j@                  z         _#        y ))Nc                      y N r   r   r   s      r   <lambda>z+BibtexExpression.__init__.<locals>.<lambda>g       r   z@stringz	@preamblez@commentz_-:
StringNamec                      y rE   rF   rG   s      r   rH   z+BibtexExpression.__init__.<locals>.<lambda>q   rI   r   Integerz{}r+   r-   BracedValue)ignore_exprz"{}"QuotedValue#)delimStringExpressionr3   @	EntryType,Keyc                     t        | ||      j                         }t        |      dk  rj                  | |d      t	        |      D ],  \  }}|j                         sj                  | ||z   d       |S )zParse action for validating citekeys.

            It ensures citekey is not empty and has no space.

            :args: see pyparsing documentation.
            r   zEmpty citekeys are not allowed.)locmsgz#Whitespace not allowed in citekeys.)r%   stripr   ParseException	enumerateisspace)r"   r#   r$   keyicselfs         r   citekeyParseActionz5BibtexExpression.__init__.<locals>.citekeyParseAction   s     gx7==?C3x!|))/P * R R!# C199;--hlA . C CC
 Jr   z_-().+r4   =r2   Fieldsc                 j    t        |j                  d            D ci c]  \  }}||
 c}}S c c}}w )Nre   )reversedr5   )r   r   r   kvs        r   rH   z+BibtexExpression.__init__.<locals>.<lambda>   s)    x0IJfq!QTJ Js   /EntryT)	as_stringExplicitCommentc                 8    | d   st        j                  d      y )Nr   zMatch must not be empty.)r6   r\   )r   s    r   mustNotBeEmptyz1BibtexExpression.__init__.<locals>.mustNotBeEmpty   s     Q4''(BCC r   ImplicitCommentStringValueStringDefinitionPreambleDeclaration)$set_string_name_parse_actionr6   CaselessKeywordWord	alphanumsr   _string_name_parse_actionnums
CharsNotInForwardoriginal_text_for
ZeroOrMoreset_parse_actionr0   nested_exprremove_quotesDelimitedList_string_expr_parse_actionr>   alphasr%   SkipToGroupr:   Optionalr@   entryLineEndLiteral	StringEndexplicit_commentr(   implicit_comment
string_defpreamble_declmain_expression)rb   string_def_startpreamble_startcomment_line_startstring_nameintegerbraced_value_contentbraced_valuebrace_in_quotedtext_in_quotedquoted_valuestring_exprr9   
entry_typer_   rc   
field_namer8   
field_listnot_an_implicit_commentrn   s   `                    r   __init__zBibtexExpression.__init__e   s   ))*>? --i8++K8//
; 4bggbllU23LA))*>?$$T%C%CD #"''"''"9-  "}}T2zz| --"--/C CDDsJ 	 	%%m4
 ..ctDu-r++"-- @AACG 	%%b&6&67b&&L(;6s " 	$$T%C%CD&;&0
 <bkk#&);;[I
##K0 biinU#	$ 	/0 6RWWR\\H45kB
##K0 @bkk#&66>?H}- Nb&&u-BKK<L0MM "
##J	LMj'bkk#.>(>(KLM!
 $&::<"**S/#A')||~#6/BKK*+  +B!C)-//0A!C 	../GH..}=	D
! 4 4II-.??O!-!/ 	../GH2;;'78;LKK&'<  "	#7bkk.9/678MO
  "}}""#%%& 

 %%	& 'r   c                     | j                   | j                  | j                  | j                  | j                  fD ]  }t        ||        y)zwAdd notice to logger on entry, comment, preamble, string definitions.

        :param log_fun: logger function
        N)r   r   r   r   r   r   )rb   log_funes      r   add_log_functionz!BibtexExpression.add_log_function   sJ    
 **''''$$//	# 	0A
 $Aw/	0r   c                     || _         y)aK  Set the parseAction for string name expression.

        .. Note::

            For some reason pyparsing duplicates the string_name
            expression so setting its parseAction a posteriori has no effect
            in the context of a string expression. This is why this function
            should be used instead.
        N_string_name_parse_action_fun)rb   funs     r   rs   z-BibtexExpression.set_string_name_parse_action  s     .1*r   c                 (    | j                  |||      S rE   r   rb   r   r   r   s       r   rw   z*BibtexExpression._string_name_parse_action  s    11!Q::r   c                 ,    t        j                  |      S rE   )r   expression_if_neededr   s       r   r   z*BibtexExpression._string_expr_parse_action  s    &;;A>>r   c                 <    | j                   j                  |d      S )z)Execute parse expression on a file objectT)	parse_all)r   
parse_filerb   file_objs     r   r   zBibtexExpression.parse_file  s    ##..x4.HHr   c                 $    | j                  |      S )zRExecute parse expression on a file object

        Alias for parse_file()
        )r   r   s     r   	parseFilezBibtexExpression.parseFile  s    
 x((r   N)__name__
__module____qualname____doc__r6   r\   r   r   rs   rw   r   r   r   rF   r   r   rB   rB   U   s:     &&NP'd
0
1;?I)r   rB   )	pyparsingr6   bibdatabaser   r   r   r   r%   r(   r0   r:   r@   objectrB   rF   r   r   <module>r      sA     0
	)"%
#*$9I)v I)r   