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