mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
Improve type safety of write_list_flag function.
This commit is contained in:
parent
e6f2f12dc9
commit
a7b214a9af
@ -37,23 +37,25 @@ impl FlagConverter {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_list_flag(&self, pfx: &str, name: &str, v: &Val, w: &mut Write) -> Result<()> {
|
fn write_list_flag(
|
||||||
if let &Val::List(ref def) = v {
|
&self,
|
||||||
// first of all we need to make sure that each &Val is only a primitive type.
|
pfx: &str,
|
||||||
for v in def.iter() {
|
name: &str,
|
||||||
let vref = v.as_ref();
|
def: &Vec<Rc<Val>>,
|
||||||
if vref.is_list() || vref.is_tuple() || vref.is_macro() {
|
w: &mut Write,
|
||||||
eprintln!(
|
) -> Result<()> {
|
||||||
"Skipping non primitive val in list for flag {}{}",
|
// first of all we need to make sure that each &Val is only a primitive type.
|
||||||
pfx, name
|
for v in def.iter() {
|
||||||
);
|
let vref = v.as_ref();
|
||||||
} else {
|
if vref.is_list() || vref.is_tuple() || vref.is_macro() {
|
||||||
try!(self.write_flag_name(pfx, name, w));
|
eprintln!(
|
||||||
try!(self.write(pfx, vref, w));
|
"Skipping non primitive val in list for flag {}{}",
|
||||||
}
|
pfx, name
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
try!(self.write_flag_name(pfx, name, w));
|
||||||
|
try!(self.write(pfx, vref, w));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
panic!("Impossible call happened. Somebody messed up.")
|
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -82,14 +84,18 @@ impl FlagConverter {
|
|||||||
try!(self.write_flag_name(pfx, &name.val, w));
|
try!(self.write_flag_name(pfx, &name.val, w));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if val.is_tuple() {
|
match val.as_ref() {
|
||||||
let new_pfx = format!("{}{}.", pfx, name);
|
&Val::Tuple(_) => {
|
||||||
try!(self.write(&new_pfx, val, w));
|
let new_pfx = format!("{}{}.", pfx, name);
|
||||||
} else if val.is_list() {
|
try!(self.write(&new_pfx, val, w));
|
||||||
try!(self.write_list_flag(pfx, &name.val, &val, w));
|
}
|
||||||
} else {
|
&Val::List(ref def) => {
|
||||||
try!(self.write_flag_name(pfx, &name.val, w));
|
try!(self.write_list_flag(pfx, &name.val, def, w));
|
||||||
try!(self.write(pfx, &val, w));
|
}
|
||||||
|
_ => {
|
||||||
|
try!(self.write_flag_name(pfx, &name.val, w));
|
||||||
|
try!(self.write(pfx, &val, w));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&Val::Macro(ref _def) => {
|
&Val::Macro(ref _def) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user