Struct syntect::parsing::ParseState
source · pub struct ParseState { /* private fields */ }
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§
source§impl ParseState
impl ParseState
sourcepub fn new(syntax: &SyntaxReference) -> ParseState
pub fn new(syntax: &SyntaxReference) -> ParseState
Creates a state from a syntax definition, keeping its own reference-counted point to the main context of the syntax
sourcepub fn parse_line(
&mut self,
line: &str,
syntax_set: &SyntaxSet
) -> Result<Vec<(usize, ScopeStackOp)>, ParsingError>
pub fn parse_line( &mut self, line: &str, syntax_set: &SyntaxSet ) -> Result<Vec<(usize, ScopeStackOp)>, ParsingError>
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§
source§impl Clone for ParseState
impl Clone for ParseState
source§fn clone(&self) -> ParseState
fn clone(&self) -> ParseState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ParseState
impl Debug for ParseState
source§impl PartialEq<ParseState> for ParseState
impl PartialEq<ParseState> for ParseState
source§fn eq(&self, other: &ParseState) -> bool
fn eq(&self, other: &ParseState) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for ParseState
impl StructuralEq for ParseState
impl StructuralPartialEq for ParseState
Auto Trait Implementations§
impl RefUnwindSafe for ParseState
impl !Send for ParseState
impl !Sync for ParseState
impl Unpin for ParseState
impl UnwindSafe for ParseState
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.