#[derive(Debug, Clone, Copy)]
pub struct Dialect {
pub keywords: &'static [&'static str],
pub multi_punct: &'static [&'static str],
pub raw_strings: bool,
pub digit_separators: bool,
pub record_keywords: &'static [&'static str],
pub lambdas: bool,
}
const C_KEYWORDS: &[&str] = &[
"_Alignas",
"_Alignof",
"_Atomic",
"_Bool",
"_Complex",
"_Generic",
"_Imaginary",
"_Noreturn",
"_Static_assert",
"_Thread_local",
"alignas",
"alignof",
"auto",
"bool",
"break",
"case",
"char",
"const",
"constexpr",
"continue",
"default",
"do",
"double",
"else",
"enum",
"extern",
"false",
"float",
"for",
"goto",
"if",
"inline",
"int",
"long",
"nullptr",
"register",
"restrict",
"return",
"short",
"signed",
"sizeof",
"static",
"static_assert",
"struct",
"switch",
"thread_local",
"true",
"typedef",
"typeof",
"typeof_unqual",
"union",
"unsigned",
"void",
"volatile",
"while",
];
const C_MULTI_PUNCT: &[&str] = &[
"<<=", ">>=", "...", "->", "++", "--", "<<", ">>", "<=", ">=", "==", "!=", "&&", "||", "+=",
"-=", "*=", "/=", "%=", "&=", "|=", "^=", "##",
];
pub const C: Dialect = Dialect {
keywords: C_KEYWORDS,
multi_punct: C_MULTI_PUNCT,
raw_strings: false,
digit_separators: false,
record_keywords: &["struct", "union"],
lambdas: false,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn c_multi_punct_is_ordered_longest_first() {
let lens: Vec<usize> = C.multi_punct.iter().map(|op| op.len()).collect();
let mut sorted = lens.clone();
sorted.sort_unstable_by(|a, b| b.cmp(a));
assert_eq!(lens, sorted, "greedy matching needs longest-first order");
}
#[test]
#[allow(clippy::assertions_on_constants)] fn c_dialect_has_no_cpp_only_features() {
assert!(!C.raw_strings);
assert!(!C.digit_separators);
assert!(!C.lambdas);
assert!(!C.keywords.contains(&"class"));
assert!(!C.multi_punct.contains(&"::"));
}
}