Struct synoptic::highlighter::Highlighter[][src]

pub struct Highlighter {
    pub regex: HashMap<String, Vec<Regex>>,
    pub multiline_regex: HashMap<String, Vec<Regex>>,
}
Expand description

For performing highlighting operations You can create a new Highlighter instance using the new method

let mut h = Highlighter::new();

Fields

regex: HashMap<String, Vec<Regex>>multiline_regex: HashMap<String, Vec<Regex>>

Implementations

This will create a new, blank highlighter instance

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

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

This is the method that you call to get the stream of tokens for a specific line. The first argument is the string with the code that you wish to highlight.
the second argument is the line number that you wish to highlight. It returns a vector of tokens which can be used to highlight the individual line

let mut lua = Highlighter::new();
lua.add("(?ms)[[.*?]]", "string");
lua.add("print", "keyword");
lua.run_line(r#"
print ([[ Hello World!
]])
"#, 2);

This example will return the second line, with the ]] marked as a string The advantage of using this over the run method is that it is a lot faster This is because it only has to render one line rather than all of them, saving time

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 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

This is a function that will convert from a stream of tokens into a token option type A token option type is nicer to work with for certain formats such as HTML

This is a function that will convert from a tokopt slice to a token stream A token stream is easier to render for certain formats such as the command line

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.