[−][src]Struct syntect::parsing::ParseState
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.
Methods
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]
&mut self,
line: &str,
syntax_set: &SyntaxSet
) -> Vec<(usize, ScopeStackOp)>
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]
fn clone(&self) -> ParseState
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for ParseState
[src]
impl Eq for ParseState
[src]
impl PartialEq<ParseState> for ParseState
[src]
fn eq(&self, other: &ParseState) -> bool
[src]
fn ne(&self, other: &ParseState) -> bool
[src]
impl StructuralEq for ParseState
[src]
impl StructuralPartialEq for ParseState
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,