[−][src]Struct synoptic::highlighter::Highlighter
For performing highlighting operations
You can create a new Highlighter instance using the new
method
let mut h = Highlighter::new();
Fields
regex: HashMap<&'static str, Vec<Regex>>
multiline_regex: HashMap<&'static str, Vec<Regex>>
Implementations
impl Highlighter
[src]
#[must_use]pub fn new() -> Self
[src]
This will create a new, blank highlighter instance
pub fn join(
&mut self,
regex: &[&'static str],
token: &'static str
) -> Result<(), ReError>
[src]
&mut self,
regex: &[&'static str],
token: &'static str
) -> Result<(), ReError>
This method allows you to add multiple definitions to the highlighter The first argument is for your list of definitions and the second is for the name This is useful for adding lists of keywords, for example:
let mut python = Highlighter::new(); python.join(&["def", "return", "import"], "keyword");
For multiline tokens, you can add (?ms) or (?sm) to the beginning
Errors
This will return an error if one or more of your regex expressions are invalid
pub fn add(
&mut self,
regex: &'static str,
token: &'static str
) -> Result<(), ReError>
[src]
&mut self,
regex: &'static str,
token: &'static str
) -> Result<(), ReError>
This method allows you to add a single definition to the highlighter The first argument is for your definition and the second is for the name This is useful for adding things like regular expressions, for example:
let mut python = Highlighter::new(); python.add("[0-9]+", "number");
For multiline tokens, you can add (?ms) or (?sm) to the beginning
Errors
This will return an error if your regex is invalid
pub fn run(&mut self, code: &'static str) -> Vec<Vec<Token>>
[src]
This is the method that you call to get the stream of tokens The argument is the string with the code that you wish to highlight This will return a vector of a vector of tokens, representing the lines and the tokens in them
let mut python = Highlighter::new(); python.add("[0-9]+", "number"); python.run("some numbers: 123");
This example will highlight the numbers 123
in the string
Trait Implementations
impl Default for Highlighter
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Highlighter
[src]
impl Send for Highlighter
[src]
impl Sync for Highlighter
[src]
impl Unpin for Highlighter
[src]
impl UnwindSafe for Highlighter
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,