Follow-up: replace println_stderr with eprintln.

This commit is contained in:
Richard Newman 2018-02-15 10:18:46 -08:00
parent 54bd883c65
commit 20d1b45293

View file

@ -8,8 +8,6 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the // CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License. // specific language governing permissions and limitations under the License.
use std::io::Write;
use combine::{ use combine::{
ParseError, ParseError,
Parser, Parser,
@ -17,20 +15,6 @@ use combine::{
Stream, Stream,
}; };
/// println!, but to stderr.
///
/// Doesn't pollute stdout, which is useful when running tests under Emacs, which parses the output
/// of the test suite to format errors and can get confused when user output is interleaved into the
/// stdout stream.
///
/// Cribbed from http://stackoverflow.com/a/27590832.
macro_rules! println_stderr(
($($arg:tt)*) => { {
let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
r.expect("failed printing to stderr");
} }
);
#[derive(Clone)] #[derive(Clone)]
pub struct Log<P, T>(P, T) pub struct Log<P, T>(P, T)
where P: Parser, where P: Parser,
@ -50,8 +34,8 @@ impl<I, P, T> Parser for Log<P, T>
let head = input.clone().uncons(); let head = input.clone().uncons();
let result = self.0.parse_stream(input.clone()); let result = self.0.parse_stream(input.clone());
match result { match result {
Ok((ref value, _)) => println_stderr!("{:?}: [{:?} ...] => Ok({:?})", self.1, head.ok(), value), Ok((ref value, _)) => eprintln!("{:?}: [{:?} ...] => Ok({:?})", self.1, head.ok(), value),
Err(_) => println_stderr!("{:?}: [{:?} ...] => Err(_)", self.1, head.ok()), Err(_) => eprintln!("{:?}: [{:?} ...] => Err(_)", self.1, head.ok()),
} }
result result
} }