
]c           @  sh  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z d  d l
 j Z d  d l Z g  a d  d l m Z d e f d     YZ d e f d     YZ d   Z e j d	 e j  Z d
   Z d   Z d   Z d a e d e d  Z d   Z e  d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& g  Z! d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: g Z" d; d< d= d> d? g Z# d0 j$ g  e" D] Z% e j& e%  ^ qe#  Z' d@ Z( dA Z) dB e f dC     YZ* dD e f dE     YZ+ e e dF  Z, dG   Z- dH   Z. dI   Z/ dJ   Z0 dK   Z1 dL   Z2 dM e f dN     YZ3 e3   Z4 dO   Z5 e5 d  dP    Z6 e5 d$  dQ    Z7 e5 dR  dS    Z8 e5 d  dT    Z9 e5 d   dU    Z: e5 d  dV    Z; e5 d  dW    Z< e5 d!  dX    Z= e5 d"  dY    Z> e5 dZ  d[    Z? e5 d  d\    Z@ e5 d#  d]    ZA e5 d  d^    ZB e5 d_  d`    ZC e5 da  db    ZD e5 d&  dc    ZE e5 d  dd    ZF e5 d  de    ZG e5 df  e dg   ZH e5 dh  di    ZI e5 dj  dk    ZJ e5 d  dl    ZK e5 dm  dn    ZL do   ZM dp   ZN eO e jP jQ dq dr   ZR e5 ds  dt    ZS e5 du  dv    ZT dw   ZU e5 dx  dy    ZV e5 dz  d{    ZW e e d|  ZX d}   ZY e5 d  d~    ZZ d   Z[ d   Z\ e d d  Z] d   Z^ d   Z_ d S(   i(   t   print_functionN(   t   match_logical_wordt
   ParseErrorc           B  s#   e  Z d d e d   Z d   Z RS(   c         C  s  d t  |  | | f } | rt | t  r@ d j |  } n  | j d  } t |  d k r d  }	 d }
 x |
 t | d  k  r| d |
 } | d k r |
 d 7}
 nK | |	 k r d  }	 n6 |	 r n- | d k s | d k s | d	 k r | }	 n  |
 d 7}
 qp W|	 r | d
 |	 7} q n  xy | D]n } | d | 7} | d  k	 r| t |  k rx| d d | d 7} d  } q| t |  8} n  | r'Pq'q'Wn  | |  _ t j	 |  |  d  S(   Nu   File "%s", line %d: %st    s   
i   i    s   \t   `s   't   "s:   
(Perhaps you left out a %s at the end of the first line.)s   
    t    t   ^(
   t   unicode_filenamet
   isinstancet   listt   joint   splitt   lent   Nonet   messaget	   Exceptiont   __init__(   t   selft   filenamet   numbert   msgt   linet   post   firstR   t   linest   open_stringt   it   ct   l(    (    s   renpy/parser.pyR   .   s@    	$			c         C  s   |  j  S(   N(   R   (   R   (    (    s   renpy/parser.pyt   __unicode__]   s    N(   t   __name__t
   __module__R   t   FalseR   R   (    (    (    s   renpy/parser.pyR   ,   s   /t   LineNumberHolderc           B  s   e  Z d  Z d   Z RS(   s)   
    Holds the expected line number.
    c         C  s   d |  _  d  S(   Ni    (   R   (   R   (    (    s   renpy/parser.pyR   h   s    (   R   R    t   __doc__R   (    (    (    s   renpy/parser.pyR"   c   s   c         C  sV   t  |  t  r |  Sy |  j d  SWn n Xy |  j d  SWn n X|  j d  S(   s4   
    Converts the supplied filename to unicode.
    t   mbcss   utf-8s   latin-1(   R	   t   unicodet   decode(   t   fn(    (    s   renpy/parser.pyR   l   s    s   __(\w+)|\w+| +|.c         C  sd   t  j j |   } t  j j |  d } | j d d  } d   } t j d | |  } d | d S(   Ni    R   t   _c         S  s   t  t |  j d    S(   Ni    (   t   hext   ordt   group(   t   m(    (    s   renpy/parser.pyt
   munge_char   s    s   [^a-zA-Z0-9_]t   _m1_t   __(   t   ost   patht   basenamet   splitextt   replacet   ret   sub(   R'   t   rvR-   (    (    s   renpy/parser.pyt   munge_filename   s    	c         C  s   |  } t  j j |   }  t  j j t j j  } t  j j t j j  } |  j |  rv t  j j |  |  j	 d d  S|  j |  r t  j j |  |  j	 d d  S| j	 d d  Sd S(   sy   
    Returns a version of fn that is either relative to the base directory,
    or relative to the Ren'Py directory.
    s   \t   /N(
   R0   R1   t   abspatht   renpyt   configt   basedirt
   renpy_baset
   startswitht   relpathR4   (   R'   t   ofnR=   R>   (    (    s   renpy/parser.pyt   elide_filename   s    c         C  sf   t  j j t j j |   } t  j j |  r1 | St  j j t j j |   } t  j j |  rb | S|  S(   N(   R0   R1   R   R;   R<   R=   t   existsR>   (   R'   t   fn1t   fn2(    (    s   renpy/parser.pyt   unelide_filename   s    R   i   c           sn    f d   } |  a  | r$ | } n. t |  d  } | j   j d  } | j   t |   }  t |     | d 7} g  } | } d }	 t |  r | d d k r |	 d 7}	 n  | s t j	 j
   j r t j j }
 n i  }
 t |  } t j j j |   xE|	 | k  rB| } g  } d } |  | f } t j j t  | |	  |
 | <d } x|	 | k  r>|	 } | |	 } | d k rt |  | d	   n  | d
 k r| rd j |  } t j d |  s| j |  | | f  n  | d k r|	 } n  | d |
 | _ x" | | d d k r!| d 8} q W| |
 | _ | |
 | j |
 | j !|
 | _ | |
 | j |
 | j !|
 | _ |	 d 7}	 | d 7} d } g  } Pn  | d
 k r| d 7} d } n  | d k r|	 d 7}	 qMn  | d k r| |	 d d
 k r|	 d 7}	 | d 7} | j d  qMn  | d k r2| d 7} n  | d k rQ| rQ| d 8} n  | d k r|	 } x | |	 d
 k r|	 d 7}	 qfWqMn  | d k r| } | j |  |	 d 7}	 t } t } |	 | d k  r | |	 | k r | |	 d | k r | j |  | j |  |	 d 7}	 t } n  g  } xD|	 | k  rl| |	 } | d
 k rX| d 7} n  | d k rt|	 d 7}	 q)n  | rt } |	 d 7}	 | j |  q)n  | | k r:| s|	 d 7}	 | j |  Pn  |	 | d k  r:| |	 d | k r:| |	 d | k r:|	 d 7}	 | j |  | j |  | j |  Pq:n  | d k rOt } n  | j |  |	 d 7}	 q)q)Wd j |  } d | k rt j d | |  } n  | j |  qMn  t | |	  \ } } } | r| d } d | k r  | } qn  | j |  | }	 |	 | d k rMt |  | d d | d t  qMqMWq W| rjt |  | d d | d t  n  | S(    s  
    Reads `filename`, and divides it into logical lines.

    Returns a list of (filename, line number, line text) triples.

    If `filedata` is given, it should be a unicode string giving the file
    contents. In that case, `filename` need not exist.
    c           si   |  j  d  } t |  d @d k r2 |  j  d  Sd |  j  d  k rT |  j  d  S|   |  j  d  S(   Ni   i    R/   i   (   R+   R   (   R,   t   brackets(   t   prefix(    s   renpy/parser.pyt   munge_string   s    t   rbs   utf-8s   

i    u   ﻿i   u   	s1   Tab characters are not allowed in Ren'Py scripts.u   
R   u   ^\s*$u    u   u   \i   u   \
u   ([{u   }])u   #u   "'`i   s   [__s   (\.|\[+)__(\w+)u   __i   s:   Overly long logical line. (Check strings and parenthesis.)R   R   sB   is not terminated with a newline. (Check strings and parenthesis.)N(    t   original_filenamet   opent   readR&   t   closeRB   R8   R   R;   t   gamet   contextt
   init_phaset
   scripteditR   t   filest   addt   LineR   R   R   R5   t   matcht   appendt	   end_delimt   endt   startt   textt	   full_textR!   t   TrueR6   R   (   R   t   filedatat
   linenumbert	   add_linesRI   t   datat   fR7   R   R   R   t   len_datat   start_numberR   t
   parendeptht   loct   endpost   startposR   t   delimt   escapet   triplequotet   st   wordt   magicRY   t   rest(    (   RH   s   renpy/parser.pyt   list_logical_lines   s    
	


	""


	
 


4
	



8
	

)!c           s/   d         f d     d d  d S(   sE  
    This takes as input the list of logical line triples output from
    list_logical_lines, and breaks the lines into blocks. Each block
    is represented as a list of (filename, line number, line text,
    block) triples, where block is a block list (which may be empty if
    no block is associated with this line.)
    c         S  sR   d } d } x5 t  rC |  | d k r? | d 7} | d 7} q n  Pq W| |  | f S(   Ni    R   i   (   R]   (   R   t   deptht   index(    (    s   renpy/parser.pyt   depth_split  s    	

c   
        s   g  } d  } x |  t   k  r  |  \ } } }   |  \ } } | | k  rV Pn  | d  k rk | } n  | | k r t | | d   n  |  d 7}   |  | d  \ }	 }  | j | | | |	 f  q W| |  f S(   Ns   indentation mismatch.i   (   R   R   R   RW   (
   R   t	   min_depthR7   Rq   R   R   R[   t
   line_depthRo   t   block(   Rs   t   gll_coreR   (    s   renpy/parser.pyRw     s    	
i    (    (   R   (    (   Rs   Rw   R   s   renpy/parser.pyt   group_logical_lines  s    
	t   $t   ast   att   behindt   callt
   expressiont   hidet   ift   int   imaget   initt   jumpt   menut   onlayert   pythont   returnt   scenet   showt   witht   whilet   zordert	   transforms   <>s   <<s   <=t   <s   >>s   >=t   >s   !=s   ==t   |R   t   &t   +t   -s   **t   *s   //R9   t   %t   ~s   \bor\bs   \band\bs   \bnot\bs   \bin\bs   \bis\bu"   [a-zA-Z_ -�][0-9a-zA-Z_ -�]*u'   [-0-9a-zA-Z_ -�][-0-9a-zA-Z_ -�]*t   SubParsec           B  s    e  Z d  Z d   Z d   Z RS(   ss   
    This represents the information about a subparse that can be provided to
    a creator-defined statement.
    c         C  s   | |  _  d  S(   N(   Rv   (   R   Rv   (    (    s   renpy/parser.pyR   0  s    c         C  s5   |  j  s d Sd j |  j  d j |  j  d j  Sd  S(   Ns   <SubParse empty>s   <SubParse {}:{}>i    (   Rv   t   formatR   R_   (   R   (    (    s   renpy/parser.pyt   __repr__3  s    	(   R   R    R#   R   R   (    (    (    s   renpy/parser.pyR   *  s   	t   Lexerc           B  s  e  Z d  Z e d d0 d d0 d  Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z e j d
    Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z  d   Z! d   Z" d   Z# e$ d   Z% e$ d!  Z& d"   Z' e e$ d#  Z( d$   Z) d%   Z* d&   Z+ d'   Z, d(   Z- d0 d)  Z. d*   Z/ d+   Z0 d,   Z1 d-   Z2 d.   Z3 e d/  Z4 RS(1   s   
    The lexer that is used to lex script files. This works on the idea
    that we want to lex each line in a block individually, and use
    sub-lexers to lex sub-blocks.
    i    s   

c         C  s   | |  _  | |  _ | |  _ t |  _ d |  _ d |  _ d |  _ d |  _ g  |  _	 | |  _
 d |  _ d |  _ d |  _ d |  _ | |  _ | |  _ d  S(   NiR   i    (   R   t   init_offsetRv   R!   t   eobR   R   R[   R   t   subblockt   global_labelR   t   word_cache_post   word_cache_newpost
   word_cachet   monologue_delimitert	   subparses(   R   Rv   R   R   R   R   R   (    (    s   renpy/parser.pyR   B  s     															c         C  sr   |  j  d 7_  |  j  t |  j  k r4 t |  _ t S|  j |  j  \ |  _ |  _ |  _ |  _	 d |  _
 d |  _ t S(   s'  
        Advances this lexer to the next line in the block. The lexer
        starts off before the first line, so advance must be called
        before any matching can be done. Returns True if we've
        successfully advanced to a line in the block, or False if we
        have advanced beyond all lines in the block. In general, once
        this method has returned False, the lexer is in an undefined
        state, and it doesn't make sense to call any method other than
        advance (which will always return False) on the lexer.
        i   i    i(   R   R   Rv   R]   R   R!   R   R   R[   R   R   R   (   R   (    (    s   renpy/parser.pyt   advance^  s    	(		c         C  s_   |  j  d 8_  t |  _ |  j |  j  \ |  _ |  _ |  _ |  _ t |  j  |  _	 d |  _
 d S(   s   
        Puts the parsing point at the end of the previous line. This is used
        after renpy_statement to prevent the advance that Ren'Py statements
        do.
        i   iN(   R   R!   R   Rv   R   R   R[   R   R   R   R   (   R   (    (    s   renpy/parser.pyt	   unadvancev  s
    	(c         C  sv   |  j  r d S|  j t |  j  k r) d St j | t j  j |  j |  j  } | sZ d S| j	   |  _ | j
 d  S(   s  
        Tries to match the given regexp at the current location on the
        current line. If it succeds, it returns the matched text (if
        any), and updates the current position to be after the
        match. Otherwise, returns None and the position is unchanged.
        i    N(   R   R   R   R   R[   R5   t   compilet   DOTALLRV   RY   R+   (   R   t   regexpR,   (    (    s   renpy/parser.pyt   match_regexp  s    	'c         C  s   |  j  d  d S(   sQ   
        Advances the current position beyond any contiguous whitespace.
        u   (\s+|\\\n)+N(   R   (   R   (    (    s   renpy/parser.pyt   skip_whitespace  s    c         C  s   |  j    |  j |  S(   s   
        Matches something at the current position, skipping past
        whitespace. Even if we can't match, the current position is
        still skipped past the leading whitespace.
        (   R   R   (   R   R   (    (    s   renpy/parser.pyRV     s    
c         C  s,   |  j  } |  j   | k r | S| |  _  d S(   s   
        Matches a keyword at the current position. A keyword is a word
        that is surrounded by things that aren't words, like
        whitespace. (This prevents a keyword from matching a prefix.)
        R   (   R   Rm   (   R   Rm   t   oldpos(    (    s   renpy/parser.pyt   keyword  s
    		c         c  s3   y	 d VWn# t  k
 r. } t j | j  n Xd S(   sm   
        Catches errors, then causes the line to advance if it hasn't been
        advanced already.
        N(   R   t   parse_errorsRW   R   (   R   t   e(    (    s   renpy/parser.pyt   catch_error  s    	c         C  s(   t  |  j |  j | |  j |  j   d S(   sc   
        Convenience function for reporting a parse error at the current
        location.
        N(   R   R   R   R[   R   (   R   R   (    (    s   renpy/parser.pyt   error  s    c         C  s    |  j    |  j t |  j  k S(   s   
        Returns True if, after skipping whitespace, the current
        position is at the end of the end of the current line, or
        False otherwise.
        (   R   R   R   R[   (   R   (    (    s   renpy/parser.pyt   eol  s    
c         C  s    |  j    s |  j d  n  d S(   sG   
        If we are not at the end of the line, raise an error.
        s   end of line expected.N(   R   R   (   R   (    (    s   renpy/parser.pyt
   expect_eol  s    c         C  s7   |  j  r3 |  j   } | j   | j d |  n  d S(   sz   
        Called to indicate this statement does not expect a block.
        If a block is found, raises an error.
        so   Line is indented, but the preceding %s statement does not expect a block. Please check this line's indentation.N(   R   t   subblock_lexerR   R   (   R   t   stmtt   ll(    (    s   renpy/parser.pyt   expect_noblock  s    	
c         C  s!   |  j  s |  j d |  n  d S(   sk   
        Called to indicate that the statement requires that a non-empty
        block is present.
        s   %s expects a non-empty block.N(   R   R   (   R   R   (    (    s   renpy/parser.pyt   expect_block  s    	c         C  s   t  |  j  S(   sL   
        Called to check if the current line has a non-empty block.
        (   t   boolR   (   R   (    (    s   renpy/parser.pyt	   has_block  s    c         C  sF   |  j  p | } t |  j d | d |  j d |  j d |  j d |  j S(   sk   
        Returns a new lexer object, equiped to parse the block
        associated with this line.
        R   R   R   R   R   (   R   R   R   R   R   R   R   (   R   R   (    (    s   renpy/parser.pyR     s    c         C  s   |  j  d  } | d k r- |  j  d  } n  | d k rK |  j  d  } n  | d k r[ d S| d d k r~ t } | d } n t } | d d !} d   } | s t j d	 d
 |  } t j d | |  } n  | S(   s'  
        Lexes a string, and returns the string to the user, or None if
        no string could be found. This also takes care of expanding
        escapes and collapsing whitespace.

        Be a little careful, as this can return an empty string, which is
        different than None.
        s   r?"([^\\"]|\\.)*"s   r?'([^\\']|\\.)*'s   r?`([^\\`]|\\.)*`i    t   ri   ic         S  s   |  j  d  } | d k r d S| d k r/ d S| d k r? d S| d k rO d	 S| d
 d k r |  j  d  } | r t t |  j  d  d   Sn | Sd  S(   Ni   t   {s   {{t   [s   [[R   s   %%t   ns   
i    t   ui   i   (   R+   t   unichrt   int(   R,   R   t   group2(    (    s   renpy/parser.pyt   dequote#  s    s   \s+R   s   \\(u([0-9a-fA-F]{1,4})|.)N(   RV   R   R]   R!   R5   R6   (   R   Rl   t   rawR   (    (    s   renpy/parser.pyt   string  s"    
	c         C  s/  |  j  d  } | d k r- |  j  d  } n  | d k rK |  j  d  } n  | d k r[ d S| d d k r~ t } | d } n t } | d d !} d	   } | s+t j d
 d |  } g  } xi | j |  j  D]U } | j   } | s q n  t j d d |  } t j d | |  } | j	 |  q W| S| S(   s   
        Lexes a triple quoted string, intended for use with monologue mode.
        This is about the same as the double-quoted strings, except that
        runs of whitespace with multiple newlines are turned into a single
        newline.
        s   r?"""([^\\"]|\\.)*"""s   r?'''([^\\']|\\.)*'''s   r?```([^\\`]|\\.)*```i    R   i   i   ic         S  s   |  j  d  } | d k r d S| d k r/ d S| d k r? d S| d k rO d	 S| d
 d k r |  j  d  } | r t t |  j  d  d   Sn | Sd  S(   Ni   R   s   {{R   s   [[R   s   %%R   s   
i    R   i   i   (   R+   R   R   (   R,   R   R   (    (    s   renpy/parser.pyR   Z  s    s    *\n *s   
s   \s+R   s   \\(u([0-9a-fA-F]{1,4})|.)N(
   RV   R   R]   R!   R5   R6   R   R   t   stripRW   (   R   Rl   R   R   R7   (    (    s   renpy/parser.pyt   triple_string>  s2    	c         C  s   |  j  d  S(   sf   
        Tries to parse an integer. Returns a string containing the
        integer, or None.
        s   (\+|\-)?\d+(   RV   (   R   (    (    s   renpy/parser.pyt   integer  s    c         C  s   |  j  d  S(   sk   
        Tries to parse a number (float). Returns a string containing the
        number, or None.
        s(   (\+|\-)?(\d+\.?\d*|\.\d+)([eE][-+]?\d+)?(   RV   (   R   (    (    s   renpy/parser.pyt   float  s    c         C  s   |  j  d  S(   sG   
        Matches the characters in an md5 hash, and then some.
        s   \w+(   RV   (   R   (    (    s   renpy/parser.pyt   hash  s    c         C  sY   |  j  |  j k r% |  j |  _  |  j S|  j  |  _ |  j t  } | |  _ |  j  |  _ | S(   s?   
        Parses a name, which may be a keyword or not.
        (   R   R   R   R   RV   t   word_regexp(   R   R7   (    (    s   renpy/parser.pyRm     s    	c         C  sz   |  j  } |  j   } | d k s- | d k r] |  j |  j  |  j  d !d k r] | |  _  d Sn  | t k rv | |  _  d S| S(	   sG   
        This tries to parse a name. Returns the name or None.
        R   R   i   R   t   'R   (   R   R   R   N(   R   Rm   R[   R   t   KEYWORDS(   R   R   R7   (    (    s   renpy/parser.pyt   name  s    	 		c         C  s3   | r/ | d d k r/ | j  d  d |  _ n  d S(   s   
        Set current global_label, which is used for label_name calculations.
        label can be any valid label or None, but this has only effect if label
        has global part.
        i    t   .N(   R   R   (   R   t   label(    (    s   renpy/parser.pyt   set_global_label  s    c         C  s   |  j  } d } |  j   } | ss |  j d  s; |  j rH | |  _  d S|  j } |  j   } | s | |  _  d SnS |  j d  r | r | |  j k r | |  _  d S|  j   } | s | |  _  d Sn  | s | S| d | S(   s  
        Try to parse label name. Returns name in form of "global.local" if local
        is present, "global" otherwise; or None if it doesn't parse.

        If declare is True, allow only such names that are valid for declaration
        (e.g. forbid global name mismatch)
        s   \.R   N(   R   R   R   RV   R   (   R   t   declaret   old_post
   local_namet   global_name(    (    s   renpy/parser.pyt
   label_name  s.    							c         C  s   |  j  d t  S(   s>   
        Same as label_name, but set declare to True.
        R   (   R   R]   (   R   (    (    s   renpy/parser.pyt   label_name_declare  s    c         C  s}   |  j  } |  j t  } | d k s0 | d k r` |  j |  j  |  j  d !d k r` | |  _  d Sn  | t k ry | |  _  d S| S(	   s   
        Matches a word that is a component of an image name. (These are
        strings of numbers, letters, and underscores.)
        R   R   i   R   R   R   (   R   R   R   N(   R   RV   t   image_word_regexpR[   R   R   (   R   R   R7   (    (    s   renpy/parser.pyt   image_name_component  s    	 		c         C  s7  |  j    r t S|  j |  j } | d k r |  j d 7_ |  j t |  j  k rf |  j d 8_ t S|  j |  j } | d k r |  j d 8_ t Sn | d k r t S| } xs t r#|  j d 7_ |  j    r |  j d  n  |  j |  j } | | k rPn  | d k r |  j d 7_ q q W|  j d 7_ t S(	   s   
        This tries to match a python string at the current
        location. If it matches, it returns True, and the current
        position is updated to the end of the string. Otherwise,
        returns False.
        R   i   R   R   s)   end of line reached while parsing string.s   \(   R   R   (   R   R   (   R   R!   R[   R   R   R]   R   (   R   R   Ri   (    (    s   renpy/parser.pyt   python_string  s4    	c         C  s`   |  j    } | s d SxC |  j d  r[ |  j    } | sJ |  j d  n  | d | 7} q W| S(   sQ  
        This tries to match a dotted name, which is one or more names,
        separated by dots. Returns the dotted name if it can, or None
        if it cannot.

        Once this sees the first name, it commits to parsing a
        dotted_name. It will report an error if it then sees a dot
        without a name behind it.
        s   \.s   expecting name.R   N(   R   R   RV   R   (   R   R7   R   (    (    s   renpy/parser.pyt   dotted_name9  s    c         C  s&   | s
 | St  j j | |  j |  j  S(   N(   R;   t   astt   PyExprR   R   (   R   Rl   t   expr(    (    s   renpy/parser.pyR   R  s    c         C  s   |  j  } x |  j   s |  j |  j  } | | k rQ |  j |  j | |  j  !|  S| d k rm |  j   q n  |  j   r q n  |  j  d 7_  q W|  j d |  d S(   s#  
        This matches python code up to, but not including, the non-whitespace
        delimiter characters. Returns a string containing the matched code,
        which may be empty if the first thing is the delimiter. Raises an
        error if EOL is reached before the delimiter.
        s   '"i   s(   reached end of line when expecting '%s'.N(   R   R   R[   R   R   t   parenthesised_pythonR   (   R   Ri   R   RZ   R   (    (    s   renpy/parser.pyt   delimited_pythonX  s    	
c         C  sD   |  j  d t  } | s( |  j d  n  |  j | j   |  } | S(   sk   
        Returns a python expression, which is arbitrary python code
        extending to a colon.
        t   :s   expected python_expression(   R   R!   R   R   R   (   R   R   t   peR7   (    (    s   renpy/parser.pyt   python_expressiont  s
    c         C  s   |  j  |  j } | d k rN |  j d 7_ |  j d t  |  j d 7_ t S| d k r |  j d 7_ |  j d t  |  j d 7_ t S| d k r |  j d 7_ |  j d t  |  j d 7_ t St S(   s   
        Tries to match a parenthesised python expression. If it can,
        returns true and updates the current position to be after the
        closing parenthesis. Returns False otherwise.
        t   (i   t   )R   t   ]R   t   }(   R[   R   R   R!   R]   (   R   R   (    (    s   renpy/parser.pyR     s"    c         C  sW  |  j  } xt rx |  j t  r' q W|  j   r8 Pn  |  j   pe |  j   pe |  j   pe |  j   sl Pn  xn t r |  j	   |  j   r Pn  |  j d  r |  j
   } | so |  j d  qo qo n  |  j   r qo n  Pqo W| r |  j t  r q n  | r|  j d  rq n  Pq W|  j | |  j  !j   } | s;d St j j | |  j |  j  S(   so   
        Tries to parse a simple_expression. Returns the text if it can, or
        None if it cannot.
        s   \.s   expecting name after dot.t   ,N(   R   R]   RV   t   operator_regexpR   R   R   R   R   R   Rm   R   R[   R   R   R;   R   R   R   R   (   R   t   commat   operatorRZ   R   R[   (    (    s   renpy/parser.pyt   simple_expression  s@    			
c         C  s   |  j  d t  S(   st   
        One or more simple expressions, separated by commas, including an
        optional trailing comma.
        R   (   R   R]   (   R   (    (    s   renpy/parser.pyt   comma_expression  s    c         C  s   |  j  d t  S(   s=   
        Parses the name portion of a say statement.
        R   (   R   R!   (   R   (    (    s   renpy/parser.pyt   say_expression  s    c         C  s(   |  j  |  j |  j |  j |  j |  j f S(   s   
        Returns an opaque representation of the lexer state. This can be
        passed to revert to back the lexer up.
        (   R   R   R   R[   R   R   (   R   (    (    s   renpy/parser.pyt
   checkpoint  s    c         C  sd   | \ |  _  |  _ |  _ |  _ |  _ |  _ d |  _ |  j  t |  j  k  rW t	 |  _
 n	 t |  _
 d S(   s   
        Reverts the lexer to the given state. State must have been returned
        by a previous checkpoint operation on this lexer.
        iN(   R   R   R   R[   R   R   R   R   Rv   R!   R   R]   (   R   t   state(    (    s   renpy/parser.pyt   revert  s
    *	c         C  s   |  j  |  j f S(   s   
        Returns a (filename, line number) tuple representing the current
        physical location of the start of the current logical line.
        (   R   R   (   R   (    (    s   renpy/parser.pyt   get_location   s    c         C  sl   t  | t  r- | p | } |  j |  } n | p< | j j } |   } | d k rh |  j d |  n  | S(   s   
        Tries to parse thing, and reports an error if it cannot be done.

        If thing is a string, tries to parse it using
        self.match(thing). Otherwise, thing must be a method on this lexer
        object, which is called directly.
        s   expected '%s' not found.N(   R	   t
   basestringRV   t   im_funct	   func_nameR   R   (   R   t   thingR   R7   (    (    s   renpy/parser.pyt   require  s    		c         C  sN   |  j    |  j } t |  j  |  _ t j j |  j | j   |  j |  j	  S(   s   
        Skips whitespace, then returns the rest of the current
        line, and advances the current position to the end of
        the current line.
        (
   R   R   R   R[   R;   R   R   R   R   R   (   R   R   (    (    s   renpy/parser.pyRo     s    
	c         C  s,   |  j  } t |  j  |  _  |  j | j   S(   sG   
        Like rest, but returns a string rather than a PyExpr.
        (   R   R   R[   R   (   R   R   (    (    s   renpy/parser.pyt   rest_statement*  s    	c           sM   g   t      |  j   _     f d     |  j d  d j   S(   s   
        Returns the subblock of this code, and subblocks of that
        subblock, as indented python code. This tries to insert
        whitespace to ensure line numbers match up.
        c           s   x |  D] \ } } } } x3   j  | k  rN  j | d    j  d 7_  q W| | d }  j |    j  | j d  7_   | | d  q Wd  S(   Ns   
i   s       (   R   RW   t   count(   Rv   t   indentt   _fnt   lnR[   R   t   linetext(   t   ot   processR7   (    s   renpy/parser.pyR   ?  s    R   (   R"   R   R   R   R   (   R   (    (   R   R   R7   s   renpy/parser.pyt   python_block3  s    	c         C  s
   t  |   S(   so   
        Returns an Argument object if there is a list of arguments, or None
        there is not one.
        (   t   parse_arguments(   R   (    (    s   renpy/parser.pyt	   argumentsQ  s    c         C  so   |  j  d k r t d   n  t |   } |  j   t | t  sO | g } n  t |  } |  j  j |  | S(   s   
        Parses the remainder of the current line as a statement in the
        Ren'Py script language. Returns a SubParse corresponding to the
        AST node generated by that statement.
        sH   A renpy_statement can only be parsed inside a creator-defined statement.N(	   R   R   R   t   parse_statementR   R	   R
   R   RW   (   R   Rv   t   sp(    (    s   renpy/parser.pyt   renpy_statementY  s    
c         C  s  |  j  d  k r t d   n  |  j d k  r: |  j   n  g  } xy |  j s y< t |   } t | t  rz | j	 |  n | j
 |  WqC t k
 r } t j
 | j  |  j   qC XqC W| s | r | j
 t j |  j     q |  j d  n  t |  } |  j  j
 |  | S(   NsD   A renpy_block can only be parsed inside a creator-defined statement.i    s*   At least one Ren'Py statement is expected.(   R   R   R   R   R   R   R  R	   R
   t   extendRW   R   R   R   R   t   PassR   R   R   (   R   t   emptyRv   R   R   R  (    (    s   renpy/parser.pyt   renpy_blockn  s*    N(5   R   R    R#   R!   R   R   R   R   R   R   RV   R   t
   contextlibt   contextmanagerR   R   R   R   R   R   R   R   R   R   R   R   R   Rm   R   R   R   R   R   R   R   R   R]   R   R   R   R   R   R   R   R   R   R   Ro   R   R   R  R  R	  (    (    (    s   renpy/parser.pyR   ;  s\   						
			
					
	9	E							(			1			=											c   	      C  s;  |  j    g } |  j |  j  g } xP t rv | j |  j     |  j   } | s` | j   Pn  | j | j    q' W| r | j |  j     |  j   } | d k	 r | j t	 |   q | j   n  | r1x] t
 | |  D]I \ } } | r | d d k r |  j |  |  j   |  j d  q q Wn  t |  S(   so   
    This parses an image name, and returns it as a tuple. It requires
    that the image name be present.
    i    R   s/   image name components may not begin with a '-'.N(   R   R   R   R]   RW   t   popR   R   R   R%   t   zipR   R   R   t   tuple(	   R   R   t   nodasht   pointsR7   R   Rl   R   t   p(    (    s   renpy/parser.pyt   parse_image_name  s,    	

c         C  s\   |  j  |  j  g } x@ t rW |  j d  s1 Pn  |  j   } | sG Pn  | j |  q W| S(   s   
    This parses a comma-separated list of simple_expressions, and
    returns a list of strings. It requires at least one
    simple_expression be present.
    R   (   R   R   R]   RV   RW   (   R   R7   R   (    (    s   renpy/parser.pyt   parse_simple_expression_list  s    	c   	      C  s  d } d } g  } d } g  } |  j d  s< |  j d  r` |  j |  j  } | j   f } n t |  t  } d } xit r|  j d  r | r |  j d  qx |  j |  j  } qx n  |  j d  r | r |  j d  qx t	 |   } qx n  |  j d  r/| r|  j d  qx |  j |  j  } qx n  |  j d	  rr| d k	 rZ|  j d
  qx |  j |  j  } qx n  |  j d  r| r|  j d  n  x< t r|  j |  j  } | j
 |  |  j d  sPqqWqx n  Pqx W| | | | | | | f S(   s)   
    This parses an image specifier.
    R~   R   R   s(   multiple onlayer clauses are prohibited.R{   s#   multiple at clauses are prohibited.Rz   s#   multiple as clauses are prohibited.R   s'   multiple zorder clauses are prohibited.R|   s'   multiple behind clauses are prohibited.R   N(   R   R   R   R   R   R  R]   R   R   R  RW   RV   (	   R   t   tagt   layert   at_listR   R|   R~   t
   image_namet   bhtag(    (    s   renpy/parser.pyt   parse_image_specifier  sT    		c         C  sY   |  j    } |  j d  s | S|  j |  j  } t j | d |  | t j | |  g S(   s   
    Tries to parse the with clause associated with this statement. If
    one exists, then the node is wrapped in a list with the
    appropriate pair of With nodes. Otherwise, just returns the
    statement by itself.
    R   R   (   R   R   R   R   R   t   With(   R   t   nodeRf   R   (    (    s   renpy/parser.pyt
   parse_with  s    c      	   C  sY  |  j    } t } t } t } d  } d  } d  }	 d  }
 g  } g  } x`| j   r| j d  r | j | j  } | j   | j d  qE n  | j d  r | j | j  } | j   | j d  qE n  | j	   } | j   } | j
   } | d  k	 rd| d  k	 rd| j   | j d  | r6| j d  n  | rL| j d  n  t } | }	 | }
 qE n  | j |  | j
   } | d  k r| j d  n  | j   r| j r| j d	  n  | r| r| j d
  n  | rt } n  | j | d d  f  | j d   qE n  t } d } | j t |   | j d  rU| j | j  } n  | j d  | j   | j d  t | j     } | j | | | f  qE W| s|  j d  n  g  } | r| j t j | |	 |
 d  d t  n  | j t j | | | | | p| | |   x5 t |  D]' \ } } | rHd | _ q*d | _ q*W| S(   NR   s   with clauset   sets   set menuitems   say menuitems:   Say menuitems and captions may not exist in the same menu.s)   Only one say menuitem may exist per menu.s   expected menuitemsl   Line is followed by a block, despite not being a menu choice. Did you forget a colon at the end of the line?s:   Captions and say menuitems may not exist in the same menu.R]   R   R   s   choice menuitems"   Menu does not contain any choices.t   interactt   normalt   force(   R   R!   R   R   R   R   R   R   R   R   R   R   R]   R   R   R   RW   R  R   R   t   parse_blockR   t   Sayt   Menut	   enumeratet   rollback(   t   stmtlRf   R  R   t
   has_choicet   has_sayt   has_captiont   with_R  t   say_whot   say_whatt   itemst   item_argumentsR   t   whot   whatR   t	   conditionRv   R7   Rr   R   (    (    s   renpy/parser.pyt
   parse_menu/  s    


		
(.c   	      C  s  g  } g  } d  } d  } t } t   } |  j d  s: d  Sxt r|  j d  rV Pn  |  j d  r | d  k	 r |  j d  n  |  j |  j  } | | k r |  j d |  n  | j |  n|  j d  r9| s |  j d  n  t } |  j   } | d  k	 r| | k r&|  j d |  n  | j |  qn |  j |  j  } | | k rk|  j d |  n  | j |  |  j d  r|  j	   |  j
 d	  } n d  } | j | | f  | r| j |  n  |  j d  rPn  |  j d
  q= Wt j j | | | |  S(   Ns   \(s   \)s   \*\*s&   a label may have only one ** parameters   parameter %s appears twice.s   \*s%   a label may have only one * parametert   =s   ),R   (   R   R]   R  RV   R   R   R   RT   R!   R   R   RW   R;   R   t   ParameterInfo(	   R   t
   parameterst
   positionalt   extrapost   extrakwt   add_positionalt   namesR   t   default(    (    s   renpy/parser.pyt   parse_parameters  sT    		
c         C  s^  g  } d
 } d
 } |  j d  s% d
 Sx t rG|  j d  rA Pn  |  j d  r~ | d
 k	 rl |  j d  n  |  j d  } n |  j d  r | d
 k	 r |  j d  n  |  j d  } ni |  j   } |  j   } | o |  j d  s |  j |  d
 } n  |  j   | j	 | |  j d  f  |  j d  r7Pn  |  j
 d	  q( Wt j j | | |  S(   s7   
    Parse a list of arguments, if one is present.
    s   \(s   \)s   \*\*s$   a call may have only one ** arguments   ),s   \*s#   a call may have only one * argumentR3  R   N(   R   RV   R]   R   R   R   R   R   R   RW   R   R;   R   t   ArgumentInfo(   R   R  R8  R7  R   R   (    (    s   renpy/parser.pyR    s6    		
t	   ParseTriec           B  s)   e  Z d  Z d   Z d   Z d   Z RS(   sI   
    This is a trie of words, that's used to pick a parser function.
    c         C  s   d  |  _ i  |  _ d  S(   N(   R   R;  t   words(   R   (    (    s   renpy/parser.pyR   +  s    	c         C  sd   | s | |  _  d  S| d } | d } | |  j k rI t   |  j | <n  |  j | j | |  d  S(   Ni    i   (   R;  R?  R>  RT   (   R   R   t   functionR   Ro   (    (    s   renpy/parser.pyRT   /  s    	

c         C  sW   | j  } | j   p! | j d  } | |  j k rC | | _  |  j S|  j | j |  S(   Ns   \$(   R   Rm   RV   R?  R;  t   parse(   R   R   R   Rm   (    (    s   renpy/parser.pyRA  =  s    		(   R   R    R#   R   RT   RA  (    (    (    s   renpy/parser.pyR>  &  s   		c           s     j        f d   } | S(   s   
    A function decorator used to declare a statement. Keywords is a string
    giving the keywords that precede the statement.
    c           s   t  j   |   |  S(   N(   t
   statementsRT   (   Rb   (   t   keywords(    s   renpy/parser.pyt   wrapU  s    (   R   (   RC  RD  (    (   RC  s   renpy/parser.pyt	   statementM  s    c         C  s[  g  } |  j  |  j  } |  j  d  |  j   |  j d  t |  j    } | j | | f  |  j   xx |  j d  r |  j  |  j  } |  j  d  |  j   |  j d  t |  j    } | j | | f  |  j   qn W|  j d  rK|  j  d  |  j   |  j d  t |  j    } | j d | f  |  j   n  t	 j
 | |  S(   NR   s   if statementt   elifs   elif clauset   elses   else clauseR]   (   R   R   R   R   R!  R   RW   R   R   R   t   If(   R   Rf   t   entriesR1  Rv   (    (    s   renpy/parser.pyt   if_statement_  s0    



c         C  se   |  j  |  j  } |  j  d  |  j   |  j d  t |  j    } |  j   t j | | |  S(   NR   s   while statement(	   R   R   R   R   R!  R   R   R   t   While(   R   Rf   R1  Rv   (    (    s   renpy/parser.pyt   while_statement  s    

t   passc         C  s.   |  j  d  |  j   |  j   t j |  S(   Ns   pass statement(   R   R   R   R   R  (   R   Rf   (    (    s   renpy/parser.pyt   pass_statement  s    

c         C  s   |  j  d  |  j   } |  j |  t |   } |  j d  |  j   t |  | |  } |  j   g  } | r | j t	 j
 | | g  d    n  | j |  | S(   Ns   menu statementR   (   R   R   R   R  R   R   R2  R   RW   R   t   LabelR   R  (   R   Rf   R   R  R   R7   (    (    s   renpy/parser.pyt   menu_statement  s    

"c         C  sL   |  j  d  |  j   } | s( d  } n  |  j   |  j   t j | |  S(   Ns   return statement(   R   Ro   R   R   R   R   t   Return(   R   Rf   Ro   (    (    s   renpy/parser.pyt   return_statement  s    	

c         C  sv   |  j  d  |  j d  r7 t } |  j |  j  } n t } |  j |  j  } |  j   |  j   t	 j
 | | |  S(   Ns   jump statementR~   (   R   R   R]   R   R   R!   R   R   R   R   t   Jump(   R   Rf   R~   t   target(    (    s   renpy/parser.pyt   jump_statement  s    

c         C  sd  |  j  d  |  j d  r7 t } |  j |  j  } n t } |  j |  j  } |  j d  t |   } t j	 | | | |  g } |  j d  r |  j |  j
  } | j t j | | g  d    np t j j r6| t j j k r6| rt j j d t t j j | j  q6t j j | t t j j | j  n  | j t j |   |  j   |  j   | S(   Ns   call statmentR~   RM  t   from(   R   R   R]   R   R   R!   R   R  R   t   CallR   RW   RO  R   R;   RR   R   t   add_fromt   report_missingRK   RY   R  R   R   (   R   Rf   R~   RT  R  R7   R   (    (    s   renpy/parser.pyt   call_statement  s(    "&&

c         C  s   |  j  d  r$ |  j |  j  } n d } |  j   rS |  j   t j | d  |  St |   } t j | | | d  } t	 |  |  } |  j
 d  r t j j |  j    | _ n |  j d  |  j   |  j   | S(   NR   t   masteri   R   s   scene statement(   R   R   R   R   R   R   t   SceneR   R  R  RV   R;   t   atlt	   parse_atlR   R   R   (   R   Rf   R  t   imspecR   R7   (    (    s   renpy/parser.pyt   scene_statement  s    


c         C  s   t  |   } t j | |  } t |  |  } |  j d  rZ t j j |  j    | _ n |  j	 d  |  j
   |  j   | S(   NR   s   show statement(   R  R   t   ShowR  RV   R;   R]  R^  R   R   R   R   (   R   Rf   R_  R   R7   (    (    s   renpy/parser.pyt   show_statement  s    

s
   show layerc         C  s   |  j  |  j  } |  j d  r0 t |   } n g  } |  j d  r` t j j |  j    } n d  } |  j
 d  |  j   |  j   t j | | | |  } | S(   NR{   R   s   show layer statement(   R   R   R   R  RV   R;   R]  R^  R   R   R   R   R   R   t	   ShowLayer(   R   Rf   R  R  R]  R7   (    (    s   renpy/parser.pyt   show_layer_statement)  s    

c         C  sL   t  |   } t |  t j | |   } |  j   |  j d  |  j   | S(   Ns   hide statement(   R  R  R   t   HideR   R   R   (   R   Rf   R_  R7   (    (    s   renpy/parser.pyt   hide_statementA  s    

c         C  sC   |  j  |  j  } |  j   |  j d  |  j   t j | |  S(   Ns   with statement(   R   R   R   R   R   R   R  (   R   Rf   R   (    (    s   renpy/parser.pyt   with_statementM  s
    

c         C  s   t  |  d t } |  j d  rL |  j   d  } t j j |  j    } nB |  j	 d  |  j
   } | s{ |  j d  n  d  } |  j d  t j | | | |  } |  j s t j | | g d |  j  } n  |  j   | S(   NR  R   R3  s   expected expressions   image statementi  (   R  R]   RV   R   R   R;   R]  R^  R   R   Ro   R   R   R   t   ImageR   t   InitR   R   (   R   Rf   R   R   R]  R7   (    (    s   renpy/parser.pyt   image_statementW  s     
	"
t   definec         C  s  |  j    } | r! t |  } n d } d } |  j |  j  } x3 |  j d  rt | d | } |  j |  j  } qB W|  j d  |  j   } | s |  j d  n  |  j d  t j	 | | | |  } |  j
 s t j | | g | |  j  } n  |  j   | S(   Ni    t   stores   \.R   R3  s   expected expressions   define statement(   R   R   R   Rm   RV   Ro   R   R   R   t   DefineR   Ri  R   R   (   R   Rf   t   priorityRl  R   R   R7   (    (    s   renpy/parser.pyt   define_statementt  s&    	"
R;  c         C  s  |  j    } | r! t |  } n d } d } |  j |  j  } x3 |  j d  rt | d | } |  j |  j  } qB W|  j d  |  j   } | s |  j d  n  |  j d  t j	 | | | |  } |  j
 s t j | | g | |  j  } n  |  j   | S(   Ni    Rl  s   \.R   R3  s   expected expressions   default statement(   R   R   R   Rm   RV   Ro   R   R   R   t   DefaultR   Ri  R   R   (   R   Rf   Rn  Rl  R   R   R7   (    (    s   renpy/parser.pyt   default_statement  s&    	"
c         C  s   |  j    } | r! t |  } n d } |  j |  j  } t |   } | rm | j s] | j rm |  j d  n  |  j d  |  j   t	 j
 j |  j    } t j | | | |  } |  j s t j | | g | |  j  } n  |  j   | S(   Ni    sA   transform statement does not take a variable number of parametersR   (   R   R   R   R   R<  R8  R7  R   R   R;   R]  R^  R   R   t	   TransformR   Ri  R   R   (   R   Rf   Rn  R   R5  R]  R7   (    (    s   renpy/parser.pyt   transform_statement  s     
	"
c         C  sO   |  j    } | s" |  j d  n  |  j d  |  j   t j | | d d S(   Ns   expected python codes   one-line python statementRl  (   R   R   R   R   R   t   Python(   R   Rf   t   python_code(    (    s   renpy/parser.pyt   one_line_python  s    
c         C  s   t  } t  } d } |  j d  r* t } n  |  j d  rB t } n  |  j d  rj d |  j |  j  } n  |  j d  |  j   |  j d  |  j   } |  j   | r t	 j
 | | | d | St	 j | | | d | Sd  S(   NRl  t   earlyR   R   s   store.R   s   python block(   R!   R   R]   R   R   R   R   R   R   R   t   EarlyPythonRt  (   R   Rf   R   Rw  Rl  Ru  (    (    s   renpy/parser.pyt   python_statement  s"    		

R   c         C  s   |  j  |  j  } |  j |  t |   } |  j d  rC t } n t } |  j  d  |  j   t |  j	 |   } |  j
   t j | | | | d | S(   NR   R   (   R   R   R   R<  R   R]   R!   R   R!  R   R   R   RO  (   R   Rf   R   R   R5  R   Rv   (    (    s   renpy/parser.pyt   label_statement	  s    	

s   init offsetc         C  sS   |  j  d  |  j  |  j  } |  j   |  j d  |  j   t |  |  _ g  S(   NR3  s   init offset statement(   R   R   R   R   R   R   R   (   R   Rf   t   offset(    (    s   renpy/parser.pyt   init_offset_statement	  s    

s
   init labelc         C  s   t  |  | d t S(   NR   (   Rz  R]   (   R   Rf   (    (    s   renpy/parser.pyt   init_label_statement&	  s    c         C  s   |  j    } | r! t |  } n d } |  j d  ro |  j   |  j d  t |  j t   } |  j   n2 z% |  j	 } t |  _	 t
 |   g } Wd  | |  _	 Xt j | | | |  j  S(   Ni    R   s   init statement(   R   R   RV   R   R   R!  R   R]   R   R   R  R   Ri  R   (   R   Rf   R  Rn  Rv   t   old_init(    (    s   renpy/parser.pyt   init_statement+	  s    
		
s   rpy monologuec         C  sh   |  j  d  r d |  _ n( |  j  d  r6 d |  _ n |  j d  |  j   |  j d  |  j   g  S(   Nt   doubles   

t   singles   
s.   rpy monologue expects either single or double.s   rpy monologue(   R   R   R   R   R   R   (   R   Rf   (    (    s   renpy/parser.pyt   rpy_statementL	  s    

c         C  sg   t  j j |   } |  j   | s& g  St j | |  } |  j sc t j | | g d |  j  } n  | S(   Ni(	   R;   t
   screenlangt   parse_screenR   R   t   ScreenR   Ri  R   (   R   Rf   t   screenR7   (    (    s   renpy/parser.pyt   screen1_statement]	  s    
	"c         C  sc   t  j j j |  |  } |  j   t j | |  } |  j s_ t j | | g d |  j	  } n  | S(   Ni(
   R;   t   sl2t   slparserR  R   R   R  R   Ri  R   (   R   Rf   R  R7   (    (    s   renpy/parser.pyt   screen2_statementp	  s    
	"t   RENPY_SCREEN_LANGUAGEt   2R  c         C  sp   t  } |  j   } | d  k	 r- t |  } n  | d k rF t |  |  S| d k r_ t |  |  S|  j d  d  S(   Ni   i   s   Bad screen language version.(   t   default_screen_languageR   R   R   R  R  R   (   R   Rf   t   screen_languaget   slver(    (    s   renpy/parser.pyt   screen_statement	  s    t   testcasec         C  s   |  j  |  j  } |  j  d  |  j   |  j d  t j j j |  j   |  } |  j	   t
 j | | |  } |  j s t
 j | | g d |  j  } n  | S(   NR   s   testcase statementi  (   R   R   R   R   R;   t   testt
   testparserR!  R   R   R   t   TestcaseR   Ri  R   (   R   Rf   R   R  R7   (    (    s   renpy/parser.pyt   testcase_statement	  s    

	"c   	        s  | j  d  | j   | j d  | j     g  } d  } d  }   f d   } x(  j   r{  j d  r | d  k	 r   j d  n    j   } y |   j	    } Wqx  j d  qxXqT   j d  rk| d  k r   j d  n    j   } y |   j	    } Wn   j d  n X| j
 t j j | | | | |   d  } d  } d  } d  } qT   j d	  qT W| r  j d
  n  | j   | j r| St j |  | | j  S(   NR   s   translate strings statementc           s_   |  j    }  y5 t |  d d t j j d  } t | t j j  SWn     j d  n Xd  S(   Ns   <string>t   evali   s   could not parse string(	   R   R   R;   R   t   new_compile_flagsR  Rl  t   __dict__R   (   Rl   t   bc(   R   (    s   renpy/parser.pyt   parse_string	  s    t   olds(   previous string is missing a translations   Could not parse string.t   news   no string to translates   unknown statements%   final string is missing a translation(   R   R   R   R   R   R   R   R   R   Ro   RW   R;   R   t   TranslateStringR   Ri  R   (	   t   init_loct   languageR   Rv   R  Rf   R  t   newlocR  (    (   R   s   renpy/parser.pyt   translate_strings	  sJ    

%	
	t	   translatec         C  sn  |  j  |  j  } | d k r' d  } n  |  j  |  j  } | d k rU t | | |   S| d k r z> |  j } t |  _ t |  |  g } t j	 | | |  g SWd  | |  _ XnZ | d k r	z> |  j } t |  _ t
 |  |  g } t j | | |  g SWd  | |  _ Xn  |  j  d  |  j   |  j d  t |  j    } |  j   t j | | | |  t j |  g S(   NR   t   stringsR   t   styleR   s   translate statement(   R   R   R   R   R  R   R]   Ry  R   t   TranslateEarlyBlockt   style_statementt   TranslateBlockR   R   R!  R   R   t	   Translatet   EndTranslate(   R   Rf   R  t
   identifierR~  Rv   (    (    s   renpy/parser.pyt   translate_statement	  s4    					

R  c           s   |  j  |  j  } d    t j | |      f d   } x | |   rN q? W|  j d  sx |  j d  |  j   nS |  j d  |  j   |  j	   } x- | j
   r x | |  r q W| j   q W|  j s t j |  g |  j   n  |  j
    S(   Nc           s  |  j  d  rD   d  k	 r+ |  j d  n  |  j |  j   _ t S|  j  d  r` t  _ t S|  j  d  r  j d  k	 r |  j d  n  |  j |  j	   _ t S|  j  d  r|  j |  j	  } | t
 j j k r |  j d |  n   j j |  t S|  j  d  rI j d  k	 r0|  j d	  n  |  j |  j   _ t S|  j	   } | d  k	 r| d
 k r| t
 j j k r|  j d |  n  |  j k r|  j d |  n  |  j |  j   j | <t St S(   Nt   iss   parent clause appears twice.t   cleart   takes   take clause appears twice.t   dels   style property %s is not known.t   variants   variant clause appears twice.t
   propertiess    style property %s appears twice.(   R   R   R   R   Rm   t   parentR]   R  R  R   R;   R  t   prefixed_all_propertiest   delattrRW   R  R   R  R!   (   R   t   propname(   R  R7   (    s   renpy/parser.pyt   parse_clause$
  sB    	R   s   style statement(   R   Rm   R   R   t   StyleRV   R   R   R   R   R   R   Ri  R   (   R   Rf   R   R  R   (    (   R  R7   s   renpy/parser.pyR  
  s(    4
	
c         C  s  | d  k r d  St } d  } d  } x t r |  j d  rC t } q% |  j d  r | d  k	 rn |  j d  n  |  j |  j  } q% t |   }	 |	 d  k r Pn  | d  k	 r |  j d  n  |	 } q% Wt | t	  rZg  }
 xy | D]q } | d k r|
 j
 t j | d g  d i  f   q |
 j
 t j | | | | d	 | d
 | d | d |  q W|
 St j | | | | d	 | d
 | d | d | Sd  S(   Nt
   nointeractR   s&   say can only take a single with clauses+   say can only take a single set of argumentss   {clear}s	   nvl cleart   nvlR  t
   attributesR  R  t   temporary_attributes(   R  s   clear(   R   R]   R   R!   R   R   R   R  R	   R
   RW   R   t   UserStatementR"  (   R   Rf   R/  R0  R  R  R  R*  R  t   argsR7   R   (    (    s   renpy/parser.pyt
   finish_says
  s4    		
(;c         C  s}   g  } xU t  r] |  j d  } | s- d } n  |  j   } | d k rI Pn  | j | |  q	 W| rs t |  } n d } | S(   sH   
    Returns a list of say attributes, or None if there aren't any.
    R   R   N(   R]   RV   R   R   RW   R  (   R   R  RH   t	   component(    (    s   renpy/parser.pyt   say_attributes
  s    		c         C  s6  |  j    } |  j   p! |  j   } t |  | d  |  } | d  k	 rl |  j   rl |  j d  |  j   | S|  j |  |  j	   } t
 |   } |  j d  r t
 |   } n d  } |  j   p |  j   } | d  k	 r%| d  k	 r%t |  | | | | |  } |  j   |  j d  |  j   | S|  j d  d  S(   Ns   say statements   \@s   expected statement.(   R   R   R   R  R   R   R   R   R   R   R  RV   R   R   (   R   Rf   R   R0  R7   R/  R  R  (    (    s   renpy/parser.pyt   say_statement
  s*    


c         C  sD   |  j    } t j |   } | d k r7 |  j d  n  | |  |  S(   sR  
    This parses a Ren'Py statement. l is expected to be a Ren'Py lexer
    that has been advanced to a logical line. This function will
    advance l beyond the last logical line making up the current
    statement, and will return an AST object representing this
    statement, or a list of AST objects representing this statement.
    s   expected statement.N(   R   RB  RA  R   R   (   R   Rf   t   pf(    (    s   renpy/parser.pyR  
  s
    
c         C  s   |  j    g  } xy |  j s y< t |   } t | t  rJ | j |  n | j |  Wq t k
 r } t j | j	  |  j    q Xq W| S(   s   
    This parses a block of Ren'Py statements. It returns a list of the
    statements contained within the block. l is a new Lexer object, for
    this block.
    (
   R   R   R  R	   R
   R  RW   R   R   R   (   R   R7   R   R   (    (    s   renpy/parser.pyR!    s    
c         C  s   d |  d t  j _ y" t |  | |  } t |  } Wn$ t k
 r\ } t j | j  d SXt
 |  } t |  } t r d S| r | j t j | d j | d j f d   n  | S(   sK  
    Parses a Ren'Py script contained within the file `fn`.

    Returns a list of AST objects representing the statements that were found
    at the top level of the file.

    If `filedata` is given, it should be a unicode string giving the file
    contents.

    If `linenumber` is given, the parse starts at `linenumber`.
    s   While parsing R   iN(   R;   RO   t   exception_infoRp   Rx   R   R   RW   R   R   R   R!  R   RQ  R   R_   (   R'   R^   R_   R   t   nestedR   R   R7   (    (    s   renpy/parser.pyRA    s    0c          C  s   t  }  g  a  |  S(   N(   R   (   R7   (    (    s   renpy/parser.pyt   get_parse_errors@  s    c          C  s  t  s
 t Sd }  t j j d d  \ } } | j t j  t d d | t d d | t d |  x{ t  D]s } |  | 7}  |  d 7}  y | j	 d  } Wn n Xt d |  t | d | y t   t |  Wqo qo Xqo Wt d |  t d	 t j
 d | t t j   d | | j   t j j j |  |  y8 t j j j d
 k rvt j j | g d d d n  Wn n Xt S(   NR   s
   errors.txtt   wsF   I'm sorry, but errors were detected in your script. Please correct thet   files#   errors listed below, and try again.s   

s   utf-8s   Ren'Py Version:t   runi   t	   transient(   R   R!   R;   R   t   open_error_filet   writet   codecst   BOM_UTF8t   printt   encodet   versiont   timet   ctimeRN   t   displayt   report_parse_errorsRO   R  t   commandt   exportst   launch_editorR]   (   R\   Rb   t   error_fnR   (    (    s   renpy/parser.pyR  G  sB    


#(`   t
   __future__R    R  R5   R0   R  R
  t   renpy.displayR;   t
   renpy.testt	   renpy.astR   t	   renpy.sl2R   t   renpy.parsersupportR   R   R   t   objectR"   R   R   t   St   lllwordR8   RB   RF   RK   R   R!   Rp   Rx   R  R   t	   OPERATORSt   ESCAPED_OPERATORSR   R   Rj   R   R   R   R   R   R  R  R  R  R2  R<  R  R>  RB  RE  RJ  RL  RN  RP  RR  RU  RZ  R`  Rb  Rd  Rf  Rg  Rj  Ro  Rq  Rs  Rv  Ry  Rz  R|  R}  R  R  R  R  R   t   environt   getR  R  R  R  R  R  R  R  R  R  R!  RA  R  R  (    (    (    s   renpy/parser.pyt   <module>   s   7						G		/   Z)		I		w	K	5$		+	&
""	!			D-Z0	1		#	