Skip to content

Commit

Permalink
Support C-string literal syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 15, 2024
1 parent 86ac6a9 commit 1ad491d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ rust-version = "1.60"
verbatim = ["syn/parsing"]

[dependencies]
proc-macro2 = { version = "1.0.74", default-features = false }
syn = { version = "2.0.46", default-features = false, features = ["full"] }
proc-macro2 = { version = "1.0.80", default-features = false }
syn = { version = "2.0.59", default-features = false, features = ["full"] }

[dev-dependencies]
indoc = "2"
proc-macro2 = { version = "1.0.74", default-features = false }
proc-macro2 = { version = "1.0.80", default-features = false }
quote = { version = "1.0.35", default-features = false }
syn = { version = "2.0.46", default-features = false, features = ["parsing"] }
syn = { version = "2.0.59", default-features = false, features = ["parsing"] }

[lib]
doc-scrape-examples = false
Expand Down
7 changes: 6 additions & 1 deletion src/lit.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::algorithm::Printer;
use proc_macro2::Literal;
use syn::{Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr};
use syn::{Lit, LitBool, LitByte, LitByteStr, LitCStr, LitChar, LitFloat, LitInt, LitStr};

impl Printer {
pub fn lit(&mut self, lit: &Lit) {
match lit {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Lit::Str(lit) => self.lit_str(lit),
Lit::ByteStr(lit) => self.lit_byte_str(lit),
Lit::CStr(lit) => self.lit_c_str(lit),
Lit::Byte(lit) => self.lit_byte(lit),
Lit::Char(lit) => self.lit_char(lit),
Lit::Int(lit) => self.lit_int(lit),
Expand All @@ -26,6 +27,10 @@ impl Printer {
self.word(lit.token().to_string());
}

fn lit_c_str(&mut self, lit: &LitCStr) {
self.word(lit.token().to_string());
}

fn lit_byte(&mut self, lit: &LitByte) {
self.word(lit.token().to_string());
}
Expand Down

0 comments on commit 1ad491d

Please sign in to comment.