[- @sdZddlZddlZddlZddlmZddlmZdddgZGdddZ d d d dZ ej d ej j Zd dZddZedkreejdkree qejdZeeZee eeWdQXndS)z8A lexical analyzer class for simple shell-like syntaxes.N)deque)StringIOshlexsplitquotec@seZdZdZdddddZddZddd Zd d Zd d ZddZ ddZ ddddZ ddZ ddZ dS)rz8A lexical analyzer class for simple shell-like syntaxes.NFcCsAt|trt|}n|dk r?||_||_ntj|_d|_||_|rod|_n d|_d|_ d|_ |jr|j d7_ nd|_ d|_ d|_ d|_d |_d |_t|_d |_d |_d|_t|_d|_|jr=td |j|jfndS)N#Z?abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_u|ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞz Fz'"\" rzshlex: reading from %s, line %d) isinstancestrrinstreaminfilesysstdinposixeof commenters wordchars whitespacewhitespace_splitquotesescape escapedquotesstaterpushbacklinenodebugtoken filestacksourceprint)selfrrrr%/usr/lib/python3.4/shlex.py__init__s<                        zshlex.__init__cCs:|jdkr&tdt|n|jj|dS)z:Push a token onto the stack popped by the get_token methodr zshlex: pushing token N)rr#reprr appendleft)r$tokr%r%r& push_token8szshlex.push_tokencCst|trt|}n|jj|j|j|jf||_||_d|_|jr|dk rt d|jfqt d|jfndS)z9Push an input source onto the lexer's input source stack.r Nzshlex: pushing to file %szshlex: pushing to stream %s) r rrr!r)rrrrr#)r$ newstreamnewfiler%r%r& push_source>s"     zshlex.push_sourcecCsa|jj|jj\|_|_|_|jrTtd|j|jfnd|_dS)zPop the input source stack.zshlex: popping to %s, line %dr N) rcloser!popleftrrrr#r)r$r%r%r& pop_sourceLs  ! zshlex.pop_sourcecCs>|jrB|jj}|jdkr>tdt|n|S|j}|jdk rx\||jkr|j|j}|r|\}}|j||n|j }q`Wnx9||j kr|j s|j S|j |j }qW|jdkr:||j kr-tdt|q:tdn|S)zBGet a token from the input stream (or from stack if it's nonempty)r zshlex: popping token Nz shlex: token=zshlex: token=EOF) rr0rr#r( read_tokenr" sourcehookr. get_tokenrr!r1)r$r*rawspecr-r,r%r%r&r4Us.      zshlex.get_tokencCsd}d}x|jjd}|dkr@|jd|_n|jdkrttdt|jdt|n|jdkrd|_Pq|jdkr|sd|_Pq||jkr|jd krtd n|js|j r|rPqqq||j kr.|jj |jd|_q|j rX||j krXd }||_q||j kr|||_d |_q||jkr|j s||_n||_q|jr||_d |_q||_|js|j r|rPqqq|j|jkrd }|s>|jd kr/td ntdn||jkr|j ss|j||_d|_Pqd |_q|j r||j kr|j|jkr|j}||_q|j||_q|j|j krp|s|jd krtdntdn||jkrT||jkrT||krT|j|j|_n|j||_||_q|jd kr|sd|_Pq||jkr|jd krtdnd|_|js|j r|rPqqq||j krK|jj |jd|_|j rd|_|js>|j r|rPqHqqq|j ro||jkro||_q|j r||j krd }||_q||j ks||jks|jr|j||_q|jj||jd krtdnd|_|jrPqqqqW|j}d|_|j rV| rV|dkrVd}n|jdkr|rtdt|qtdn|S)NFr r  zshlex: in statezI see character:rz+shlex: I see whitespace in whitespace stateaTz shlex: I see EOF in quotes statezNo closing quotationz shlex: I see EOF in escape statezNo escaped characterz%shlex: I see whitespace in word statez&shlex: I see punctuation in word statezshlex: raw token=zshlex: raw token=EOF)rreadrrr#r(rr rrrreadlinerrrr ValueErrorrrr))r$ZquotedZ escapedstateZnextcharresultr%r%r&r2us                                         zshlex.read_tokencCs|ddkr#|dd}nt|jtrotjj| rotjjtjj|j|}n|t|dfS)z(Hook called on a filename to be sourced.rr r r) r rrospathisabsjoindirnameopen)r$r-r%r%r&r3s %'zshlex.sourcehookcCs>|dkr|j}n|dkr0|j}nd||fS)zs"