Files
old-parkingkoncept/parkingkonceptvenv/lib/python3.7/site-packages/jmespath/__pycache__/parser.cpython-37.pyc

114 lines
16 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
<00>[<5B>]<5D>J<00>@spdZddlZddlmZddlmZddlmZddlmZddlmZGdd <09>d e <09>Z
eGd
d <0B>d e <09><03>Z dS) a<>Top down operator precedence parser.
This is an implementation of Vaughan R. Pratt's
"Top Down Operator Precedence" parser.
(http://dl.acm.org/citation.cfm?doid=512927.512931).
These are some additional resources that help explain the
general idea behind a Pratt parser:
* http://effbot.org/zone/simple-top-down-parsing.htm
* http://javascript.crockford.com/tdop/tdop.html
A few notes on the implementation.
* All the nud/led tokens are on the Parser class itself, and are dispatched
using getattr(). This keeps all the parsing logic contained to a single
class.
* We use two passes through the data. One to create a list of token,
then one pass through the tokens to create the AST. While the lexer actually
yields tokens, we convert it to a list so we can easily implement two tokens
of lookahead. A previous implementation used a fixed circular buffer, but it
was significantly slower. Also, the average jmespath expression typically
does not have a large amount of token so this is not an issue. And
interestingly enough, creating a token list first is actually faster than
consuming from the token iterator one token at a time.
<EFBFBD>N)<01>lexer)<01>with_repr_method)<01>ast)<01>
exceptions)<01>visitorc@s<>eZdZddddddddddddddddddddddddd d
d d d d<0E>ZdZiZdZdxdd<12>Zdd<14>Zdd<16>Z dd<18>Z
dydd<1A>Z dd<1C>Z dd<1E>Z dd <20>Zd!d"<22>Zd#d$<24>Zd%d&<26>Zd'd(<28>Zd)d*<2A>Zd+d,<2C>Zd-d.<2E>Zd/d0<64>Zd1d2<64>Zd3d4<64>Zd5d6<64>Zd7d8<64>Zd9d:<3A>Zd;d<<3C>Zd=d><3E>Zd?d@<40>ZdAdB<64>ZdCdD<64>Z dEdF<64>Z!dGdH<64>Z"dIdJ<64>Z#dKdL<64>Z$dMdN<64>Z%dOdP<64>Z&dQdR<64>Z'dSdT<64>Z(dUdV<64>Z)dWdX<64>Z*dYdZ<64>Z+d[d\<5C>Z,d]d^<5E>Z-d_d`<60>Z.dadb<64>Z/dzddde<64>Z0dfdg<64>Z1dhdi<64>Z2djdk<64>Z3dldm<64>Z4dndo<64>Z5dpdq<64>Z6drds<64>Z7dtdu<64>Z8e9dvdw<64><00>Z:dcS){<7B>Parserr<00><00><00><00><00> <00><00><00>(<00>-<00>2<00>7<00><)<1D>eof<6F>unquoted_identifier<65>quoted_identifier<65>literal<61>rbracket<65>rparen<65>comma<6D>rbrace<63>number<65>current<6E>expref<65>colon<6F>pipe<70>or<6F>and<6E>eq<65>gt<67>lt<6C>gte<74>lte<74>ne<6E>flatten<65>star<61>filter<65>dot<6F>not<6F>lbrace<63>lbracket<65>lparen<65>
<00><>cCs"d|_dg||_||_d|_dS)Nr)<04> tokenizer<65>_tokensZ _buffer_size<7A>_index)<02>self<6C> lookahead<61>r8<00>5/tmp/pip-install-u_6_z2pz/jmespath/jmespath/parser.py<70>__init__Ns zParser.__init__cCsH|j<00>|<01>}|dk r|S|<00>|<01>}||j|<t|j<00>|jkrD|<00><05>|S)N)<06>_CACHE<48>get<65> _do_parse<73>len<65> _MAX_SIZE<5A>_free_cache_entries)r6<00>
expression<EFBFBD>cached<65> parsed_resultr8r8r9<00>parseTs 

z Parser.parsec
Cs<>y
|<00>|<01>Stjk
r6}z ||_<03>Wdd}~XYnZtjk
rd}z|<02>|<01><00>Wdd}~XYn,tjk
r<EFBFBD>}z ||_<03>Wdd}~XYnXdS)N)<07>_parserZ
LexerErrorrA<00>IncompleteExpressionErrorZset_expression<6F>
ParseError)r6rA<00>er8r8r9r=^s

zParser._do_parsecCsrt<00><01><00>|<01>|_t|j<03>|_d|_|jdd<02>}|<00><08>dksh|<00> d<01>}t
<EFBFBD> |d|d|dd|d<00><04>t ||<02>S)Nr)<01> binding_powerr<00>start<72>value<75>typezUnexpected token: %s) rZLexer<65>tokenizer3<00>listr4r5<00> _expression<6F>_current_token<65>_lookahead_tokenrrG<00> ParsedResult)r6rA<00>parsed<65>tr8r8r9rEks   
z Parser._parsecCs<>|<00>d<01>}|<00><01>t|d|d|j<03>}||<02>}|<00><04>}xX||j|kr<>t|d|d<00>}|dkrv|<00>d<01>}|<00>|<07>q:|<00><01>||<04>}|<00><04>}q:W|S)Nrz _token_nud_%srLz _token_led_%s)rQ<00>_advance<63>getattr<74>_error_nud_tokenrP<00> BINDING_POWER<45>_error_led_token)r6rIZ
left_tokenZ nud_function<6F>left<66> current_tokenZledZ error_tokenr8r8r9rOvs 
 
  zParser._expressioncCst<00>|d<00>S)NrK)rr)r6<00>tokenr8r8r9<00>_token_nud_literal<61>szParser._token_nud_literalcCst<00>|d<00>S)NrK)r<00>field)r6r\r8r8r9<00>_token_nud_unquoted_identifier<65>sz%Parser._token_nud_unquoted_identifiercCs@t<00>|d<00>}|<00><02>dkr<|<00>d<03>}t<04>d|d|dd<05><04>|S)NrKr0rrLz1Quoted identifier not allowed for function names.)rr^rPrQrrG)r6r\r^rTr8r8r9<00>_token_nud_quoted_identifier<65>s 
z#Parser._token_nud_quoted_identifiercCs:t<00><01>}|<00><02>dkrt<00><01>}n|<00>|jd<00>}t<00>||<03>S)Nrr*)r<00>identityrP<00>_parse_projection_rhsrX<00>value_projection)r6r\rZ<00>rightr8r8r9<00>_token_nud_star<61>s
 
zParser._token_nud_starcCs|<00>t<01><02><00>S)N)<03>_token_led_filterrra)r6r\r8r8r9<00>_token_nud_filter<65>szParser._token_nud_filtercCs|<00><00>S)N)<01>_parse_multi_select_hash)r6r\r8r8r9<00>_token_nud_lbrace<63>szParser._token_nud_lbracecCs|<00><00>}|<00>d<01>|S)Nr)rO<00>_match)r6r\rAr8r8r9<00>_token_nud_lparen<65>s
zParser._token_nud_lparencCs*t<00>t<00><02><00>}|<00>|jd<00>}t<00>||<03>S)Nr))rr)rarbrX<00>
projection)r6r\rZrdr8r8r9<00>_token_nud_flatten<65>s zParser._token_nud_flattencCs|<00>|jd<00>}t<02>|<02>S)Nr-)rOrXrZnot_expression)r6r\<00>exprr8r8r9<00>_token_nud_not<6F>szParser._token_nud_notcCsz|<00><00>dkr$|<00><01>}|<00>t<03><04>|<02>S|<00><00>dkrn|<00>d<03>dkrn|<00><06>|<00><06>|<00>|jd<00>}t<03> t<03><04>|<02>S|<00>
<EFBFBD>SdS)N)rrr*rr) rP<00>_parse_index_expression<6F>_project_if_slicerra<00>
_lookaheadrUrbrXrl<00>_parse_multi_select_list)r6r\rdr8r8r9<00>_token_nud_lbracket<65>s  zParser._token_nud_lbracketcCsR|<00>d<01>dks|<00>d<03>dkr$|<00><01>St<02>|<00>d<01>d<00>}|<00><05>|<00>d<05>|SdS)NrrrrKr)rr<00>_parse_slice_expressionr<00>indexrQrUrj)r6<00>noder8r8r9rp<00>s
zParser._parse_index_expressioncCs<>dddg}d}|<00><00>}x<>|dks<>|dkr<>|dkr\|d7}|dkrR|<00>|<00>d<01>d<06>|<00><03>n6|dkr<>|<00>d<01>d||<|<00><03>n|<00>|<00>d<01>d<06>|<00><00>}qW|<00>d<02>tj|<01>S) Nrrr
rrz syntax errorrrK)rP<00>_raise_parse_error_for_tokenrQrUrjr<00>slice)r6<00>partsrvr[r8r8r9ru<00>s$


 
zParser._parse_slice_expressioncCst<00><01>S)N)rZ current_node)r6r\r8r8r9<00>_token_nud_current<6E>szParser._token_nud_currentcCs|<00>|jd<00>}t<02>|<02>S)Nr)rOrXrr)r6r\rAr8r8r9<00>_token_nud_expref<65>szParser._token_nud_exprefcCsr|<00><00>dksJ|<00>|jd<00>}|ddkr:|d<00>|<02>|St<04>||g<02>Sn$|<00><06>|<00>|jd<00>}t<04>||<02>SdS)Nr*r,rL<00> subexpression<6F>children) rP<00>_parse_dot_rhsrX<00>appendrr}rUrbrc)r6rZrdr8r8r9<00>_token_led_dot<6F>s   zParser._token_led_dotcCs|<00>|jd<00>}t<02>||<02>S)Nr )rOrXrr )r6rZrdr8r8r9<00>_token_led_pipeszParser._token_led_pipecCs|<00>|jd<00>}t<02>||<02>S)Nr!)rOrXrZ or_expression)r6rZrdr8r8r9<00> _token_led_or szParser._token_led_orcCs|<00>|jd<00>}t<02>||<02>S)Nr")rOrXrZand_expression)r6rZrdr8r8r9<00>_token_led_and szParser._token_led_andcCs<>|ddkr:|<00>d<03>}t<01>|d|d|dd|d<00><04>|d}g}x8|<00><03>dks~|<00><04>}|<00><03>dkrr|<00>d<08>|<04>|<05>qHW|<00>d<07>t<07>||<04>}|S) NrLr^<00><><EFBFBD><EFBFBD><EFBFBD>rJrKzInvalid function name '%s'rr) rQrrGrPrOrjr<>rZfunction_expression)r6rZZprev_t<5F>name<6D>argsrAZ function_noder8r8r9<00>_token_led_lparens 
 

 zParser._token_led_lparencCsH|<00>d<01>}|<00>d<02>|<00><02>dkr*t<03><04>}n|<00>|jd<00>}t<03>|||<02>S)Nrrr)r+)rOrjrPrrarbrXZfilter_projection)r6rZ<00> conditionrdr8r8r9rf%s 

 
zParser._token_led_filtercCs |<00>|d<01>S)Nr#)<01>_parse_comparator)r6rZr8r8r9<00> _token_led_eq/szParser._token_led_eqcCs |<00>|d<01>S)Nr()r<>)r6rZr8r8r9<00> _token_led_ne2szParser._token_led_necCs |<00>|d<01>S)Nr$)r<>)r6rZr8r8r9<00> _token_led_gt5szParser._token_led_gtcCs |<00>|d<01>S)Nr&)r<>)r6rZr8r8r9<00>_token_led_gte8szParser._token_led_gtecCs |<00>|d<01>S)Nr%)r<>)r6rZr8r8r9<00> _token_led_lt;szParser._token_led_ltcCs |<00>|d<01>S)Nr')r<>)r6rZr8r8r9<00>_token_led_lte>szParser._token_led_ltecCs&t<00>|<01>}|<00>|jd<00>}t<00>||<02>S)Nr))rr)rbrXrl)r6rZrdr8r8r9<00>_token_led_flattenAs
 zParser._token_led_flattencCs~|<00>d<01>}|ddkrJ|<00><01>}|ddkr<|d<00>|<03>|S|<00>||<03>Sn0|<00>d<06>|<00>d<07>|<00>|jd<00>}t<07>||<03>SdS)NrrL)rr<00>index_expressionr~r*r) rQrpr<>rqrjrbrXrrl)r6rZr\rdr8r8r9<00>_token_led_lbracketGs
  

zParser._token_led_lbracketcCs:t<00>||g<02>}|ddkr2t<00>||<00>|jd<00><01>S|SdS)NrLryr*)rr<>rlrbrX)r6rZrdZ
index_exprr8r8r9rqZs  zParser._project_if_slicecCs|<00>|j|<00>}t<02>|||<03>S)N)rOrXr<00>
comparator)r6rZr<>rdr8r8r9r<>cszParser._parse_comparatorcCsJg}x0|<00><00>}|<01>|<02>|<00><02>dkr(Pq|<00>d<02>qW|<00>d<01>t<04>|<01>S)Nrr)rOr<>rPrjrZmulti_select_list)r6Z expressionsrAr8r8r9rsgs
 
zParser._parse_multi_select_listcCs<>g}x<>|<00>d<01>}|jddgd<04>|d}|<00>d<06>|<00>d<01>}tj||d<07>}|<01>|<05>|<00><07>dkrl|<00>d<08>q|<00><07>d kr|<00>d <09>PqWtj|d
<EFBFBD>S) Nrrr)<01> token_typesrKr)<02>key_namerwrr)Znodes) rQ<00>_match_multiple_tokensrjrOrZ key_val_pairr<72>rPZmulti_select_dict)r6<00>pairsZ key_tokenr<6E>rKrwr8r8r9rhss 
 


   
zParser._parse_multi_select_hashcCs<>|j|<00><01>|jkrt<03><04>}nd|<00><01>dkr6|<00>|<01>}nL|<00><01>dkrN|<00>|<01>}n4|<00><01>dkrp|<00>d<03>|<00>|<01>}n|<00>|<00> d<04>d<05>|S)Nr/r+r,rz syntax error)
rXrP<00>_PROJECTION_STOPrrarOrjrrxrQ)r6rIrdr8r8r9rb<00>s
     
  zParser._parse_projection_rhscCs<>|<00><00>}|dkr|<00>|<01>S|dkr4|<00>d<02>|<00><03>S|dkrN|<00>d<03>|<00><04>S|<00>d<04>}ddddg}d||df}|<00>||<05>dS) N)rrr*r/r.rrrzExpecting: %s, got: %srL)rPrOrjrsrhrQrx)r6rIr7rT<00>allowed<65>msgr8r8r9r<00>s 



zParser._parse_dot_rhscCs6|ddkr&t<00>|d|d|d<00><03>|<00>|d<05>dS)NrLrrJrKz invalid token)rrFrx)r6r\r8r8r9rW<00>s zParser._error_nud_tokencCs|<00>|d<01>dS)Nz invalid token)rx)r6r\r8r8r9rY<00>szParser._error_led_tokenNcCs,|<00><00>|kr|<00><01>n|<00>||<00>d<01><01>dS)Nr)rPrU<00>_raise_parse_error_maybe_eofrQ)r6<00>
token_typer8r8r9rj<00>s 
z Parser._matchcCs*|<00><00>|kr|<00>||<00>d<01><01>|<00><03>dS)Nr)rPr<>rQrU)r6r<>r8r8r9r<><00>s zParser._match_multiple_tokenscCs|jd7_dS)Nr)r5)r6r8r8r9rU<00>szParser._advancecCs|j|jdS)NrL)r4r5)r6r8r8r9rP<00>szParser._current_tokencCs|j|j|dS)NrL)r4r5)r6rr8r8r9rr<00>szParser._lookaheadcCs|j|j|S)N)r4r5)r6rr8r8r9rQ<00>szParser._lookahead_tokencCs,|d}|d}|d}t<00>||||<02><04>dS)NrJrKrL)rrG)r6r\<00>reason<6F> lex_position<6F> actual_value<75> actual_typer8r8r9rx<00>s
z#Parser._raise_parse_error_for_tokencCsN|d}|d}|d}|dkr.t<00>|||<05><03>d||f}t<00>||||<06><04>dS)NrJrKrLrzExpecting: %s, got: %s)rrFrG)r6Z expected_typer\r<>r<>r<><00>messager8r8r9r<><00>s
z#Parser._raise_parse_error_maybe_eofcCs2x,t<00>|j<02><03>t|jd<00><01>D] }|j|=qWdS)Nr )<06>random<6F>sampler;<00>keys<79>intr?)r6<00>keyr8r8r9r@<00>s"zParser._free_cache_entriescCs|j<00><01>dS)z'Clear the expression compilation cache.N)r;<00>clear)<01>clsr8r8r9<00>purge<67>sz Parser.purge)r )r)N);<3B>__name__<5F>
__module__<EFBFBD> __qualname__rXr<>r;r?r:rDr=rErOr]r_r`rergrirkrmrortrprur{r|r<>r<>r<>r<>r<>rfr<>r<>r<>r<>r<>r<>r<>r<>rqr<>rsrhrbrrWrYrjr<>rUrPrrrQrxr<>r@<00> classmethodr<64>r8r8r8r9r%s<>

 
 
  
 rc@s.eZdZdd<02>Zd
dd<05>Zdd<07>Zdd <09>ZdS) rRcCs||_||_dS)N)rArS)r6rArSr8r8r9r:<00>szParsedResult.__init__NcCst<00>|<02>}|<03>|j|<01>}|S)N)rZTreeInterpreter<65>visitrS)r6rK<00>optionsZ interpreter<65>resultr8r8r9<00>search<63>s
zParsedResult.searchcCst<00><01>}|<01>|j<03>}|S)afRender the parsed AST as a dot file.
Note that this is marked as an internal method because
the AST is an implementation detail and is subject
to change. This method can be used to help troubleshoot
or for development purposes, but is not considered part
of the public supported API. Use at your own risk.
)rZGraphvizVisitorr<72>rS)r6Zrenderer<65>contentsr8r8r9<00>_render_dot_files
 zParsedResult._render_dot_filecCs
t|j<01>S)N)<02>reprrS)r6r8r8r9<00>__repr__szParsedResult.__repr__)N)r<>r<>r<>r:r<>r<>r<>r8r8r8r9rR<00>s
rR) <0C>__doc__r<5F>ZjmespathrZjmespath.compatrrrr<00>objectrrRr8r8r8r9<00><module>s     S