3 Z d?d@Z!dAdBZ"dCS)Gr!ztag:yaml.org,2002:)r z!!cCs*d|_d|_i|_g|_g|_|j|_dS)N) current_event yaml_version tag_handlesstatesmarksparse_stream_startstate)selfr r r __init__Qs zParser.__init__cCsg|_d|_dS)N)rr)rr r r disposeYszParser.disposecGsN|jdkr|jr|j|_|jdk rJ|s,dSx|D]}t|j|r2dSq2WdS)NTF)r r isinstance)rchoicesZchoicer r r check_event^s     zParser.check_eventcCs |jdkr|jr|j|_|jS)N)r r)rr r r peek_eventks  zParser.peek_eventcCs*|jdkr|jr|j|_|j}d|_|S)N)r r)rvaluer r r get_eventrs   zParser.get_eventcCs(|j}t|j|j|jd}|j|_|S)N)encoding) get_tokenZStreamStartEvent start_markend_markrparse_implicit_document_startr)rtokeneventr r r rs   zParser.parse_stream_startcCs\|jtttsP|j|_|j}|j}}t||dd}|j j |j |j |_ |S|jSdS)NF)explicit) check_tokenDirectiveTokenDocumentStartTokenStreamEndToken DEFAULT_TAGSr peek_tokenrDocumentStartEventrappendparse_document_endparse_block_noderparse_document_start)rr!rrr"r r r r s z$Parser.parse_implicit_document_startcCsx|jtr|jqW|jts|j}|j}|j\}}|jtsdtddd|jj |jj|j}|j }t ||d||d}|j j |j|j|_n4|j}t|j|j }|j st|j std|_|S)Nz)expected '', but found %rT)r#versiontags)r$DocumentEndTokenrr'r)rprocess_directivesr&ridrr*rr+r,parse_document_contentrZStreamEndEventAssertionErrorr)rr!rr/r0rr"r r r r.s.           zParser.parse_document_startcCsL|j}|j}}d}|jtr2|j}|j}d}t|||d}|j|_|S)NFT)r#) r)rr$r1rrZDocumentEndEventr.r)rr!rrr#r"r r r r,s  zParser.parse_document_endcCs<|jttttr0|j|jj}|jj |_ |S|j SdS)N) r$r%r&r1r'process_empty_scalarr)rrpoprr-)rr"r r r r4s   zParser.parse_document_contentcCsd|_i|_x|jtr|j}|jdkrp|jdk rDtddd|j|j\}}|dkrftddd|j|j|_q|jdkr|j\}}||jkrtddd||j||j|<qW|jr|j|jj f}n |jdf}x(|j D]}||jkr|j ||j|<qW|S)NZYAMLzfound duplicate YAML directiverz:found incompatible YAML document (version 1.* is required)ZTAGzduplicate tag handle %r) r rr$r%rnamerrrcopyr()rr!majorminorhandleprefixrkeyr r r r2s8            zParser.process_directivescCs |jddS)NT)block) parse_node)rr r r r-szParser.parse_block_nodecCs|jS)N)r@)rr r r parse_flow_node szParser.parse_flow_nodecCs|jdddS)NT)r?indentless_sequence)r@)rr r r 'parse_block_node_or_indentless_sequencesz.Parser.parse_block_node_or_indentless_sequenceFc CsR|jtr4|j}t|j|j|j}|jj|_ nd}d}d}}} |jt r|j}|j}|j}|j}|jt r|j}|j} |j}|j}nF|jt r|j}|j}} |j}|j}|jt r|j}|j}|j}|dk r&|\} } | dk r"| |j krt d|d| | |j | | }n| }|dkr>|jj}}d}|dkpR|dk} |r|jtr|jj}t||| ||}|j|_ n|jtr|j}|j}|jr|dks|dkrd } n|dkrd} nd} t||| |j|||jd}|jj|_ nH|jtr<|jj}t||| ||dd}|j|_ n|jtrp|jj}t||| ||dd}|j|_ n|r|jtr|jj}t||| ||dd}|j|_ n|r|jtr|jj}t||| ||dd}|j|_ nj|dk s|dk rt||| dfd||}|jj|_ n2|r(d } nd } |j}t d | |d |j|j|S)Nzwhile parsing a nodezfound undefined tag handle %rr TF)style) flow_styler?Zflowzwhile parsing a %s nodez'expected the node content, but found %r)TF)FT)FF) r$Z AliasTokenrZ AliasEventrrrrr7rZ AnchorTokenZTagTokenrrr)BlockEntryTokenZSequenceStartEventparse_indentless_sequence_entryZ ScalarTokenZplain ScalarEventrDZFlowSequenceStartTokenparse_flow_sequence_first_entryZFlowMappingStartTokenMappingStartEventparse_flow_mapping_first_keyZBlockSequenceStartToken parse_block_sequence_first_entryZBlockMappingStartTokenparse_block_mapping_first_keyr3)rr?rBr!r"ZanchortagrrZtag_markr<suffixZimplicitZnoder r r r@s                               zParser.parse_nodecCs|j}|jj|j|jS)N)rrr+rparse_block_sequence_entry)rr!r r r rMxsz'Parser.parse_block_sequence_first_entrycCs|jtrH|j}|jtts4|jj|j|jS|j|_|j |j S|jtsv|j }t d|j dd|j|j|j}t|j|j }|jj|_|j j|S)Nz while parsing a block collectionrz"expected , but found %r)r$rGr BlockEndTokenrr+rQr-rr6rr)rrr3rSequenceEndEventr7)rr!r"r r r rQ}s        z!Parser.parse_block_sequence_entrycCsr|jtrL|j}|jtttts8|jj|j|j S|j|_ |j |j S|j }t|j|j}|jj|_ |S)N)r$rGrKeyToken ValueTokenrSrr+rHr-rr6rr)rTrr7)rr!r"r r r rHs    z&Parser.parse_indentless_sequence_entrycCs|j}|jj|j|jS)N)rrr+rparse_block_mapping_key)rr!r r r rNsz$Parser.parse_block_mapping_first_keycCs|jtrJ|j}|jttts6|jj|j|jS|j|_ |j |j S|jtsx|j }t d|jdd|j|j|j}t|j|j }|jj|_ |jj|S)Nzwhile parsing a block mappingrz"expected , but found %rrR)r$rUrrVrSrr+parse_block_mapping_valuerCrr6rr)rrr3rMappingEndEventr7)rr!r"r r r rWs       zParser.parse_block_mapping_keycCsl|jtrL|j}|jttts6|jj|j|jS|j|_ |j |j Sn|j|_ |j }|j |j SdS)N)r$rVrrUrSrr+rWrCrr6rr)r)rr!r r r rXs z Parser.parse_block_mapping_valuecCs"|j}|jj|j|jddS)NT)first)rrr+rparse_flow_sequence_entry)rr!r r r rJsz&Parser.parse_flow_sequence_first_entrycCs|jts|sF|jtr"|jn$|j}td|jdd|j|j|jt r||j}t ddd|j|j dd}|j |_ |S|jts|jj|j|jS|j}t|j|j }|jj|_ |jj|S)Nzwhile parsing a flow sequencerzexpected ',' or ']', but got %rT)rErR)r$FlowSequenceEndTokenFlowEntryTokenrr)rrr3rrUrKr%parse_flow_sequence_entry_mapping_keyrrr+r[rArTr7)rrZr!r"r r r r[s,        z Parser.parse_flow_sequence_entrycCsD|j}|jttts,|jj|j|jS|j|_ |j |j SdS)N) rr$rVr]r\rr+'parse_flow_sequence_entry_mapping_valuerArr6r)rr!r r r r^sz,Parser.parse_flow_sequence_entry_mapping_keycCsj|jtrJ|j}|jtts4|jj|j|jS|j|_ |j |j Sn|j|_ |j }|j |j SdS)N)r$rVrr]r\rr+%parse_flow_sequence_entry_mapping_endrArr6rr)r)rr!r r r r_s  z.Parser.parse_flow_sequence_entry_mapping_valuecCs|j|_|j}t|j|jS)N)r[rr)rYr)rr!r r r r`sz,Parser.parse_flow_sequence_entry_mapping_endcCs"|j}|jj|j|jddS)NT)rZ)rrr+rparse_flow_mapping_key)rr!r r r rLsz#Parser.parse_flow_mapping_first_keycCs|jts|sF|jtr"|jn$|j}td|jdd|j|j|jt r|j}|jt tts||j j |j |jS|j |_|j|jSn |jts|j j |j|jS|j}t|j|j}|j j|_|jj|S)Nzwhile parsing a flow mappingrzexpected ',' or '}', but got %rrR)r$FlowMappingEndTokenr]rr)rrr3rrUrVrr+parse_flow_mapping_valuerArr6rparse_flow_mapping_empty_valuerYr7)rrZr!r"r r r ras.        zParser.parse_flow_mapping_keycCsj|jtrJ|j}|jtts4|jj|j|jS|j|_ |j |j Sn|j|_ |j }|j |j SdS)N)r$rVrr]rbrr+rarArr6rr)r)rr!r r r rc9s  zParser.parse_flow_mapping_valuecCs|j|_|j|jjS)N)rarr6r)r)rr r r rdGsz%Parser.parse_flow_mapping_empty_valuecCstdddd||S)NTFrF)TF)rI)rZmarkr r r r6KszParser.process_empty_scalarN)FF)F)F)#rrrr(rrrrrrr r.r,r4r2r-rArCr@rMrQrHrNrWrXrJr[r^r_r`rLrarcrdr6r r r r rHsB    / g    N)__all__errorrtokensZeventsscannerrrr r r r >s