big_code_analysis_ast/languages/mod.rs
1//! Per-language tree-sitter token enums.
2//!
3//! Every `language_*.rs` module under this directory is generated by
4//! the `enums/` codegen crate from `enums/templates/rust.rs`. Each
5//! module declares one enum per grammar — one variant per tree-sitter
6//! token kind — plus a `From<u16>` / `PartialEq<u16>` set of impls
7//! whose match expressions enumerate every variant.
8//!
9//! Two pedantic clippy lints fire systemically on those generated
10//! matches and are silenced via a per-file `#![allow(...)]` block in
11//! each generated module:
12//!
13//! - `match_same_arms` — distinct token variants frequently share the
14//! same conversion arm, but collapsing them via `|` would obscure
15//! the per-language token set, which is the point of these files.
16//! - `too_many_lines` — the conversion match is one expression
17//! spanning hundreds of lines for any non-trivial grammar.
18//!
19//! Hand-written modules that *consume* these enums via `use Foo::*`
20//! patterns (`src/getter.rs`, `src/checker.rs`, `src/alterator.rs`,
21//! per-metric impls under `src/metrics/`) carry their own file-level
22//! `#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]`
23//! because explicit imports would list dozens of variants per match
24//! arm and obscure the per-language token sets in those files.
25
26#![allow(clippy::enum_variant_names)]
27
28pub mod language_ccomment;
29pub use language_ccomment::*;
30
31pub mod language_bash;
32pub use language_bash::*;
33
34pub mod language_c;
35pub use language_c::*;
36
37pub mod language_cpp;
38pub use language_cpp::*;
39
40pub mod language_mozcpp;
41pub use language_mozcpp::*;
42
43pub mod language_csharp;
44pub use language_csharp::*;
45
46pub mod language_elixir;
47pub use language_elixir::*;
48
49pub mod language_go;
50pub use language_go::*;
51
52pub mod language_groovy;
53pub use language_groovy::*;
54
55pub mod language_irules;
56pub use language_irules::*;
57
58pub mod language_java;
59pub use language_java::*;
60
61pub mod language_kotlin;
62pub use language_kotlin::*;
63
64pub mod language_lua;
65pub use language_lua::*;
66
67pub mod language_mozjs;
68pub use language_mozjs::*;
69
70pub mod language_javascript;
71pub use language_javascript::*;
72
73pub mod language_objc;
74pub use language_objc::*;
75
76pub mod language_perl;
77pub use language_perl::*;
78
79pub mod language_php;
80pub use language_php::*;
81
82pub mod language_python;
83pub use language_python::*;
84
85pub mod language_ruby;
86pub use language_ruby::*;
87
88pub mod language_rust;
89pub use language_rust::*;
90
91pub mod language_tcl;
92pub use language_tcl::*;
93
94pub mod language_tsx;
95pub use language_tsx::*;
96
97pub mod language_typescript;
98pub use language_typescript::*;
99
100pub mod language_preproc;
101pub use language_preproc::*;
102
103#[cfg(test)]
104mod tests {
105 use super::*;
106
107 // #954: Tcl is the only grammar with an `error` keyword (variant
108 // `Tcl::Error`, display "error"), so the tree-sitter ERROR sentinel
109 // is renamed to `Tcl::Error2` (display "ERROR"). The generated
110 // `From<u16>` fallback for an out-of-range id must yield that
111 // sentinel, never the keyword — otherwise an unknown/error node is
112 // silently misclassified as a valid `error` command token. This
113 // pins the runtime contract every language module upholds against a
114 // Tcl-only regression of the generator template.
115 #[test]
116 fn tcl_from_u16_out_of_range_maps_to_error_sentinel() {
117 let fallback = Tcl::from(u16::MAX);
118 assert_eq!(fallback, Tcl::Error2);
119 assert_ne!(fallback, Tcl::Error);
120 assert_eq!(<&'static str>::from(fallback), "ERROR");
121 assert_eq!(<&'static str>::from(Tcl::Error), "error");
122 }
123
124 // A grammar with no `error` keyword (Rust) keeps the plain `Error`
125 // sentinel name, so its fallback is unaffected — confirming the fix
126 // is scoped to the genuine clash and did not perturb other languages.
127 #[test]
128 fn rust_from_u16_out_of_range_maps_to_plain_error_sentinel() {
129 assert_eq!(<&'static str>::from(Rust::from(u16::MAX)), "ERROR");
130 }
131}