pub fn language_from_string(lang_str: &str) -> Option<Language>
Expand description
Convert a string representation to a Language enum
This function parses various string representations of programming
language names and returns the corresponding Language
enum value.
The parsing is case-insensitive and supports multiple aliases for
each language.
§Arguments
lang_str
- String representation of the language name
§Returns
Some(Language)
if the string is recognized, None
otherwise.
§Supported Aliases
- Python: “python”, “py”
- Rust: “rust”, “rs”
- JavaScript: “javascript”, “js”
- TypeScript: “typescript”, “ts”
- C++: “cpp”, “c++”, “cxx”
- C#: “csharp”, “c#”, “cs”
- And many more…
§Examples
use tree_parser::{language_from_string, Language};
assert_eq!(language_from_string("python"), Some(Language::Python));
assert_eq!(language_from_string("RUST"), Some(Language::Rust));
assert_eq!(language_from_string("js"), Some(Language::JavaScript));
assert_eq!(language_from_string("unknown"), None);