³ò
5ÒÇIc           @   sj   d  d g Z  d d k l Z d d k Td d k Td d k Td e f d „  ƒ  YZ d  e f d „  ƒ  YZ d S(   t   Parsert   ParserErroriÿÿÿÿ(   t   MarkedYAMLError(   t   *c           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR   E   s   c           B   s:  e  Z h  d  d  <d d <Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z e e 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 e d „ Z d „  Z d „  Z  d  „  Z! RS(!   u   !u   tag:yaml.org,2002:u   !!c         C   s=   d  |  _ d  |  _ h  |  _ g  |  _ g  |  _ |  i |  _ d  S(   N(   t   Nonet   current_eventt   yaml_versiont   tag_handlest   statest   markst   parse_stream_startt   state(   t   self(    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyt   __init__S   s    					c         G   s„   |  i  d  j o! |  i o |  i ƒ  |  _  q1 n |  i  d  j	 o? | p t Sn x- | D]! } t |  i  | ƒ o t SqW qW Wn t S(   N(   R   R   R   t   Truet
   isinstancet   False(   R   t   choicest   choice(    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyt   check_event[   s    
 c         C   s8   |  i  d  j o! |  i o |  i ƒ  |  _  q1 n |  i  S(   N(   R   R   R   (   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyt
   peek_eventh   s    
c         C   sG   |  i  d  j o! |  i o |  i ƒ  |  _  q1 n |  i  } d  |  _  | S(   N(   R   R   R   (   R   t   value(    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyt	   get_evento   s    
		c         C   s:   |  i  ƒ  } t | i | i d | i ƒ} |  i |  _ | S(   Nt   encoding(   t	   get_tokent   StreamStartEventt
   start_markt   end_markR   t   parse_implicit_document_startR   (   R   t   tokent   event(    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR   |   s
    c         C   s…   |  i  t t t ƒ pa |  i |  _ |  i ƒ  } | i } } t | | d t	 ƒ} |  i
 i |  i ƒ |  i |  _ | Sn |  i ƒ  Sd  S(   Nt   explicit(   t   check_tokent   DirectiveTokent   DocumentStartTokent   StreamEndTokent   DEFAULT_TAGSR	   t
   peek_tokenR   t   DocumentStartEventR   R
   t   appendt   parse_document_endt   parse_block_nodeR   t   parse_document_start(   R   R   R   R   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR   ˆ   s    
	c      	   C   s!  |  i  t ƒ p¿ |  i ƒ  } | i } |  i ƒ  \ } } |  i  t ƒ p/ t d  d  d |  i ƒ  i |  i ƒ  i ƒ ‚ n |  i	 ƒ  } | i
 } t | | d t d | d | ƒ} |  i i |  i ƒ |  i |  _ nO |  i	 ƒ  } t | i | i
 ƒ } |  i p t ‚ |  i p t ‚ d  |  _ | S(   Ns)   expected '<document start>', but found %rR!   t   versiont   tags(   R"   R%   R'   R   t   process_directivesR$   R   R   t   idR   R   R(   R   R
   R)   R*   t   parse_document_contentR   t   StreamEndEventt   AssertionErrorR   (   R   R   R   R-   R.   R   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR,   œ   s*    				c         C   sw   |  i  ƒ  } | i } } t } x0 |  i t ƒ o |  i ƒ  } | i } t } q" Wt | | d | ƒ} |  i	 |  _
 | S(   NR!   (   R'   R   R   R"   t   DocumentEndTokenR   R   R   t   DocumentEndEventR,   R   (   R   R   R   R   R!   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR*   ·   s    		c         C   sY   |  i  t t t t ƒ o2 |  i |  i ƒ  i ƒ } |  i i	 ƒ  |  _
 | Sn |  i ƒ  Sd  S(   N(   R"   R#   R$   R4   R%   t   process_empty_scalarR'   R   R
   t   popR   R+   (   R   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR1   É   s    	c         C   s˜  d  |  _ h  |  _ x|  i t ƒ oý |  i ƒ  } | i d j ot |  i d  j	 o t d  d  d | i ƒ ‚ n | i	 \ } } | d j o t d  d  d | i ƒ ‚ n | i	 |  _ q | i d j oY | i	 \ } } | |  i j o) t d  d  d | i
 d ƒ | i ƒ ‚ n | |  i | <q q W|  i o |  i |  i i ƒ  f } n |  i d  f } x9 |  i D]. } | |  i j o |  i | |  i | <qbqbW| S(   Nu   YAMLs   found duplicate YAML directivei   s:   found incompatible YAML document (version 1.* is required)u   TAGs   duplicate tag handle %rs   utf-8(   R   R   R	   R"   R#   R   t   nameR   R   R   t   encodet   copyR&   (   R   R   t   majort   minort   handlet   prefixR   t   key(    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR/   Ò   s:    					

 c         C   s   |  i  d t ƒ S(   Nt   block(   t
   parse_nodeR   (   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR+     s    c         C   s
   |  i  ƒ  S(   N(   RA   (   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyt   parse_flow_node  s    c         C   s   |  i  d t d t ƒ S(   NR@   t   indentless_sequence(   RA   R   (   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyt'   parse_block_node_or_indentless_sequence  s    c      	   C   s  |  i  t ƒ o= |  i ƒ  } t | i | i | i ƒ } |  i i ƒ  |  _	 n³d  } d  } d  } } }	 |  i  t ƒ of |  i ƒ  } | i } | i } | i } |  i  t ƒ o+ |  i ƒ  } | i }	 | i } | i } qNnr |  i  t ƒ oa |  i ƒ  } | i } }	 | i } | i } |  i  t ƒ o" |  i ƒ  } | i } | i } qNn | d  j	 o{ | d j on | \ }
 } |
 d  j	 oK |
 |  i j o& t d | d |
 i d ƒ |	 ƒ ‚ n |  i |
 | } qÖ| } n | d  j o |  i ƒ  i } } n d  } | d  j p
 | d j } | oG |  i  t ƒ o7 |  i ƒ  i } t | | | | | ƒ } |  i |  _	 n™|  i  t ƒ o¯ |  i ƒ  } | i } | i o | d  j p | d j o t t f } n* | d  j o t t f } n t t f } t | | | | i | | d | i ƒ} |  i i ƒ  |  _	 nÚ|  i  t ƒ o= |  i ƒ  i } t | | | | | d t ƒ} |  i |  _	 n|  i  t ƒ o= |  i ƒ  i } t | | | | | d t ƒ} |  i |  _	 n@| oM |  i  t ƒ o= |  i ƒ  i } t | | | | | d t ƒ} |  i  |  _	 nì | oM |  i  t! ƒ o= |  i ƒ  i } t | | | | | d t ƒ} |  i" |  _	 n˜ | d  j	 p | d  j	 o7 t | | | t f d | | ƒ } |  i i ƒ  |  _	 nG | o
 d } n d	 } |  i ƒ  } t d
 | | d | i# | i ƒ ‚ | S(   Nu   !s   while parsing a nodes   found undefined tag handle %rs   utf-8t   stylet
   flow_styleu    R@   t   flows   while parsing a %s nodes'   expected the node content, but found %r($   R"   t
   AliasTokenR   t
   AliasEventR   R   R   R
   R7   R   R   t   AnchorTokent   TagTokenR	   R   R9   R'   t   BlockEntryTokent   SequenceStartEventt   parse_indentless_sequence_entryt   ScalarTokent   plainR   R   t   ScalarEventRE   t   FlowSequenceStartTokent   parse_flow_sequence_first_entryt   FlowMappingStartTokent   MappingStartEventt   parse_flow_mapping_first_keyt   BlockSequenceStartTokent    parse_block_sequence_first_entryt   BlockMappingStartTokent   parse_block_mapping_first_keyR0   (   R   R@   RC   R   R    t   anchort   tagR   R   t   tag_markR=   t   suffixt   implicitt   node(    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRA   
  s®    									
	$

c         C   s)   |  i  ƒ  } |  i i | i ƒ |  i ƒ  S(   N(   R   R   R)   R   t   parse_block_sequence_entry(   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRX   q  s    c         C   sú   |  i  t ƒ o` |  i ƒ  } |  i  t t ƒ p! |  i i |  i ƒ |  i ƒ  Sqp |  i |  _ |  i	 | i
 ƒ Sn |  i  t ƒ p6 |  i ƒ  } t d |  i d d | i | i ƒ ‚ n |  i ƒ  } t | i | i
 ƒ } |  i i ƒ  |  _ |  i i ƒ  | S(   Ns    while parsing a block collectioniÿÿÿÿs"   expected <block end>, but found %r(   R"   RL   R   t   BlockEndTokenR
   R)   Ra   R+   R   R6   R   R'   R   R   R0   R   t   SequenceEndEventR7   (   R   R   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRa   v  s     c         C   s­   |  i  t ƒ of |  i ƒ  } |  i  t t t t ƒ p! |  i i |  i ƒ |  i	 ƒ  Sqv |  i |  _
 |  i | i ƒ Sn |  i ƒ  } t | i | i ƒ } |  i i ƒ  |  _
 | S(   N(   R"   RL   R   t   KeyTokent
   ValueTokenRb   R
   R)   RN   R+   R   R6   R   R'   Rc   R   R7   (   R   R   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRN   ‹  s    	c         C   s)   |  i  ƒ  } |  i i | i ƒ |  i ƒ  S(   N(   R   R   R)   R   t   parse_block_mapping_key(   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRZ   Ÿ  s    c         C   sý   |  i  t ƒ oc |  i ƒ  } |  i  t t t ƒ p! |  i i |  i ƒ |  i ƒ  Sqs |  i |  _	 |  i
 | i ƒ Sn |  i  t ƒ p6 |  i ƒ  } t d |  i d d | i | i ƒ ‚ n |  i ƒ  } t | i | i ƒ } |  i i ƒ  |  _	 |  i i ƒ  | S(   Ns   while parsing a block mappingiÿÿÿÿs"   expected <block end>, but found %r(   R"   Rd   R   Re   Rb   R
   R)   t   parse_block_mapping_valueRD   R   R6   R   R'   R   R   R0   R   t   MappingEndEventR7   (   R   R   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRf   ¤  s     c         C   sŸ   |  i  t ƒ oc |  i ƒ  } |  i  t t t ƒ p! |  i i |  i ƒ |  i ƒ  Sq› |  i |  _	 |  i
 | i ƒ Sn) |  i |  _	 |  i ƒ  } |  i
 | i ƒ Sd  S(   N(   R"   Re   R   Rd   Rb   R
   R)   Rf   RD   R   R6   R   R'   R   (   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRg   ·  s    c         C   s/   |  i  ƒ  } |  i i | i ƒ |  i d t ƒ S(   Nt   first(   R   R   R)   R   t   parse_flow_sequence_entryR   (   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRS   Ð  s    c         C   s8  |  i  t ƒ pä | pT |  i  t ƒ o |  i ƒ  qk |  i ƒ  } t d |  i d d | i | i ƒ ‚ n |  i  t	 ƒ oD |  i ƒ  } t
 d  d  t | i | i d t ƒ} |  i |  _ | Sqô |  i  t ƒ p! |  i i |  i ƒ |  i ƒ  Sqô n |  i ƒ  } t | i | i ƒ } |  i i ƒ  |  _ |  i i ƒ  | S(   Ns   while parsing a flow sequenceiÿÿÿÿs   expected ',' or ']', but got %rRF   (   R"   t   FlowSequenceEndTokent   FlowEntryTokenR   R'   R   R   R0   R   Rd   RU   R   R   R   t%   parse_flow_sequence_entry_mapping_keyR   R
   R)   Rj   RB   Rc   R7   (   R   Ri   R   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRj   Õ  s,    	c         C   sc   |  i  ƒ  } |  i t t t ƒ p! |  i i |  i ƒ |  i ƒ  Sn |  i |  _	 |  i
 | i ƒ Sd  S(   N(   R   R"   Re   Rl   Rk   R
   R)   t'   parse_flow_sequence_entry_mapping_valueRB   R   R6   R   (   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRm   ï  s    	c         C   sœ   |  i  t ƒ o` |  i ƒ  } |  i  t t ƒ p! |  i i |  i ƒ |  i ƒ  Sq˜ |  i |  _	 |  i
 | i ƒ Sn) |  i |  _	 |  i ƒ  } |  i
 | i ƒ Sd  S(   N(   R"   Re   R   Rl   Rk   R
   R)   t%   parse_flow_sequence_entry_mapping_endRB   R   R6   R   R'   R   (   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRn   ù  s    c         C   s+   |  i  |  _ |  i ƒ  } t | i | i ƒ S(   N(   Rj   R   R'   Rh   R   (   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRo     s    c         C   s/   |  i  ƒ  } |  i i | i ƒ |  i d t ƒ S(   NRi   (   R   R   R)   R   t   parse_flow_mapping_keyR   (   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRV     s    c         C   sW  |  i  t ƒ p| pT |  i  t ƒ o |  i ƒ  qk |  i ƒ  } t d |  i d d | i | i ƒ ‚ n |  i  t	 ƒ oc |  i ƒ  } |  i  t
 t t ƒ p! |  i i |  i ƒ |  i ƒ  Sq|  i |  _ |  i | i ƒ Sq|  i  t ƒ p! |  i i |  i ƒ |  i ƒ  Sqn |  i ƒ  } t | i | i ƒ } |  i i ƒ  |  _ |  i i ƒ  | S(   Ns   while parsing a flow mappingiÿÿÿÿs   expected ',' or '}', but got %r(   R"   t   FlowMappingEndTokenRl   R   R'   R   R   R0   R   Rd   Re   R
   R)   t   parse_flow_mapping_valueRB   R   R6   R   t   parse_flow_mapping_empty_valueRh   R7   (   R   Ri   R   R    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRp     s.    	c         C   sœ   |  i  t ƒ o` |  i ƒ  } |  i  t t ƒ p! |  i i |  i ƒ |  i ƒ  Sq˜ |  i |  _	 |  i
 | i ƒ Sn) |  i |  _	 |  i ƒ  } |  i
 | i ƒ Sd  S(   N(   R"   Re   R   Rl   Rq   R
   R)   Rp   RB   R   R6   R   R'   R   (   R   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRr   2  s    c         C   s"   |  i  |  _ |  i |  i ƒ  i ƒ S(   N(   Rp   R   R6   R'   R   (   R   (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyRs   @  s    c         C   s   t  d  d  t t f d | | ƒ S(   Nu    (   RQ   R   R   R   (   R   t   mark(    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR6   D  s    ("   R   R   R&   R   R   R   R   R   R   R,   R*   R1   R/   R+   RB   RD   R   RA   RX   Ra   RN   RZ   Rf   Rg   RS   Rj   Rm   Rn   Ro   RV   Rp   Rr   Rs   R6   (    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pyR    H   sB   												/			g								
					N(	   t   __all__t   errorR   t   tokenst   eventst   scannerR   t   objectR    (    (    (    s!   /p/zhu/06/nlp/nltk/yaml/parser.pys   <module>>   s   


