[][src]Struct syntect::parsing::ScopeStack

pub struct ScopeStack {
    pub scopes: Vec<Scope>,
    // some fields omitted
}

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>

Methods

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]

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]

impl Debug for ScopeStack[src]

impl Default for ScopeStack[src]

impl<'de> Deserialize<'de> for ScopeStack[src]

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]

impl Serialize for ScopeStack[src]

impl StructuralEq for ScopeStack[src]

impl StructuralPartialEq for ScopeStack[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.