22
33use koto_runtime:: { prelude:: * , Result } ;
44use koto_serialize:: SerializableValue ;
5- use serde_yaml :: Value as YamlValue ;
5+ use serde_yaml_ng :: Value as YamlValue ;
66
7- pub fn yaml_value_to_koto_value ( value : & serde_yaml :: Value ) -> Result < KValue > {
7+ pub fn yaml_value_to_koto_value ( value : & YamlValue ) -> Result < KValue > {
88 let result = match value {
99 YamlValue :: Null => KValue :: Null ,
1010 YamlValue :: Bool ( b) => KValue :: Bool ( * b) ,
@@ -37,6 +37,20 @@ pub fn yaml_value_to_koto_value(value: &serde_yaml::Value) -> Result<KValue> {
3737 }
3838 KValue :: Map ( map)
3939 }
40+ YamlValue :: Tagged ( tagged_value) => {
41+ let map = KMap :: with_type ( "TaggedValue" ) ;
42+
43+ let tag = tagged_value. tag . to_string ( ) ;
44+ let tag = match tag. strip_prefix ( "!" ) {
45+ Some ( stripped) => stripped. to_string ( ) ,
46+ None => tag,
47+ } ;
48+
49+ map. insert ( "tag" , tag) ;
50+ map. insert ( "value" , yaml_value_to_koto_value ( value) ?) ;
51+
52+ KValue :: Map ( map)
53+ }
4054 } ;
4155
4256 Ok ( result)
@@ -46,7 +60,7 @@ pub fn make_module() -> KMap {
4660 let result = KMap :: with_type ( "yaml" ) ;
4761
4862 result. add_fn ( "from_string" , |ctx| match ctx. args ( ) {
49- [ KValue :: Str ( s) ] => match serde_yaml :: from_str ( s) {
63+ [ KValue :: Str ( s) ] => match serde_yaml_ng :: from_str ( s) {
5064 Ok ( value) => match yaml_value_to_koto_value ( & value) {
5165 Ok ( result) => Ok ( result) ,
5266 Err ( e) => runtime_error ! ( "Error while parsing input: {}" , e) ,
@@ -57,7 +71,7 @@ pub fn make_module() -> KMap {
5771 } ) ;
5872
5973 result. add_fn ( "to_string" , |ctx| match ctx. args ( ) {
60- [ value] => match serde_yaml :: to_string ( & SerializableValue ( value) ) {
74+ [ value] => match serde_yaml_ng :: to_string ( & SerializableValue ( value) ) {
6175 Ok ( result) => Ok ( result. into ( ) ) ,
6276 Err ( e) => runtime_error ! ( "yaml.to_string: {}" , e) ,
6377 } ,
0 commit comments