[−][src]Struct syntect::parsing::ScopeStack
A stack/sequence of scopes. This is used both to represent hierarchies for a given
token of text, as well as in ScopeSelectors
. Press ctrl+shift+p
in Sublime Text
to see the scope stack at a given point.
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
impl ScopeStack
[src]
pub fn new() -> ScopeStack
[src]
pub fn from_vec(v: Vec<Scope>) -> ScopeStack
[src]
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)
[src]
pub fn pop(&mut self)
[src]
pub fn apply(&mut self, op: &ScopeStackOp)
[src]
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]),
[src]
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.
pub fn debug_print(&self, repo: &ScopeRepository)
[src]
Prints out each scope in the stack separated by spaces and then a newline. Top of the stack at the end.
pub fn bottom_n(&self, n: usize) -> &[Scope]
[src]
Return the bottom n elements of the stack. Equivalent to &scopes[0..n] on a Vec
pub fn as_slice(&self) -> &[Scope]
[src]
Return a slice of the scopes in this stack
pub fn len(&self) -> usize
[src]
Return the height/length of this stack
pub fn is_empty(&self) -> bool
[src]
pub fn does_match(&self, stack: &[Scope]) -> Option<MatchPower>
[src]
checks if this stack as a selector matches the given stack if so it returns a match score, higher match scores are 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.
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
impl Clone for ScopeStack
[src]
fn clone(&self) -> ScopeStack
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for ScopeStack
[src]
impl Default for ScopeStack
[src]
fn default() -> ScopeStack
[src]
impl<'de> Deserialize<'de> for ScopeStack
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for ScopeStack
[src]
impl Eq for ScopeStack
[src]
impl FromStr for ScopeStack
[src]
type Err = ParseScopeError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<ScopeStack, ParseScopeError>
[src]
Parses a scope stack from a whitespace separated list of scopes.
impl PartialEq<ScopeStack> for ScopeStack
[src]
fn eq(&self, other: &ScopeStack) -> bool
[src]
fn ne(&self, other: &ScopeStack) -> bool
[src]
impl Serialize for ScopeStack
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralEq for ScopeStack
[src]
impl StructuralPartialEq for ScopeStack
[src]
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
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<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
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> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,