1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
pub use self::{
ast::*,
collections::{NamedItem, NamedSet, Unnamed},
};
use heck::ToPascalCase;
use indexmap::IndexMap;
use serde::Deserialize;
use std::fmt::{Display, Formatter};
use thiserror::Error;
mod ast;
mod collections;
mod tokens;
#[derive(Clone, Debug, Deserialize)]
#[serde(bound(deserialize = "'de: 's"))]
pub struct Specs<'s> {
pub static_tokens: IndexMap<Ident<'s>, &'s str>,
pub dynamic_tokens: IndexMap<Ident<'s>, &'s str>,
pub delimiters: IndexMap<Ident<'s>, Delimiter<'s>>,
}
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Deserialize)]
#[serde(transparent)]
pub struct Ident<'a>(&'a str);
#[derive(Copy, Clone, Debug, Deserialize)]
pub struct Delimiter<'d> {
open: &'d str,
close: &'d str,
}
impl<'i> Ident<'i> {
pub fn as_type(&self) -> proc_macro2::Ident {
quote::format_ident!("{}", self.0.to_pascal_case())
}
}
impl Display for Ident<'_> {
#[inline(always)]
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(self.0, f)
}
}
#[derive(Clone, Debug, Error)]
#[error("invalid ident: {0}")]
pub struct InvalidIdent(String);
fn is_rust_keyword(word: &str) -> bool {
#[rustfmt::skip]
const KEYWORDS: &[&str] = &[
"as", "async", "await", "break", "const", "continue", "crate", "dyn", "else", "enum", "extern",
"false", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub",
"ref", "return", "self", "Self", "static", "struct", "super", "trait", "true", "type",
"unsafe", "use", "where", "while",
"abstract", "become", "box", "do", "final", "macro", "override", "priv", "try", "typeof",
"unsized", "virtual", "yield",
];
KEYWORDS.contains(&word)
}
#[cfg(test)]
#[allow(clippy::type_complexity)]
const SNAPSHOT_CASES: &[&str] = &["json", "foo"];