mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -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(());
|
||||
}
|
||||
|
||||
fn write_list_flag(&self, pfx: &str, name: &str, v: &Val, w: &mut Write) -> Result<()> {
|
||||
if let &Val::List(ref def) = v {
|
||||
// first of all we need to make sure that each &Val is only a primitive type.
|
||||
for v in def.iter() {
|
||||
let vref = v.as_ref();
|
||||
if vref.is_list() || vref.is_tuple() || vref.is_macro() {
|
||||
eprintln!(
|
||||
"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));
|
||||
}
|
||||
fn write_list_flag(
|
||||
&self,
|
||||
pfx: &str,
|
||||
name: &str,
|
||||
def: &Vec<Rc<Val>>,
|
||||
w: &mut Write,
|
||||
) -> Result<()> {
|
||||
// first of all we need to make sure that each &Val is only a primitive type.
|
||||
for v in def.iter() {
|
||||
let vref = v.as_ref();
|
||||
if vref.is_list() || vref.is_tuple() || vref.is_macro() {
|
||||
eprintln!(
|
||||
"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(());
|
||||
}
|
||||
@ -82,14 +84,18 @@ impl FlagConverter {
|
||||
try!(self.write_flag_name(pfx, &name.val, w));
|
||||
continue;
|
||||
}
|
||||
if val.is_tuple() {
|
||||
let new_pfx = format!("{}{}.", pfx, name);
|
||||
try!(self.write(&new_pfx, val, w));
|
||||
} else if val.is_list() {
|
||||
try!(self.write_list_flag(pfx, &name.val, &val, w));
|
||||
} else {
|
||||
try!(self.write_flag_name(pfx, &name.val, w));
|
||||
try!(self.write(pfx, &val, w));
|
||||
match val.as_ref() {
|
||||
&Val::Tuple(_) => {
|
||||
let new_pfx = format!("{}{}.", pfx, name);
|
||||
try!(self.write(&new_pfx, val, w));
|
||||
}
|
||||
&Val::List(ref def) => {
|
||||
try!(self.write_list_flag(pfx, &name.val, def, w));
|
||||
}
|
||||
_ => {
|
||||
try!(self.write_flag_name(pfx, &name.val, w));
|
||||
try!(self.write(pfx, &val, w));
|
||||
}
|
||||
}
|
||||
},
|
||||
&Val::Macro(ref _def) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user