forked from syndicate-lang/preserves
Unquoted output format
This commit is contained in:
parent
8b5aa372b5
commit
62cd9ac78f
|
@ -43,6 +43,7 @@ enum InputFormat {
|
|||
enum OutputFormat {
|
||||
Text,
|
||||
Binary,
|
||||
Unquoted,
|
||||
}
|
||||
|
||||
#[derive(ArgEnum, Clone, Debug)]
|
||||
|
@ -352,6 +353,14 @@ impl<R: io::Read> std::iter::Iterator for ValueStream<R> {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_unquoted(v: &IOValue) {
|
||||
match v.value() {
|
||||
Value::String(s) => println!("{}", &s),
|
||||
Value::Symbol(s) => println!("{}", &s),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert(c: Convert) -> io::Result<()> {
|
||||
let mut vs = ValueStream::new(c.input_format, c.annotations.into(), io::stdin());
|
||||
let mut w: Box<dyn FnMut(&IOValue) -> io::Result<()>> = match c.output_format {
|
||||
|
@ -370,6 +379,8 @@ fn convert(c: Convert) -> io::Result<()> {
|
|||
let mut p = PackedWriter::new(io::stdout());
|
||||
Box::new(move |v| p.write(&mut IOValueDomainCodec, v))
|
||||
}
|
||||
OutputFormat::Unquoted =>
|
||||
Box::new(|v| Ok(print_unquoted(v))),
|
||||
};
|
||||
while let Some(value) = vs.next() {
|
||||
let value = value?;
|
||||
|
@ -414,6 +425,10 @@ fn output_one(q: &Quote, v: &IOValue) -> io::Result<()> {
|
|||
println!();
|
||||
Ok(())
|
||||
}
|
||||
OutputFormat::Unquoted => {
|
||||
print_unquoted(v);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue