Skip to main content

Grammar

Struct Grammar 

Source
pub struct Grammar {
    pub name: String,
    pub scope_name: String,
    pub scopes: Vec<String>,
    pub kind: GrammarKind,
    /* private fields */
}
Expand description

Immutable compiled grammar data.

Fields§

§name: String

Human-readable grammar name.

§scope_name: String

Root scope name.

§scopes: Vec<String>

Interned scope names used by this grammar.

§kind: GrammarKind

Tokenization strategy used by this grammar.

Implementations§

Source§

impl Grammar

Source

pub fn compile(raw: &RawGrammar) -> Result<Self, Error>

Compiles a raw grammar.

Source

pub fn plain_text() -> Self

Builds a grammar with no patterns for plain text fallback.

Source

pub fn json() -> Self

Builds the dedicated fast JSON grammar.

This does not use the recursive TextMate tokenizer. It emits the same kind of ScopeSpan values as compiled grammars while scanning each line directly.

Source

pub fn matches_name(&self, name: &str) -> bool

Returns true when this grammar matches a syntax name or alias.

Source

pub fn matches_path(&self, path: &Path) -> bool

Returns true when this grammar matches a file path.

Source

pub fn matches_first_line(&self, line: &str) -> bool

Returns true when this grammar matches the first source line.

Source

pub fn tokenize_line(&self, state: &mut LineState, line: &str) -> Vec<ScopeSpan>

Tokenizes one line, mutating the caller-owned line state.

Source

pub fn tokenize_line_into( &self, state: &mut LineState, line: &str, spans: &mut Vec<ScopeSpan>, )

Tokenizes one line into a caller-owned buffer.

Trait Implementations§

Source§

impl Debug for Grammar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Grammar

Source§

fn from_str(input: &str) -> Result<Self, Self::Err>

Parses and compiles a grammar from JSON.

Source§

type Err = Error

The associated error which can be returned from parsing.

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.