SYNTAX_SET

Struct SYNTAX_SET 

Source
struct SYNTAX_SET {
    __private_field: (),
}

Fields§

§__private_field: ()

Methods from Deref<Target = SyntaxSet>§

Source

pub fn syntaxes(&self) -> &[SyntaxReference]

The list of syntaxes in the set

Source

pub fn find_syntax_by_scope(&self, scope: Scope) -> Option<&SyntaxReference>

Finds a syntax by its default scope, for example source.regexp finds the regex syntax.

This and all similar methods below do a linear search of syntaxes, this should be fast because there aren’t many syntaxes, but don’t think you can call it a bajillion times per second.

Source

pub fn find_syntax_by_name<'a>( &'a self, name: &str, ) -> Option<&'a SyntaxReference>

Source

pub fn find_syntax_by_extension<'a>( &'a self, extension: &str, ) -> Option<&'a SyntaxReference>

Source

pub fn find_syntax_by_token<'a>( &'a self, s: &str, ) -> Option<&'a SyntaxReference>

Searches for a syntax first by extension and then by case-insensitive name

This is useful for things like Github-flavoured-markdown code block highlighting where all you have to go on is a short token given by the user

Source

pub fn find_syntax_by_first_line<'a>( &'a self, s: &str, ) -> Option<&'a SyntaxReference>

Try to find the syntax for a file based on its first line

This uses regexes that come with some sublime syntax grammars for matching things like shebangs and mode lines like -*- Mode: C -*-

Source

pub fn find_syntax_by_path<'a>( &'a self, path: &str, ) -> Option<&'a SyntaxReference>

Searches for a syntax by it’s original file path when it was first loaded from disk

This is primarily useful for syntax tests. Some may specify a Packages/PackageName/SyntaxName.sublime-syntax path, and others may just have SyntaxName.sublime-syntax. This caters for these by matching the end of the path of the loaded syntax definition files

Source

pub fn find_syntax_for_file<P>( &self, path_obj: P, ) -> Result<Option<&SyntaxReference>, Error>
where P: AsRef<Path>,

Convenience method that tries to find the syntax for a file path, first by extension/name and then by first line of the file if that doesn’t work.

May IO Error because it sometimes tries to read the first line of the file.

§Examples

When determining how to highlight a file, use this in combination with a fallback to plain text:

use syntect::parsing::SyntaxSet;
let ss = SyntaxSet::load_defaults_newlines();
let syntax = ss.find_syntax_for_file("testdata/highlight_test.erb")
    .unwrap() // for IO errors, you may want to use try!() or another plain text fallback
    .unwrap_or_else(|| ss.find_syntax_plain_text());
assert_eq!(syntax.name, "HTML (Rails)");
Source

pub fn find_syntax_plain_text(&self) -> &SyntaxReference

Finds a syntax for plain text, which usually has no highlighting rules.

This is good as a fallback when you can’t find another syntax but you still want to use the same highlighting pipeline code.

This syntax should always be present, if not this method will panic. If the way you load syntaxes doesn’t create one, use add_plain_text_syntax.

§Examples
use syntect::parsing::SyntaxSetBuilder;
let mut builder = SyntaxSetBuilder::new();
builder.add_plain_text_syntax();
let ss = builder.build();
let syntax = ss.find_syntax_by_token("rs").unwrap_or_else(|| ss.find_syntax_plain_text());
assert_eq!(syntax.name, "Plain Text");
Source

pub fn find_unlinked_contexts(&self) -> BTreeSet<String>

Trait Implementations§

Source§

impl Deref for SYNTAX_SET

Source§

type Target = SyntaxSet

The resulting type after dereferencing.
Source§

fn deref(&self) -> &SyntaxSet

Dereferences the value.
Source§

impl LazyStatic for SYNTAX_SET

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more