
    [g                     @    S SK Jr  S SKJrJr  S SKJr   " S S5      rg)    )
QueryLexer)ClauseQueryPresence)QueryParseErrorc                       \ rS rSrS rS rS rS rS r\	S 5       r
\	S 5       r\	S	 5       r\	S
 5       r\	S 5       r\	S 5       r\	S 5       rSrg)QueryParser   c                 \    [        U5      U l        X l        [        5       U l        SU l        g )Nr   )r   lexerqueryr   current_clause
lexeme_idx)selfstringr   s      3/usr/lib/python3/dist-packages/lunr/query_parser.py__init__QueryParser.__init__   s$    '

$h    c                     U R                   R                  5         U R                   R                  U l        U R                  R                  nU(       a  U" U 5      nU(       a  M  U R
                  $ N)r   runlexemes	__class__parse_clauser   )r   states     r   parseQueryParser.parse   sO    

zz))++$KE e zzr   c                 V     U R                   U R                     $ ! [         a     g f = fr   )r   r   
IndexErrorr   s    r   peek_lexemeQueryParser.peek_lexeme   s,    	<<00 		s    
((c                 P    U R                  5       nU =R                  S-  sl        U$ )N   )r!   r   )r   lexemes     r   consume_lexemeQueryParser.consume_lexeme   s#    !!#1r   c                 l    U R                   R                  U R                  5        [        5       U l        g r   )r   clauser   r   r    s    r   next_clauseQueryParser.next_clause#   s$    

$--.$hr   c           	         UR                  5       nUc  g US   [        R                  :X  a  U R                  $ US   [        R                  :X  a  U R
                  $ US   [        R                  :X  a  U R                  $ [        SR                  US   [        US   5      (       a  SUS   -   S-   5      5      eS5      5      e)Ntypez-Expected either a field or a term, found {}{}r   zwith value "" )r!   r   FIELDparse_fieldTERM
parse_termPRESENCEparse_presencer   formatlenclsparserr%   s      r   r   QueryParser.parse_clause'   s    ##%>&>Z---??"F^z.>>!F^z222%%%!?FF6N vh/00 ')99C?	 	  	 	r   c                    UR                  5       nUS   UR                  R                  ;  aA  [        SR	                  US   SR                  UR                  R                  5      5      5      eUS   /UR                  l        UR                  5       nUc  [        S5      eUS   [        R                  :X  a  U R                  $ [        SR	                  US   5      5      e)Nr   z+Unrecognized field "{}", possible fields {}z, zExpected term, found nothingr-   zExpected term, found {})r&   r   
all_fieldsr   r6   joinr   fieldsr!   r   r2   r3   r9   r:   r%   next_lexemes       r   r1   QueryParser.parse_field?   s    &&((6<<#:#::!=DD8$dii0G0G&H  )/x(8'9$((*!"@AAv*//1>>!!";"B"B;vCV"WXXr   c                     UR                  5       nUS   R                  5       UR                  l        SUS   ;   a  SUR                  l        U R                  U5      $ )Nr   *F)r&   lowerr   termuse_pipeline_peek_next_lexemer8   s      r   r3   QueryParser.parse_termU   sX    &&(%+H%5%;%;%="&""16F!!.$$V,,r   c                    UR                  5       nUc  g US   S:X  a   [        R                  UR                  l        OMUS   S:X  a   [        R
                  UR                  l        O$[        SR                  UR                  5      5      eUR                  5       nUc  [        S5      eUS   [        R                  :X  a  U R                  $ US   [        R                  :X  a  U R                  $ [        SR                  US   5      5      e)Nr   -+z5Unrecognized parser operator: {}, expected `+` or `-`z0Expected either a field or a term, found nothingr-   z+Expected either a field or a term, found {})r&   r   
PROHIBITEDr   presenceREQUIREDr   r6   strr!   r   r0   r1   r2   r3   r@   s       r   r5   QueryParser.parse_presence_   s    &&(>(s"-:-E-EF!!*H$-:-C-CF!!*!GNNJJ  ((*!"TUUv*"2"22??" JOO3>>!!=DDVF^T r   c                     UR                  5       n [        US   5      nX1R                  l        U R                  U5      $ ! [         a  n[        S5      UeS nAff = f)Nr   zEdit distance must be numeric)r&   int
ValueErrorr   r   edit_distancerH   )r9   r:   r%   rU   es        r   parse_edit_distanceQueryParser.parse_edit_distance~   sf    &&(	Jx 01M /<+$$V,,  	J!"ABI	J   A 
AAAc                     UR                  5       n [        US   5      nX1R                  l        U R                  U5      $ ! [         a  n[        S5      UeS nAff = f)Nr   zBoost must be numeric)r&   rS   rT   r   r   boostrH   )r9   r:   r%   r[   rV   s        r   parse_boostQueryParser.parse_boost   sf    &&(	Bx()E ',#$$V,,  	B!"9:A	BrY   c                 B   UR                  5       nUc  UR                  5         g US   [        R                  :X  a  UR                  5         U R                  $ US   [        R
                  :X  a  UR                  5         U R                  $ US   [        R                  :X  a  U R                  $ US   [        R                  :X  a  U R                  $ US   [        R                  :X  a  UR                  5         U R                  $ [        SR                  US   5      5      e)Nr-   zUnexpected lexeme type {})r!   r*   r   r2   r3   r0   r1   EDIT_DISTANCErW   BOOSTr\   r4   r5   r   r6   )r9   r:   rA   s      r   rH   QueryParser._peek_next_lexeme   s    ((* v*//1 >>! J$4$44 ??" J$<$<<*** J$4$44??" J$7$77 %%%!+22;v3FG r   )r   r   r   r   r   N)__name__
__module____qualname____firstlineno__r   r   r!   r&   r*   classmethodr   r1   r3   r5   rW   r\   rH   __static_attributes__ r   r   r   r      s    	
'  . Y Y* - -  < 
- 
- 
- 
-  r   r   N)lunr.query_lexerr   
lunr.queryr   r   lunr.exceptionsr   r   rh   r   r   <module>rl      s    ' , +i ir   