prettyplease/
lit.rs

1use crate::algorithm::Printer;
2use proc_macro2::Literal;
3use syn::{Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr};
4
5impl Printer {
6    pub fn lit(&mut self, lit: &Lit) {
7        match lit {
8            Lit::Str(lit) => self.lit_str(lit),
9            Lit::ByteStr(lit) => self.lit_byte_str(lit),
10            Lit::Byte(lit) => self.lit_byte(lit),
11            Lit::Char(lit) => self.lit_char(lit),
12            Lit::Int(lit) => self.lit_int(lit),
13            Lit::Float(lit) => self.lit_float(lit),
14            Lit::Bool(lit) => self.lit_bool(lit),
15            Lit::Verbatim(lit) => self.lit_verbatim(lit),
16            #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
17            _ => unimplemented!("unknown Lit"),
18        }
19    }
20
21    pub fn lit_str(&mut self, lit: &LitStr) {
22        self.word(lit.token().to_string());
23    }
24
25    fn lit_byte_str(&mut self, lit: &LitByteStr) {
26        self.word(lit.token().to_string());
27    }
28
29    fn lit_byte(&mut self, lit: &LitByte) {
30        self.word(lit.token().to_string());
31    }
32
33    fn lit_char(&mut self, lit: &LitChar) {
34        self.word(lit.token().to_string());
35    }
36
37    fn lit_int(&mut self, lit: &LitInt) {
38        self.word(lit.token().to_string());
39    }
40
41    fn lit_float(&mut self, lit: &LitFloat) {
42        self.word(lit.token().to_string());
43    }
44
45    fn lit_bool(&mut self, lit: &LitBool) {
46        self.word(if lit.value { "true" } else { "false" });
47    }
48
49    fn lit_verbatim(&mut self, token: &Literal) {
50        self.word(token.to_string());
51    }
52}