Repository: Marwes/combine (language: rust)

Issue:
`expected` error strings always quote what was expected, even if it isn't a literal
toml_edit sets some `expected` for not what character is next but what grammar item is expected (e.g. "key").

This means they are quoted, like literals.  See review comments on https://github.com/rust-lang/cargo/pull/10086


Discussion / hints:
I'd propose we have a
```rust
enum Item {
    Literal(String),
   Other(String),
}
```
(obviously some naming could be improved)

We could have some `impl From`s to keep the API compatible.

I'm willing to implement this, just looking for a go ahead.
It would be a breaking change to make this change to the "easy errors" now and I am not willing to do that for just this (the error handling could use an overhaul though). So you may need to implement your own errors, or convert the easy errors before displaying them.
In looking to see if there was a way to do this without a breaking change, it turned out `combine` already has all the information it needs.  In case you weren't referring to the formatting change as a breaking change (since most textual outputs are not considered stable and stability wasn't mentioned for #333), I am preparing a PR with the change.  At least within combine's docs, it works exactly as expected!

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index ab46d818..77e3e238 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -25,7 +25,7 @@
 //! use combine::parser::char::{digit, letter};
 //! const MSG: &'static str = r#"Parse error at line: 1, column: 1
 //! Unexpected `|`
-//! Expected `digit` or `letter`
+//! Expected digit or letter
 //! "#;
 //!
 //! fn main() {
diff --git a/src/stream/easy.rs b/src/stream/easy.rs
index a0c25f74..0a541824 100644
--- a/src/stream/easy.rs
+++ b/src/stream/easy.rs
@@ -162,8 +162,8 @@ impl<T: PartialEq, R: PartialEq> PartialEq for Info<T, R> {
 impl<T: fmt::Display, R: fmt::Display> fmt::Display for Info<T, R> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            Info::Token(ref c) => write!(f, "{}", c),
-            Info::Range(ref c) => write!(f, "{}", c),
+            Info::Token(ref c) => write!(f, "`{}`", c),
+            Info::Range(ref c) => write!(f, "`{}`", c),
             Info::Owned(ref s) => write!(f, "{}", s),
             Info::Static(s) => write!(f, "{}", s),
         }
@@ -571,7 +571,7 @@ impl<T, R> Error<T, R> {
     /// let m = format!("{}", result.unwrap_err());
     /// let expected = r"Parse error at line: 2, column: 3
     /// Unexpected `,`
-    /// Expected `.`, `a` or `digit`
+    /// Expected `.`, `a` or digit
     /// ";
     /// assert_eq!(m, expected);
     /// # }
@@ -608,7 +608,7 @@ impl<T, R> Error<T, R> {
                 // Last expected message to be written
                 _ => " or",
             };
-            write!(f, "{} `{}`", s, message)?;
+            write!(f, "{} {}", s, message)?;
         }
         if expected_count != 0 {
             writeln!(f)?;
@@ -792,8 +792,8 @@ where
 impl<T: fmt::Display, R: fmt::Display> fmt::Display for Error<T, R> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            Error::Unexpected(ref c) => write!(f, "Unexpected `{}`", c),
-            Error::Expected(ref s) => write!(f, "Expected `{}`", s),
+            Error::Unexpected(ref c) => write!(f, "Unexpected {}", c),
+            Error::Expected(ref s) => write!(f, "Expected {}", s),
             Error::Message(ref msg) => msg.fmt(f),
             Error::Other(ref err) => err.fmt(f),
         }


Test patch: