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

pub struct ParseState { /* fields omitted */ }
Expand description

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

Creates a state from a syntax definition, keeping its own reference-counted point to the main context of the syntax

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

Compare self to key and return true if they are equal.

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)

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.