��Qc@s�dZdZddgZddlZddlZddlZddlZddlZddlm Z m
Z
mZmZm
Z
defd��YZd deedd
�Zd�Zd�Zed
kr�jee���ndS(sZParser driver.
This provides a high-level interface to parse a file into a syntax tree.
s#Guido van Rossum <[email protected]>tDrivertload_grammari�Ni(tgrammartparsettokenttokenizetpgencBsVeZddd�Zed�Zed�Zed�Zded�Zed�Z RS(cCs:||_|dkr$tj�}n||_||_dS(N(RtNonetloggingt getLoggertloggertconvert(tselfRRR
((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pyt__init__s
cCs=tj|j|j�}|j�d}d}d }}}} }
d}x�D]�}|\}}}} }
|||fkr
||f|ks�t||f|f��|\}
}||
kr�d|
|7}|
}d}n||kr
||
||!7}|}q
n|tjtj fkr`||7}| \}}|j
d�rQ|d7}d}qQqQn|tjkrtj
|}n|r�|jjdtj|||�n|j||||f�r�r�|jjd�nPnd}| \}}|j
d�rQ|d7}d}qQqQWtjd||||f��|jS(
s4Parse a series of tokens and return the syntax tree.iius
s%s %r (prefix=%r)sStop.tsincomplete inputN(RtParserRRtsetupRtAssertionErrorRtCOMMENTtNLtendswithRtOPtopmapR
tdebugttok_nametaddtokent
ParseErrortrootnode(RttokensRtptlinenotcolumnttypetvaluetstarttendt line_texttprefixt quintuplets_linenots_column((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pytparse_tokens&sT
*
cCs"tj|j�}|j||�S(s*Parse a stream and return the syntax tree.(Rtgenerate_tokenstreadlineR)(RtstreamRR((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pytparse_stream_rawVscCs|j||�S(s*Parse a stream and return the syntax tree.(R-(RR,R((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pytparse_stream[scCs;tj|d|�}z|j||�SWd|j�XdS(s(Parse a file and return the syntax tree.trN(tcodecstopenR.tclose(RtfilenametencodingRR,((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pyt
parse_file_scCs+tjtj|�j�}|j||�S(s*Parse a string and return the syntax tree.(RR*tStringIOR+R)(RttextRR((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pytparse_stringgsN(
t__name__t
__module__RR
tFalseR)R-R.R5R8(((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pyRs0sGrammar.txtc Cs*|dkrtj�}n|dkr~tjj|�\}}|dkrTd}n||djttt j
��d}n|s�t||�r
|jd|�t
j|�}|r&|jd|�y|j|�Wq
tk
r}|jdt|��q
Xq&ntj�}|j|�|S( s'Load the grammar (maybe from a pickle).s.txtRt.s.pickles!Generating grammar tables from %ssWriting grammar tables to %ssWriting failed:N(RRR tostpathtsplitexttjointmaptstrtsystversion_infot_newertinfoRtgenerate_grammartdumptIOErrorRtGrammartload( tgttgptsavetforceR
theadttailtgte((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pyRms& *!
cCsNtjj|�stStjj|�s,tStjj|�tjj|�kS(s0Inquire whether file a was written since file b.(R=R>texistsR;tTruetgetmtime(tatb((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pyRE�s
cGsc|stjd}ntjdtjdtjdd�x$|D]}t|dtdt�q?WtS(s�Main program, when run as a script: produce grammar pickle files.
Calls load_grammar for each argument, a path to a grammar text file.
itlevelR,tformats%(message)sRNRO(RCtargvRtbasicConfigtINFOtstdoutRRU(targsRL((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pytmain�s
t__main__(t__doc__t
__author__t__all__R0R=RR6RCRRRRRRtobjectRRRUR;RRER`R9texittint(((s*/sys/lib/python2.7/lib2to3/pgen2/driver.pyt<module>s(P
|