fixed: emitter also emits complex keys
This commit is contained in:
parent
ff90a2127c
commit
d0f4fc3abc
1 changed files with 44 additions and 2 deletions
|
@ -113,6 +113,48 @@ impl<'a> YamlEmitter<'a> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn emit_node_compact(&mut self, node: &Yaml) -> EmitResult {
|
||||||
|
match *node {
|
||||||
|
Yaml::Array(ref v) => {
|
||||||
|
try!(write!(self.writer, "["));
|
||||||
|
if self.level >= 0 {
|
||||||
|
try!(write!(self.writer, "+ "));
|
||||||
|
}
|
||||||
|
self.level += 1;
|
||||||
|
for (cnt, x) in v.iter().enumerate() {
|
||||||
|
try!(self.write_indent());
|
||||||
|
if cnt > 0 { try!(write!(self.writer, ", ")); }
|
||||||
|
try!(self.emit_node(x));
|
||||||
|
}
|
||||||
|
self.level -= 1;
|
||||||
|
try!(write!(self.writer, "]"));
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Yaml::Hash(ref h) => {
|
||||||
|
try!(self.writer.write_str("{"));
|
||||||
|
self.level += 1;
|
||||||
|
for (cnt, (k, v)) in h.iter().enumerate() {
|
||||||
|
if cnt > 0 {
|
||||||
|
try!(write!(self.writer, ", "));
|
||||||
|
}
|
||||||
|
match *k {
|
||||||
|
// complex key is not supported
|
||||||
|
Yaml::Array(_) | Yaml::Hash(_) => {
|
||||||
|
return Err(EmitError::BadHashmapKey);
|
||||||
|
},
|
||||||
|
_ => { try!(self.emit_node(k)); }
|
||||||
|
}
|
||||||
|
try!(write!(self.writer, ": "));
|
||||||
|
try!(self.emit_node(v));
|
||||||
|
}
|
||||||
|
try!(self.writer.write_str("}"));
|
||||||
|
self.level -= 1;
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
_ => self.emit_node(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn emit_node(&mut self, node: &Yaml) -> EmitResult {
|
fn emit_node(&mut self, node: &Yaml) -> EmitResult {
|
||||||
match *node {
|
match *node {
|
||||||
Yaml::Array(ref v) => {
|
Yaml::Array(ref v) => {
|
||||||
|
@ -151,9 +193,9 @@ impl<'a> YamlEmitter<'a> {
|
||||||
}
|
}
|
||||||
try!(self.write_indent());
|
try!(self.write_indent());
|
||||||
match *k {
|
match *k {
|
||||||
// complex key is not supported
|
|
||||||
Yaml::Array(_) | Yaml::Hash(_) => {
|
Yaml::Array(_) | Yaml::Hash(_) => {
|
||||||
return Err(EmitError::BadHashmapKey);
|
try!(self.emit_node_compact(k));
|
||||||
|
//return Err(EmitError::BadHashmapKey);
|
||||||
},
|
},
|
||||||
_ => { try!(self.emit_node(k)); }
|
_ => { try!(self.emit_node(k)); }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue