From 62cd9ac78fbb1f335ab774b62405d255877d7b27 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 20 Aug 2021 15:01:30 -0400 Subject: [PATCH] Unquoted output format --- .../preserves-tools/src/bin/preserves-tool.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/implementations/rust/preserves-tools/src/bin/preserves-tool.rs b/implementations/rust/preserves-tools/src/bin/preserves-tool.rs index d89b09d..c7c5bb6 100644 --- a/implementations/rust/preserves-tools/src/bin/preserves-tool.rs +++ b/implementations/rust/preserves-tools/src/bin/preserves-tool.rs @@ -43,6 +43,7 @@ enum InputFormat { enum OutputFormat { Text, Binary, + Unquoted, } #[derive(ArgEnum, Clone, Debug)] @@ -352,6 +353,14 @@ impl std::iter::Iterator for ValueStream { } } +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 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(()) + } } }