(&self, f: &mut Formatter<'_>)
| 30 | |
| 31 | impl<'a> Display for SourceCursor<'a> { |
| 32 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 33 | match self.token().kind() { |
| 34 | Kind::Eof => Ok(()), |
| 35 | #[cfg(feature = "egg")] |
| 36 | Kind::String if self.should_expand => self.fmt_expanded_string(f), |
| 37 | Kind::String if self.should_compact && self.token().contains_escape_chars() => self.fmt_compacted_string(f), |
| 38 | // It is important to manually write out quotes for 2 reasons: |
| 39 | // 1. The quote style can be mutated from the source string (such as the case of normalising/switching quotes. |
| 40 | // 2. Some strings may not have the closing quote, which should be corrected. |
| 41 | Kind::String => match self.token().quote_style() { |
| 42 | QuoteStyle::Single => { |
| 43 | let inner = |
| 44 | &self.source[1..(self.token().len() as usize) - self.token().has_close_quote() as usize]; |
| 45 | write!(f, "'{inner}'") |
| 46 | } |
| 47 | QuoteStyle::Double => { |
| 48 | let inner = |
| 49 | &self.source[1..(self.token().len() as usize) - self.token().has_close_quote() as usize]; |
| 50 | write!(f, "\"{inner}\"") |
| 51 | } |
| 52 | // Strings must always be quoted! |
| 53 | QuoteStyle::None => unreachable!(), |
| 54 | }, |
| 55 | Kind::Delim |
| 56 | | Kind::Colon |
| 57 | | Kind::Semicolon |
| 58 | | Kind::Comma |
| 59 | | Kind::LeftSquare |
| 60 | | Kind::LeftParen |
| 61 | | Kind::RightSquare |
| 62 | | Kind::RightParen |
| 63 | | Kind::LeftCurly |
| 64 | | Kind::RightCurly => self.token().char().unwrap().fmt(f), |
| 65 | _ if self.should_compact => self.fmt_compacted(f), |
| 66 | #[cfg(feature = "egg")] |
| 67 | _ if self.should_expand => self.fmt_expanded(f), |
| 68 | _ => f.write_str(self.source), |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | impl<'a> SourceCursor<'a> { |
no test coverage detected