mod managed;
mod scripting;
mod systems;
use managed::{CSHARP, JAVA, KOTLIN, SCALA, SWIFT};
use scripting::{BASH, ELIXIR, JAVASCRIPT, LUA, PHP, PYTHON, RUBY, TYPESCRIPT};
use systems::{C, CPP, GO, RUST, ZIG};
use super::Lang;
pub(in crate::functions) struct ParamSpec {
pub lists: &'static [&'static str],
pub items: &'static [&'static str],
pub names_per_item: bool,
}
pub(in crate::functions) struct Grammar {
pub nesting: &'static [&'static str],
pub branches: &'static [&'static str],
pub elifs: &'static [&'static str],
pub switches: &'static [&'static str],
pub cases: &'static [&'static str],
pub binaries: &'static [&'static str],
pub params: Option<ParamSpec>,
pub keyword_calls: &'static [&'static str],
}
impl Lang {
pub(in crate::functions) fn grammar(self) -> &'static Grammar {
match self {
Self::Rust => &RUST,
Self::Python => &PYTHON,
Self::JavaScript => &JAVASCRIPT,
Self::TypeScript | Self::Tsx => &TYPESCRIPT,
Self::Go => &GO,
Self::Java => &JAVA,
Self::C => &C,
Self::Cpp => &CPP,
Self::CSharp => &CSHARP,
Self::Ruby => &RUBY,
Self::Php => &PHP,
Self::Kotlin => &KOTLIN,
Self::Swift => &SWIFT,
Self::Scala => &SCALA,
Self::Lua => &LUA,
Self::Elixir => &ELIXIR,
Self::Zig => &ZIG,
Self::Bash => &BASH,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn kinds_exist() {
for lang in Lang::ALL {
let language = lang.language();
let g = lang.grammar();
let params = g.params.iter().flat_map(|p| p.lists.iter().chain(p.items));
let kinds = [
g.nesting, g.branches, g.elifs, g.switches, g.cases, g.binaries,
]
.into_iter()
.flatten()
.chain(params)
.filter(|kind| !g.keyword_calls.contains(kind));
for kind in kinds {
assert_ne!(language.id_for_node_kind(kind, true), 0, "{lang:?} {kind}");
}
}
}
}