synoptic

Struct Highlighter

Source
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: usize

How many spaces a tab character should be

Implementations§

Source§

impl Highlighter

Source

pub fn new(tab_width: usize) -> Self

Creates a new highlighter

Source

pub fn keyword<S: Into<String>>(&mut self, name: S, exp: &str)

Register a new keyword token, provide its name and regex

Source

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

Source

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

Source

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.

Source

pub fn append(&mut self, line: &String)

Appends a line to the highlighter.

Source

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())
Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Highlighter

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Highlighter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.