file_identify/
interpreters.rs

1use crate::tags::{TagSet, tags_from_array};
2use phf::phf_map;
3
4// Interpreter mappings using Perfect Hash Functions for compile-time optimization.
5
6static INTERPRETER_TAGS: phf::Map<&'static str, &'static [&'static str]> = phf_map! {
7    "ash" => &["shell", "ash"],
8    "awk" => &["awk"],
9    "bash" => &["shell", "bash"],
10    "bats" => &["shell", "bash", "bats"],
11    "cbsd" => &["shell", "cbsd"],
12    "csh" => &["shell", "csh"],
13    "dash" => &["shell", "dash"],
14    "expect" => &["expect"],
15    "ksh" => &["shell", "ksh"],
16    "node" => &["javascript"],
17    "nodejs" => &["javascript"],
18    "perl" => &["perl"],
19    "php" => &["php"],
20    "php7" => &["php", "php7"],
21    "php8" => &["php", "php8"],
22    "python" => &["python"],
23    "python2" => &["python", "python2"],
24    "python3" => &["python", "python3"],
25    "ruby" => &["ruby"],
26    "sh" => &["shell", "sh"],
27    "tcsh" => &["shell", "tcsh"],
28    "zsh" => &["shell", "zsh"],
29};
30
31/// Get tags for a given interpreter using compile-time optimized lookup.
32pub fn get_interpreter_tags(interpreter: &str) -> TagSet {
33    INTERPRETER_TAGS
34        .get(interpreter)
35        .map(|&tags| tags_from_array(tags))
36        .unwrap_or_default()
37}