ó
â¡ý\c           @  s›   d  d l  m Z d  d l Z i  Z e j j ƒ  Z d d d d d d e e e d d d d d e d d e	 d d „ Z
 d „  Z d „  Z d „  Z d „  Z d S(	   iÿÿÿÿ(   t   print_functionNi    c           s$  t  ˆ j ƒ  ƒ ‰ | r! t } n  t d ˆ d | d | d |
 d | d | d | d | d	 | d
 ˆ d | ro d n d d ˆ d ˆ d | d | ƒ t ˆ <ˆ  t t d d g k rÄ t d j ˆ  ƒ ƒ ‚ n  ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ f	 d †  } t j	 j
 j ˆ | ƒ ‡ f d †  } t j ˆ | ƒ d S(   s}  
    :doc: statement_register
    :name: renpy.register_statement

    This registers a user-defined statement.

    `name`
        This is either a space-separated list of names that begin the statement, or the
        empty string to define a new default statement (the default statement will
        replace the say statement).

    `block`
        When this is False, the statement does not expect a block. When True, it
        expects a block, but leaves it up to the lexer to parse that block. If the
        string "script", the block is interpreted as containing one or more
        Ren'Py script language statements. If the string "possible", the
        block expect condition is determined by the parse function.

    `parse`
        This is a function that takes a Lexer object. This function should parse the
        statement, and return an object. This object is passed as an argument to all the
        other functions.

    `lint`
        This is called to check the statement. It is passed a single argument, the
        object returned from parse. It should call renpy.error to report errors.

    `execute`
        This is a function that is called when the statement executes. It is passed a
        single argument, the object returned from parse.

    `execute_init`
        This is a function that is called at init time, at priority 0.

    `predict`
        This is a function that is called to predict the images used by the statement.
        It is passed a single argument, the object returned from parse. It should return
        a list of displayables used by the statement.

    `next`
        This is a function that is called to determine the next statement.

        If `block` is not "script", this is passed a single argument, the object
        returned from the parse function. If `block` is "script", an additional
        argument is passed, an object that names the first statement in the block.

        The function should return either a string giving a label to jump to,
        the second argument to transfer control into the block, or None to
        continue to the statement after this one.

    `label`
        This is a function that is called to determine the label of this
        statement. If it returns a string, that string is used as the statement
        label, which can be called and jumped to like any other label.

    `warp`
        This is a function that is called to determine if this statement
        should execute during warping. If the function exists and returns
        true, it's run during warp, otherwise the statement is not run
        during warp.

    `scry`
        Used internally by Ren'Py.

    `init`
        True if this statement should be run at init-time. (If the statement
        is not already inside an init block, it's automatically placed inside
        an init block.) This calls the execute function, in addition to the
        execute_init function.

    `init_priority`
        An integer that determines the priority of initialization of the
        init block.

    `translation_strings`
        A function that is called with the parsed block. It's expected to
        return a list of strings, which are then reported as being available
        to be translated.

    `force_begin_rollback`
        This should be set to true on statements that are likely to cause the
        end of a fast skip, similar to ``menu`` or ``call screen``.

    `post_execute`
        A function that is executed as part the next statement after this
        one. (Adding a post_execute function changes the contents of the RPYC
        file, meaning a Force Compile is necessary.)

    `post_label`
        This is a function that is called to determine the label of this
        the post execute statement. If it returns a string, that string is used
        as the statement label, which can be called and jumped to like any other
        label. This can be used to create a unique return point.

    `predict_all`
        If True, then this predicts all sub-parses of this statement and
        the statement after this statement.

    `predict_next`
        This is called with a single argument, the label of the statement
        that would run after this statement.

        This should be called to predict the statements that can run after
        this one. It's expected to return a list of of labels or SubParse
        objects. This is not called if `predict_all` is true.
    t   parset   lintt   executet   execute_initt   predictt   nextt   scryt   labelt   warpt   translation_stringst   rollbackt   forcet   normalt   post_executet
   post_labelt   predict_allt   predict_nextt   scriptt   possibles"   Unknown "block" argument value: {}c   
        sâ  zSt  j j |  j ƒ |  j } g  |  _ |  j } |  j } d  } ˆ  t k ri |  j	 d j
 ˆ ƒ d ƒ nj ˆ  t k r’ |  j d j
 ˆ ƒ d ƒ nA ˆ  d k rÓ |  j d j
 ˆ ƒ d ƒ t  j j |  j ƒ  ƒ } n  |  j } ˆ ˆ |  ƒ f } |  j | k r
|  j ƒ  n  t  j j | | | | ƒ } ˆ | _ t ˆ ƒ | _ | | _ |  j | _ Wd  | |  _ t  j j ƒ  Xˆ d  k	 s…ˆ d  k	 r©t  j j | | ƒ }	 | |	 g } n  ˆ rÞ|  j rÞt  j j | | g ˆ |  j ƒ } n  | S(   Nt    s
    statementR   (   t   renpyt   exportst   push_error_handlert   errort	   subparsest   textt   subblockt   Nonet   Falset   expect_noblockt   joint   Truet   expect_blockt   parsert   parse_blockt   subblock_lexert   linet   advancet   astt   UserStatementt   translatablet   boolt   translation_relevantt
   code_blockt   pop_error_handlert   PostUserStatementt   initt   Initt   init_offset(
   t   lt   loct   old_subparsesR   R   R,   t
   start_linet   parsedt   rvt   post(	   t   blockR/   t   init_priorityt   nameR   R   R   R)   R
   (    s   renpy/statements.pyt   parse_user_statementÀ   s>    								%c           s   ˆ  t  ˆ  d |  ƒ f S(   NR   (   t   registry(   R2   (   R;   (    s   renpy/statements.pyt
   parse_dataò   s    N(   t   tuplet   splitR    t   dictR=   R   t	   Exceptiont   formatR   R"   t
   statementst   addt   parsers(   R;   R   R   R   R   R   R   R9   R/   R)   R   R:   R   R	   R
   t   force_begin_rollbackR   R   R   R   R<   R>   (    (	   R9   R/   R:   R;   R   R   R   R)   R
   s   renpy/statements.pyt   register#   s2    	'/c         C  s˜   |  j  |  j | | f g } t j j | ƒ } | j ƒ  t j j | j ƒ z9 t	 j
 | ƒ } | d k rx | j d ƒ n  | | ƒ SWd t j j ƒ  Xd S(   sQ   
    This is used for runtime parsing of CDSes that were created before 7.3.
    s1   Could not find user-defined statement at runtime.N(   t   filenamet
   linenumberR   R"   t   LexerR&   R   R   R   RF   R   R   R-   (   t   nodeR%   R   R9   R2   t   pf(    (    s   renpy/statements.pyR   ø   s    
c         O  s?   | \ } } t  | j |  ƒ }  |  d  k r/ d  S|  | | | Ž S(   N(   R=   t   getR   (   t   methodR6   t   argst   kwargsR;   (    (    s   renpy/statements.pyt   call  s
    c         C  s    | \ } } t  | j |  d  ƒ S(   N(   R=   RN   R   (   t   keyR6   R;   (    (    s   renpy/statements.pyRN     s    c         C  s   |  \ } } d j  | ƒ S(   NR   (   R   (   R6   R;   t   _parsed(    (    s   renpy/statements.pyt   get_name  s    (   t
   __future__R    R   R=   R"   t	   ParseTrieRF   R   R   R    RH   R   RR   RN   RU   (    (    (    s   renpy/statements.pyt   <module>   s4   Á		
	