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

pub struct ScopeStack { /* 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

Methods

impl ScopeStack
[src]

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.

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.

Return the bottom n elements of the stack. Equivalent to &scopes[0..n] on a Vec

Return a slice of the scopes in this stack

Return the height/length of this stack

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 Debug for ScopeStack
[src]

Formats the value using the given formatter.

impl Clone for ScopeStack
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for ScopeStack
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for ScopeStack
[src]

impl Default for ScopeStack
[src]

Returns the "default value" for a type. Read more

impl FromStr for ScopeStack
[src]

The associated error which can be returned from parsing.

Parses a scope stack from a whitespace separated list of scopes.

impl Display for ScopeStack
[src]

Formats the value using the given formatter. Read more