[−][src]Function comment_parser::get_syntax_from_path
pub fn get_syntax_from_path<P: AsRef<Path>>(
path: P
) -> Result<&'static [SyntaxRule<'static>], LanguageError>
Given a Path
, get syntax rules for a predefined
language included in the crate.
The language is identified from the path extension, and
the casing of the extension does not affect the result.
Note that get_syntax_from_path
does not check if the path exists,
nor does it attempt to load the file.
See also get_syntax_from_extension
.
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_path("foo.rs").is_ok()); assert!(get_syntax_from_path("foo.c").is_ok()); assert!(get_syntax_from_path("foo.h").is_ok()); assert!(get_syntax_from_path("foo.cpp").is_ok()); assert!(get_syntax_from_path("foo.hpp").is_ok()); assert!(get_syntax_from_path("foo.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.