Struct syntect::parsing::ScopeStack [−][src]
Expand description
A stack/sequence of scopes for representing hierarchies for a given token of text
This is also used within ScopeSelectors
.
In Sublime Text, the scope stack at a given point can be seen by pressing ctrl+shift+p
. Also
see the TextMate docs.
Example for a JS string inside a script tag in a Rails ERB
file:
text.html.ruby text.html.basic source.js.embedded.html string.quoted.double.js
Fields
scopes: Vec<Scope>
Implementations
Note: creating a ScopeStack with this doesn’t contain information
on what to do when clear_scopes
contexts end.
Modifies this stack according to the operation given
Use this to create a stack from a Vec
of changes given by the parser.
pub fn apply_with_hook<F>(&mut self, op: &ScopeStackOp, hook: F) where
F: FnMut(BasicScopeStackOp, &[Scope]),
pub fn apply_with_hook<F>(&mut self, op: &ScopeStackOp, hook: F) where
F: FnMut(BasicScopeStackOp, &[Scope]),
Modifies this stack according to the operation given and calls the hook for each basic operation.
Like apply
but calls hook
for every basic modification (as defined by
BasicScopeStackOp
). Use this to do things only when the scope stack changes.
Prints out each scope in the stack separated by spaces and then a newline. Top of the stack at the end.
Returns the bottom n
elements of the stack.
Equivalent to &scopes[0..n]
on a Vec
Checks if this stack as a selector matches the given stack, returning the match score if so
Higher match scores indicate stronger matches. Scores are ordered according to the rules found at https://manual.macromates.com/en/scope_selectors
It accomplishes this ordering through some floating point math ensuring deeper and longer matches matter. Unfortunately it is only guaranteed to return perfectly accurate results up to stack depths of 17, but it should be reasonably good even afterwards. TextMate has the exact same limitation, dunno about Sublime Text.
Examples
use syntect::parsing::{ScopeStack, MatchPower};
use std::str::FromStr;
assert_eq!(ScopeStack::from_str("a.b c e.f").unwrap()
.does_match(ScopeStack::from_str("a.b c.d e.f.g").unwrap().as_slice()),
Some(MatchPower(0o212u64 as f64)));
assert_eq!(ScopeStack::from_str("a c.d.e").unwrap()
.does_match(ScopeStack::from_str("a.b c.d e.f.g").unwrap().as_slice()),
None);
Trait Implementations
Returns the “default value” for a type. Read more
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Parses a scope stack from a whitespace separated list of scopes.
type Err = ParseScopeError
type Err = ParseScopeError
The associated error which can be returned from parsing.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for ScopeStack
impl Send for ScopeStack
impl Sync for ScopeStack
impl Unpin for ScopeStack
impl UnwindSafe for ScopeStack
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.