monkslc / hyperpolyglot

A fast programming language detector
Apache License 2.0
56 stars 13 forks source link

Use enums for languages and use it in `Definition` #15

Open Boscop opened 1 month ago

Boscop commented 1 month ago
pub enum Detection {
    Filename(&'static str),
    Extension(&'static str),
    Shebang(&'static str),
    Heuristics(&'static str),
    Classifier(&'static str),
}

From the docs it's not clear which values this string can have! It would be a nicer & more idiomatic & stable API if the set of possible languages was represented as an enum. Then we could easily match on that, to map it to syntax highlighters, markdown codeblock-language-indicator-abbreviations etc.

And it would also be more ergonomic if Detection had separate fields for language and detection method. E.g.:

pub struct Detection {
  pub language: Language, // The new enum
  pub method: DetectionMethod, // Separate enum
}