[][src]Struct syntect::parsing::ParseState

pub struct ParseState { /* fields omitted */ }

Keeps the current parser state (the internal syntax interpreter stack) between lines of parsing. If you are parsing an entire file you create one of these at the start and use it all the way to the end.

Caching

One reason this is exposed is that since it implements Clone you can actually cache these (probably along with a HighlightState) and only re-start parsing from the point of a change. See the docs for HighlightState for more in-depth discussion of caching.

This state doesn't keep track of the current scope stack and parsing only returns changes to this stack so if you want to construct scope stacks you'll need to keep track of that as well. Note that HighlightState contains exactly this as a public field that you can use.

Note: Caching is for advanced users who have tons of time to maximize performance or want to do so eventually. It is not recommended that you try caching the first time you implement highlighting.

Implementations

impl ParseState[src]

pub fn new(syntax: &SyntaxReference) -> ParseState[src]

Create a state from a syntax, keeps its own reference counted pointer to the main context of the syntax.

pub fn parse_line(
    &mut self,
    line: &str,
    syntax_set: &SyntaxSet
) -> Vec<(usize, ScopeStackOp)>
[src]

Parses a single line of the file. Because of the way regex engines work you unfortunately have to pass in a single line contiguous in memory. This can be bad for really long lines. Sublime Text avoids this by just not highlighting lines that are too long (thousands of characters).

For efficiency reasons this returns only the changes to the current scope at each point in the line. You can use ScopeStack#apply on each operation in succession to get the stack for a given point. Look at the code in highlighter.rs for an example of doing this for highlighting purposes.

The returned vector is in order both by index to apply at (the usize) and also by order to apply them at a given index (e.g popping old scopes before pushing new scopes).

The SyntaxSet has to be the one that contained the syntax that was used to construct this ParseState, or an extended version of it. Otherwise the parsing would return the wrong result or even panic. The reason for this is that contexts within the SyntaxSet are referenced via indexes.

Trait Implementations

impl Clone for ParseState[src]

impl Debug for ParseState[src]

impl Eq for ParseState[src]

impl PartialEq<ParseState> for ParseState[src]

impl StructuralEq for ParseState[src]

impl StructuralPartialEq for ParseState[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.