[−][src]Function comment_parser::get_syntax
pub fn get_syntax<S: AsRef<str>>(
name: S
) -> Option<&'static [SyntaxRule<'static>]>
Given a language name, get syntax rules for a predefined
language included in the crate.
Returns None
if the language is not supported.
In the case of None
, check the following:
- The language
name
must be written in all lower case. - The language
name
must not use special symbols e.g. use"cpp"
not"c++"
.
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.
Example
use comment_parser::get_syntax; assert!(get_syntax("rust").is_some()); assert!(get_syntax("c").is_some()); assert!(get_syntax("cpp").is_some()); assert!(get_syntax("python").is_some());
Custom Syntax Rules
Go to SyntaxRule
for an example on defining
custom syntax rules.