Struct syntect::parsing::ScopeStack
source · pub struct ScopeStack {
pub scopes: Vec<Scope>,
/* private fields */
}
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§
source§impl ScopeStack
impl ScopeStack
pub fn new() -> ScopeStack
sourcepub fn from_vec(v: Vec<Scope>) -> ScopeStack
pub fn from_vec(v: Vec<Scope>) -> ScopeStack
Note: creating a ScopeStack with this doesn’t contain information
on what to do when clear_scopes
contexts end.
pub fn push(&mut self, s: Scope)
pub fn pop(&mut self)
sourcepub fn apply(&mut self, op: &ScopeStackOp) -> Result<(), ScopeError>
pub fn apply(&mut self, op: &ScopeStackOp) -> Result<(), ScopeError>
Modifies this stack according to the operation given
Use this to create a stack from a Vec
of changes given by the parser.
sourcepub fn apply_with_hook<F>(
&mut self,
op: &ScopeStackOp,
hook: F
) -> Result<(), ScopeError>where
F: FnMut(BasicScopeStackOp, &[Scope]),
pub fn apply_with_hook<F>( &mut self, op: &ScopeStackOp, hook: F ) -> Result<(), ScopeError>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.
sourcepub fn debug_print(&self, repo: &ScopeRepository)
pub fn debug_print(&self, repo: &ScopeRepository)
Prints out each scope in the stack separated by spaces and then a newline. Top of the stack at the end.
sourcepub fn bottom_n(&self, n: usize) -> &[Scope]
pub fn bottom_n(&self, n: usize) -> &[Scope]
Returns the bottom n
elements of the stack.
Equivalent to &scopes[0..n]
on a Vec
pub fn is_empty(&self) -> bool
sourcepub fn does_match(&self, stack: &[Scope]) -> Option<MatchPower>
pub fn does_match(&self, stack: &[Scope]) -> Option<MatchPower>
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§
source§impl Clone for ScopeStack
impl Clone for ScopeStack
source§fn clone(&self) -> ScopeStack
fn clone(&self) -> ScopeStack
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ScopeStack
impl Debug for ScopeStack
source§impl Default for ScopeStack
impl Default for ScopeStack
source§fn default() -> ScopeStack
fn default() -> ScopeStack
source§impl<'de> Deserialize<'de> for ScopeStack
impl<'de> Deserialize<'de> for ScopeStack
source§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>,
source§impl Display for ScopeStack
impl Display for ScopeStack
source§impl FromStr for ScopeStack
impl FromStr for ScopeStack
source§fn from_str(s: &str) -> Result<ScopeStack, ParseScopeError>
fn from_str(s: &str) -> Result<ScopeStack, ParseScopeError>
Parses a scope stack from a whitespace separated list of scopes.
§type Err = ParseScopeError
type Err = ParseScopeError
source§impl PartialEq<ScopeStack> for ScopeStack
impl PartialEq<ScopeStack> for ScopeStack
source§fn eq(&self, other: &ScopeStack) -> bool
fn eq(&self, other: &ScopeStack) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for ScopeStack
impl Serialize for ScopeStack
impl Eq for ScopeStack
impl StructuralEq for ScopeStack
impl StructuralPartialEq for ScopeStack
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§
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.