pub struct Highlighter {
pub atoms: Vec<Vec<Atom>>,
pub atom_def: Vec<AtomDef>,
pub bounded_def: Vec<BoundedDef>,
pub line_ref: Vec<Vec<usize>>,
pub tokens: Vec<TokenRef>,
pub tab_width: usize,
/* private fields */
}Expand description
This is the main struct that will highlight your document
Fields§
§atoms: Vec<Vec<Atom>>The list of atoms, encapsulated within an inner vector for atoms on the same line
atom_def: Vec<AtomDef>The list of atom definitions to be used at atomization
bounded_def: Vec<BoundedDef>The list of bounded definitions to be used at tokenization
line_ref: Vec<Vec<usize>>A reference to what tokens lie on which line numbers
tokens: Vec<TokenRef>A list of the resulting tokens generated from run and append
tab_width: usizeHow many spaces a tab character should be
Implementations§
Source§impl Highlighter
impl Highlighter
Sourcepub fn keyword<S: Into<String>>(&mut self, name: S, exp: &str)
pub fn keyword<S: Into<String>>(&mut self, name: S, exp: &str)
Register a new keyword token, provide its name and regex
Sourcepub fn bounded<S: Into<String>>(
&mut self,
name: S,
start: S,
end: S,
escapable: bool,
)
pub fn bounded<S: Into<String>>( &mut self, name: S, start: S, end: S, escapable: bool, )
Register a new bounded token, with a start and end, e.g. a multiline comment having starting /* and an ending */ to delimit it The last argument is a boolean when true, tokens can be escaped with a backslash e.g. “"” would be a string of a quote
Sourcepub fn bounded_interp<S: Into<String>>(
&mut self,
name: S,
start: S,
end: S,
i_start: S,
i_end: S,
escapable: bool,
)
pub fn bounded_interp<S: Into<String>>( &mut self, name: S, start: S, end: S, i_start: S, i_end: S, escapable: bool, )
Register a new interpolatable bounded token, with a start and end, e.g. a string as a bounded token, but allowing substitution between {} The last argument is a boolean when true, tokens can be escaped with a backslash e.g. “"” would be a string of a quote
Sourcepub fn run(&mut self, lines: &Vec<String>)
pub fn run(&mut self, lines: &Vec<String>)
Do an initial pass on a vector of lines.
Note that this will overwrite any existing information, use append to add extra lines to the document.
Sourcepub fn line(&self, y: usize, line: &String) -> Vec<TokOpt>
pub fn line(&self, y: usize, line: &String) -> Vec<TokOpt>
Once you have called the run or append methods, you can use this function to retrieve individual lines by providing the original line text and the y index.
§Example
let highlighter = Highlighter::new(4); // Tab ('\t') has a display width of 4
highlighter.keyword("kw", "keyword"); // All occurances of "keyword" will be classed as a token of "kw"
highlighter.run(vec![
"this is a keyword".to_string(),
"second line!".to_string()
]);
// Get the TokOpt for the first line
highlighter.line(0, &"this is a keyword".to_string())
// Get the TokOpt for the second line
highlighter.line(1, &"second line!".to_string())Sourcepub fn edit(&mut self, y: usize, line: &String)
pub fn edit(&mut self, y: usize, line: &String)
Whenever a character is deleted or inserted on a line, call this function to update any tokens.
Sourcepub fn insert_line(&mut self, y: usize, line: &String)
pub fn insert_line(&mut self, y: usize, line: &String)
Whenever a line is inserted into the document, call this function to update any tokens.
Sourcepub fn remove_line(&mut self, y: usize)
pub fn remove_line(&mut self, y: usize)
Whenever a line is removed from a document, call this function to update any tokens.
Trait Implementations§
Source§impl Clone for Highlighter
impl Clone for Highlighter
Source§fn clone(&self) -> Highlighter
fn clone(&self) -> Highlighter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Highlighter
impl RefUnwindSafe for Highlighter
impl Send for Highlighter
impl Sync for Highlighter
impl Unpin for Highlighter
impl UnwindSafe for Highlighter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)