@@ -72,6 +72,7 @@ pub struct Parser<T> {
7272 token : Option < Token > ,
7373 anchors : HashMap < String , usize > ,
7474 anchor_id : usize ,
75+ tag_directives : HashMap < String , String >
7576}
7677
7778
@@ -104,6 +105,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
104105 anchors : HashMap :: new ( ) ,
105106 // valid anchor_id starts from 1
106107 anchor_id : 1 ,
108+ tag_directives : HashMap :: new ( )
107109 }
108110 }
109111
@@ -344,14 +346,14 @@ impl<T: Iterator<Item=char>> Parser<T> {
344346 // "found incompatible YAML document"));
345347 //}
346348 } ,
347- TokenType :: TagDirective ( ..) => {
348- // TODO add tag directive
349+ TokenType :: TagDirective ( handle, mut prefix) => {
350+ prefix. pop ( ) ; //Remove :
351+ self . tag_directives . insert ( handle , prefix) ;
349352 } ,
350353 _ => break
351354 }
352355 self . skip ( ) ;
353356 }
354- // TODO tag directive
355357 Ok ( ( ) )
356358 }
357359
@@ -455,7 +457,19 @@ impl<T: Iterator<Item=char>> Parser<T> {
455457 TokenType :: Scalar ( style, v) => {
456458 self . pop_state ( ) ;
457459 self . skip ( ) ;
458- Ok ( ( Event :: Scalar ( v, style, anchor_id, tag) , tok. 0 ) )
460+
461+ Ok ( ( if let Some ( TokenType :: Tag ( handle, suffix) ) = tag{
462+ let t = self . tag_directives . get ( & handle) ;
463+ Event :: Scalar ( v, style, anchor_id, Some (
464+ if let Some ( s) = t {
465+ TokenType :: Tag ( ( * s) . clone ( ) , suffix)
466+ } else {
467+ TokenType :: Tag ( handle , suffix)
468+ }
469+ ) )
470+ } else {
471+ Event :: Scalar ( v, style, anchor_id, tag)
472+ } , tok. 0 ) )
459473 } ,
460474 TokenType :: FlowSequenceStart => {
461475 self . state = State :: FlowSequenceFirstEntry ;
0 commit comments