
    ?dq                     ~    d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ej                  Zd	dZd Zy)
aF  Simple Python Parser

Parse Python code into a list of logical lines, represented by LogicalLine
objects. This uses Python's tokenizer to generate the tokens. As such, YAPF must
be run with the appropriate Python version---Python 2.7 for Python2 code, Python
3.x for Python3 code, etc.

This parser uses Python's native "tokenizer" module to generate a list of tokens
for the source code. It then uses Python's native "ast" module to assign
subtypes, calculate split penalties, etc.

A "logical line" produced by Python's "tokenizer" module ends with a
tokenize.NEWLINE, rather than a tokenize.NL, making it easy to separate them
out. Comments all end with a tokentizer.NL, so we need to make sure we don't
errantly pick up non-comment tokens when parsing comment blocks.

  ParseCode(): parse the code producing a list of logical lines.
    N)split_penalty_visitor)format_token)logical_line)	py3compatc                    | j                  t        j                        s| t        j                  z  } 	 t        j                  | |      }t        j
                  |       t        j                  |       j                  }t        j                  |      }t        |      }t        j                  |      j                  |       |S # t        $ r  w xY w)ac  Parse a string of Python code into logical lines.

  This provides an alternative entry point to YAPF.

  Arguments:
    unformatted_source: (unicode) The code to format.
    filename: (unicode) The name of the file being reformatted.

  Returns:
    A list of LogicalLines.

  Raises:
    An exception is raised if there's an error during AST parsing.
  )endswithoslinesepastparsefix_missing_locationsr   StringIOreadlinetokenizegenerate_tokens	Exception_CreateLogicalLinesr   SplitPenaltyvisit)unformatted_sourcefilenameast_treer   tokenslogical_liness         8/usr/lib/python3/dist-packages/yapf/pyparser/pyparser.py	ParseCoder   0   s     
	$	$RZZ	0"**$
yy+X6Hh'!!"45>>H%%h/F &f-- $$]399(C	 
 
	
s   AC Cc           	         g }d}| D ]  }t        j                  | }|r|j                  j                         j	                  d      r|j
                  d   |j
                  d   k  rt        j                  t        d|j
                  d   |j
                  d   dz   f|j                  d   |j                  d   dz   f|j                        }|j
                  d   |_        |j
                  d   |_	        d|_
        |j                  t        j                  |d             |j
                  d   |_        |j
                  d   |_	        |j                  |_
        |j                  t        j                  |t        j                   |j"                                  |} g g }}d}|D ]C  }|j"                  t$        j&                  k(  r n#|j"                  t$        j(                  k(  r(|j                  t+        j,                  ||             g }i|j"                  t$        j.                  k(  r|dz  }|j"                  t$        j0                  k(  r|dz  }|j"                  t$        j2                  k(  r|rd|j"                  t$        j4                  k(  sG|d   j"                  t$        j4                  k(  r'|j                  t+        j,                  ||             g }|j                  |       F |D ]  }|j6                  }	|	j9                         r|	gng }
|j:                  dd D ]d  }|	|_        ||	_        |}	|j9                         r|
j                  |       5|jA                         sF||
d   _!        |
jE                         |_!        f  |S )	zSeparate tokens into logical lines.

  Arguments:
    tokens: (list of tokenizer.TokenInfo) Tokens generated by tokenizer.

  Returns:
    A list of LogicalLines.
  N\r         )typestringstartendlineCONTINUATION)#r   	TokenInfor%   rstripr   r#   r&   r$   linenocolumnvalueappendr   FormatTokenr"   tokentok_namer!   r   	ENDMARKERNEWLINEr   LogicalLineINDENTDEDENTNLCOMMENTfirst
OpensScoper   previous_token
next_tokenClosesScopematching_bracketpop)r   formatted_tokensprev_toktokctokr   cur_logical_linedepthr%   previousbracket_stacks              r   r   r   R   s     ( c


s
#CX]]))+44T:qCIIaL(  "HNN1$5$9:||AQ! 34}}d JJqMdkJJqMdkdjl66t^LM1CJ1CJ

CI  ennSXX&>?AH+0 %'!-
% #c
xx8%%%
xx8###<33E;KLM	X__	$qje	X__	$qje	X[[	 

388x/?/?#?
1

"
"h&6&6
6 	\55e=MNOc"-#2  3dzzH"*"5"5"7XJRM{{12 
3#chh 
	S!??-0b*,002
33 
    )z	<unknown>)__doc__r   r	   r/   r   yapf.pyparserr   yapf.yapflibr   r   r   N_TOKENSr&   r   r    rG   r   <module>rM      s9   *  	   / % % "~~DOrG   