Struct scribe::buffer::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]
fn new() -> ScopeStack
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.
fn push(&mut self, s: Scope)
fn pop(&mut self)
fn apply(&mut self, op: &ScopeStackOp)
Modifies this stack according to the operation given
use this to create a stack from a Vec
of changes
given by the parser.
fn apply_with_hook<F>(&mut self, op: &ScopeStackOp, hook: F) where
F: FnMut(BasicScopeStackOp, &[Scope]) -> (),
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.
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.
fn bottom_n(&self, n: usize) -> &[Scope]
Return the bottom n elements of the stack. Equivalent to &scopes[0..n] on a Vec
fn as_slice(&self) -> &[Scope]
Return a slice of the scopes in this stack
fn len(&self) -> usize
Return the height/length of this stack
fn is_empty(&self) -> bool
fn does_match(&self, stack: &[Scope]) -> Option<MatchPower>
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 Display for ScopeStack
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl Default for ScopeStack
[src]
fn default() -> ScopeStack
impl FromStr for ScopeStack
[src]
type Err = ParseScopeError
fn from_str(s: &str) -> Result<ScopeStack, ParseScopeError>
Parses a scope stack from a whitespace separated list of scopes.
impl Eq for ScopeStack
[src]
impl<'de> Deserialize<'de> for ScopeStack
[src]
fn deserialize<__D>(
__deserializer: __D
) -> Result<ScopeStack, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
__deserializer: __D
) -> Result<ScopeStack, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
impl Debug for ScopeStack
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl PartialEq<ScopeStack> for ScopeStack
[src]
fn eq(&self, __arg_0: &ScopeStack) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &ScopeStack) -> bool
This method tests for !=
.
impl Serialize for ScopeStack
[src]
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
impl Clone for ScopeStack
[src]
fn clone(&self) -> ScopeStack
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more