ó
�™xTc           @   sŒ   d  d l  m Z d  d l m Z d  d l m Z d  d l Z d „  Z e d e d „ Z
 d „  Z d „  Z d	 „  Z e d
 k rˆ e ƒ  n  d S(   iÿÿÿÿ(   t   division(   t   simple_parser(   t	   tokenizerNc          C   sƒ  d d g g d d d d g g d d d d g g d d d d d g g d	 d d d d
 d d g g d d d d d d
 d g g d d d d d d
 d g g d d d d d
 d d g g g }  d t  j d k } x² |  D]ª \ } } t j d | ƒ } | rý | GHn  g  t j | ƒ D] \ } } | ^ q} | rIg  | D] } | j ^ q2GHn  g  | D] } | j ^ qP| k sqt ‚ | rÑ HqÑ qÑ Wd  S(   Nt   as   a and bt   bt   ands   a or bt   ors
   not a or bt   nots   not a or b and ct   cs   not (a or b) and cs   (not (a or b) and c)s   not ((a or b) and c)s	   --verbosei   t   input_string(   t   syst   argvR   t   word_iteratorR   t   infix_as_postfixt   valuet   AssertionError(   t   testst   verboseR	   t   expected_resultt   infixt   wordR   t   postfix(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/regression/tst_simple_parser.pyt   exercise_basic   s8    	 % ( c      	   C   sø  g  } x¦t  j d |  d | d | d | ƒ D]€\ } }  | j d k rf | j ƒ  } | j d | ƒ q+ | j d k rÐ | j ƒ  } | j ƒ  } | j d k r¶ | j d	 | | f ƒ q«| j d
 | | f ƒ q+ | j d k rt|  j ƒ  j d k sú t ‚ t |  j ƒ  j ƒ }	 |  j ƒ  j d k s*t ‚ t d |  d t ƒ }
 |
 d k rZt	 d ƒ ‚ n  | j d |	 |
 f ƒ q+ | j d k r|  j ƒ  j d k sžt ‚ t d |  d d ƒ }
 |
 d k rÎt	 d ƒ ‚ n  t |  j ƒ  j ƒ }	 |  j ƒ  j d k sþt ‚ | j d |	 |
 f ƒ q+ | j d k r›|  j ƒ  j } |  j ƒ  j d k sQt ‚ t d |  d t ƒ }
 |
 d k r�t	 d ƒ ‚ n  | j d | |
 f ƒ q+ | j | j ƒ q+ Wt
 | ƒ d k rÅd S| d } x" | d D] } d	 | | f } qÚW| S(   NR   t   stop_if_parse_stack_is_emptyt	   stop_wordt&   expect_nonmatching_closing_parenthesisR   s   (!%s)R   R   s   (%s&%s)s   (%s|%s)t   withint   (t   ,t    s   Missing argument.s
   @(%.2f,%s)t   aroundt   )t   fort   ins   (for %s in %s)i    i   (   s   ands   or(   R   R   R   t   popt   appendR   t   floatt   rewrite_parsert   Truet   RuntimeErrort   len(   R   R   R   R   t   result_stackR   t   argt   rhst   lhst   radiust   nested_resultt   vart   resultt   item(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/regression/tst_simple_parser.pyR%   +   sf    	 	 	 
c         C   s   t  j d |  ƒ } t d | ƒ S(   NR	   R   (   R   R   R%   (   R	   R   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/regression/tst_simple_parser.pyt   rewrited   s    c          C   s  d d g d d g d d g d d g d d	 g d
 d g d d	 g d d g d d g d d g d d g d d g d d g d d g g }  d t  j d k } x| |  D]t \ } } | p¹ | d  k } | rÊ | GHn  t d | ƒ } | rç | GHn  | d  k	 r| | k st ‚ n  | rž Hqž qž Wd  S(   NR   s   a and bs   (a&b)s   a and b or cs	   ((a&b)|c)s   a or b and cs	   (a|(b&c))s   within(5, a or b and c)s   @(5.00,(a|(b&c)))s   within(5, (a or b) and c)s   @(5.00,((a|b)&c))s   around(a or b and c, 5)s   around((a or b) and c, 5)s)   around((a or b) and within(3, c or d), 5)s   @(5.00,((a|b)&@(3.00,(c|d))))s
   for i in as   (for i in a)s   for i in not as   (for i in (!a))s   for i in a or bs   ((for i in a)|b)s   for i in (a or b)s   (for i in (a|b))s   for i in (a or b) and cs   ((for i in (a|b))&c)s	   --verbosei   R	   (   R
   R   t   NoneR2   R   (   R   R   R	   R   t   showR0   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/regression/tst_simple_parser.pyt   exercise_nestedh   sP       c           C   s   t  ƒ  t ƒ  d GHd  S(   Nt   OK(   R   R5   (    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/regression/tst_simple_parser.pyt   exerciseŸ   s    t   __main__(   t
   __future__R    t   iotbxR   t   libtbx.philR   R
   R   t   FalseR3   R%   R2   R5   R7   t   __name__(    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/regression/tst_simple_parser.pyt   <module>   s   	'5		7	