³ò
bì©Ic           @   sè   d  d k  l Z l Z l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ	 e e	 ƒ  ƒ Z
 e e	 ƒ  ƒ Z d „  Z d „  Z d „  Z d „  Z e d j o e ƒ  n d S(   iÿÿÿÿ(   t   AbstractFeedert   AbstractFiltert   AbstractConsumert   SExprReaderc           B   sŒ   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 e e e e e e e	 d „ Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   sa   Usage:
  
  reader = SExprReader(consumer)
  reader.feed("(this is (sexpr))")
  reader.close()
  t   ;s   
s    	
t   (t   )t   "s   \c	   	      C   sz   t  i |  | ƒ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | | | | | | |  _	 |  i
 ƒ  d  S(   N(   R   t   __init__t   comment_begint   comment_endt	   separatort   paren_begint	   paren_endt   quotet   escapet   specialt   reset(	   t   selft   next_filterR	   R
   R   R   R   R   R   (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR      s    							
c         C   s   d | GHd  S(   Ns   Ignore a close parenthesis: %d(    (   R   t   i(    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyt   illegal_close_paren9   s    	c         C   s   d | | f GHd  S(   Ns1   Premature end of file: %d parens left, partial=%s(    (   R   R   t   x(    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyt   premature_eof=   s    c         C   s:   t  |  _ t  |  _ t  |  _ d |  _ d  |  _ g  |  _ |  S(   Nt    (   t   Falset	   incommentt   inquotet   inescapet   symt   Nonet   buildt   build_stack(   R   (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR   B   s    						c         C   s!  xt  | ƒ D]\ } } |  i o | |  i j |  _ q |  i p | |  i j o |  i | 7_ t |  _ q | |  i j o t |  _ q |  i	 o# | |  i
 j o |  i | 7_ q |  i oD |  i d  j o |  i |  i ƒ n |  i i |  i ƒ d |  _ n | |  i j o t |  _ q | |  i
 j o |  i	 |  _	 q | |  i j oS |  i i |  i ƒ g  } |  i d  j o | |  _ q|  i i | ƒ | |  _ q | |  i j oa |  i d  j o |  i | ƒ qt |  i ƒ d j o |  i |  i ƒ n |  i i ƒ  |  _ q q W|  S(   NR   i   (   t	   enumerateR   R
   R   R   R   R   R   t   TrueR   R   R   R   t	   feed_nextt   appendR	   R   R    R   R   t   lent   pop(   R   t   tokensR   t   ct   empty(    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyt   feedM   sD     

c         C   sÄ   |  i  d  j o‰ |  i o  |  i  i |  i ƒ d |  _ n t |  i ƒ d j o |  i  } n |  i d } d  |  _  g  |  _ |  i t |  i ƒ | ƒ n |  i o |  i |  i ƒ n d |  _ |  S(   NR   i   (   R   R   R   R$   R%   R    R   R#   (   R   R   (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyt	   terminate‚   s    
		
	c         C   s   t  i |  ƒ |  i ƒ  d  S(   N(   R   t   closeR+   (   R   (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR,   —   s    
(   t   __name__t
   __module__t   __doc__t   COMMENT_BEGINt   COMMENT_ENDt	   SEPARATORt   PAREN_BEGINt	   PAREN_ENDt   QUOTEt   ESCAPER   R   R   R   R*   R+   R,   (    (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR      s*   				5	t   SExprIllegalClosingParenErrorc           B   s   e  Z d  Z RS(   s4   It throws an exception with an ill-structured input.(   R-   R.   R/   (    (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR7   Ÿ   s   t   SExprPrematureEOFErrorc           B   s   e  Z RS(    (   R-   R.   (    (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR8   ¢   s   t   StrictSExprReaderc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  | ƒ ‚ d  S(   N(   R7   (   R   R   (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR   ¥   s    c         C   s   t  | | ƒ ‚ d  S(   N(   R8   (   R   R   R   (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR   §   s    (   R-   R.   R   R   (    (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR9   ¤   s   	t   _SExprStrConverterc           B   s   e  Z g  Z d  „  Z RS(   c         C   s   t  i i | ƒ d  S(   N(   R:   t   resultsR$   (   R   t   s(    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR*   ¯   s    (   R-   R.   R;   R*   (    (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyR:   ­   s   c         C   s)   g  t  _ t i ƒ  i |  ƒ i ƒ  t  i S(   s   parse a string as a sexpr.(   R:   R;   t   _str_converterR   R*   R+   (   R<   (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyt	   str2sexprµ   s    	c         C   s)   g  t  _ t i ƒ  i |  ƒ i ƒ  t  i S(   s   parse a string as a sexpr.(   R:   R;   t   _str_converter_strictR   R*   R+   (   R<   (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyt   str2sexpr_strictº   s    	c         C   s6   t  |  t ƒ p |  Sn d d i t t |  ƒ ƒ d S(   s.   convert a sexpr into Lisp-like representation.R   t    R   (   t
   isinstancet   listt   joint   mapt	   sexpr2str(   t   e(    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyRF   Ã   s    c           C   sx   t  d ƒ d d d d d g d g  g d g g g g j p t ‚ t  d	 ƒ d
 d d d g g j p t ‚ t  d ƒ d  S(   Ns5   (this ;comment
 is (a test (sentences) (des()) (yo)))t   thist   ist   at   testt	   sentencest   dest   yosu   (paren\(\)theses_in\#symbol "space in 
symbol"
                   this\ way\ also. "escape is \"better than\" quote")s   paren()theses_in#symbols   space in 
symbols   this way also.s   escape is "better than" quotes   (this (is (a (parial (sentence(   R>   t   AssertionError(    (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pyRK   Ë   s    	8 
t   __main__N(   t
   abstfilterR    R   R   R   t
   ValueErrorR7   R8   R9   R:   R=   R?   R>   R@   RF   RK   R-   (    (    (    s@   /afs/athena.mit.edu/user/g/e/geofft/snippets/barn-growl/sexpr.pys   <module>
   s   						