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