[−][src]Function comment_parser::get_syntax_from_extension
pub fn get_syntax_from_extension<S: AsRef<str>>(
extension: S
) -> Result<&'static [SyntaxRule<'static>], LanguageError>
Given a file extension
, get syntax rules for a predefined
language included in the crate.
The casing of the extension
does not affect the result.
See also get_syntax_from_path
.
Supported Languages
If syntax rules for a language does not exist, then consider
trying another language, which has similar syntax rules when
it comes to comments and strings. For instance c
vs cpp
or
css
vs scss
.
Click here to see all predefined languages.
Go to SyntaxRule
for an example on defining
custom syntax rules.
Example
assert!(get_syntax_from_extension("rs").is_ok()); assert!(get_syntax_from_extension("c").is_ok()); assert!(get_syntax_from_extension("h").is_ok()); assert!(get_syntax_from_extension("cpp").is_ok()); assert!(get_syntax_from_extension("hpp").is_ok()); assert!(get_syntax_from_extension("py").is_ok());
Unsupported Syntax Rules
If you get UnsupportedLanguage
that means
the language was identified by detect-lang, but syntax rules are not
included and predefined in comment-parser for the language.
If syntax rules for a language does not exist then feel free to submit an issue on the issue tracker, or add it to languages.rs and submit a pull request.
Unknown Language
If you get UnknownLanguage
that means the language is not supported,
by the sister crate detect-lang.
Feel free to submit an issue on the issue tracker, or add it
to languages.rs and submit a pull request.