big-code-analysis 2.0.0

Tool to compute and export code metrics
Documentation
//! Per-language tree-sitter token enums.
//!
//! Every `language_*.rs` module under this directory is generated by
//! the `enums/` codegen crate from `enums/templates/rust.rs`. Each
//! module declares one enum per grammar — one variant per tree-sitter
//! token kind — plus a `From<u16>` / `PartialEq<u16>` set of impls
//! whose match expressions enumerate every variant.
//!
//! Two pedantic clippy lints fire systemically on those generated
//! matches and are silenced via a per-file `#![allow(...)]` block in
//! each generated module:
//!
//! - `match_same_arms` — distinct token variants frequently share the
//!   same conversion arm, but collapsing them via `|` would obscure
//!   the per-language token set, which is the point of these files.
//! - `too_many_lines` — the conversion match is one expression
//!   spanning hundreds of lines for any non-trivial grammar.
//!
//! Hand-written modules that *consume* these enums via `use Foo::*`
//! patterns (`src/getter.rs`, `src/checker.rs`, `src/alterator.rs`,
//! per-metric impls under `src/metrics/`) carry their own file-level
//! `#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]`
//! because explicit imports would list dozens of variants per match
//! arm and obscure the per-language token sets in those files.

#![allow(clippy::enum_variant_names)]

pub mod language_ccomment;
pub use language_ccomment::*;

pub mod language_bash;
pub use language_bash::*;

pub mod language_c;
pub use language_c::*;

pub mod language_cpp;
pub use language_cpp::*;

pub mod language_mozcpp;
pub use language_mozcpp::*;

pub mod language_csharp;
pub use language_csharp::*;

pub mod language_elixir;
pub use language_elixir::*;

pub mod language_go;
pub use language_go::*;

pub mod language_groovy;
pub use language_groovy::*;

pub mod language_irules;
pub use language_irules::*;

pub mod language_java;
pub use language_java::*;

pub mod language_kotlin;
pub use language_kotlin::*;

pub mod language_lua;
pub use language_lua::*;

pub mod language_mozjs;
pub use language_mozjs::*;

pub mod language_javascript;
pub use language_javascript::*;

pub mod language_objc;
pub use language_objc::*;

pub mod language_perl;
pub use language_perl::*;

pub mod language_php;
pub use language_php::*;

pub mod language_python;
pub use language_python::*;

pub mod language_ruby;
pub use language_ruby::*;

pub mod language_rust;
pub use language_rust::*;

pub mod language_tcl;
pub use language_tcl::*;

pub mod language_tsx;
pub use language_tsx::*;

pub mod language_typescript;
pub use language_typescript::*;

pub mod language_preproc;
pub use language_preproc::*;

#[cfg(test)]
mod tests {
    use super::*;

    // #954: Tcl is the only grammar with an `error` keyword (variant
    // `Tcl::Error`, display "error"), so the tree-sitter ERROR sentinel
    // is renamed to `Tcl::Error2` (display "ERROR"). The generated
    // `From<u16>` fallback for an out-of-range id must yield that
    // sentinel, never the keyword — otherwise an unknown/error node is
    // silently misclassified as a valid `error` command token. This
    // pins the runtime contract every language module upholds against a
    // Tcl-only regression of the generator template.
    #[test]
    fn tcl_from_u16_out_of_range_maps_to_error_sentinel() {
        let fallback = Tcl::from(u16::MAX);
        assert_eq!(fallback, Tcl::Error2);
        assert_ne!(fallback, Tcl::Error);
        assert_eq!(<&'static str>::from(fallback), "ERROR");
        assert_eq!(<&'static str>::from(Tcl::Error), "error");
    }

    // A grammar with no `error` keyword (Rust) keeps the plain `Error`
    // sentinel name, so its fallback is unaffected — confirming the fix
    // is scoped to the genuine clash and did not perturb other languages.
    #[test]
    fn rust_from_u16_out_of_range_maps_to_plain_error_sentinel() {
        assert_eq!(<&'static str>::from(Rust::from(u16::MAX)), "ERROR");
    }
}