Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 13 variants InvalidRegex { path: String, error: RegexError, }, EmptyRegex { path: String, }, InvalidScope { path: String, scope: String, offset: usize, reason: &'static str, }, InvalidSelector { path: String, selector: String, offset: usize, reason: &'static str, }, InvalidName { path: String, name: String, reason: &'static str, }, DuplicateRepository { name: String, }, DuplicateInjection { selector: String, }, DuplicateCapture { path: String, group: u32, }, CaptureOutOfRange { path: String, group: u32, groups: u32, }, ShadowedCaptures { path: String, }, UndefinedInclude { path: String, name: String, }, IncludeCycle { cycle: Vec<String>, }, TooDeep { path: String, },
}
Expand description

Why Grammar refused to emit a grammar.

Emitting validates the whole grammar first and reports the first problem. Every variant that has a path locates the problem with a JSON Pointer into the JSON that would have been emitted: /patterns/2/begin, /repository/string/captures/1/name. Repository and injection entries are addressed by name, so a path is the same whatever order the entries were added in.

The checks run in this order: the grammar’s scopeName, fileTypes, firstLineMatch, and injectionSelector; repository names and injection selectors (and their uniqueness); then every rule — the top-level patterns, the repository in name order, the injections in selector order — each checked before the rules nested in it; finally include cycles. Within a rule, its regular expressions are checked first, then its scope names, then its captures.

§Examples

use textmate_lang::{Error, Grammar, Rule};

let grammar = Grammar::new("source.demo").pattern(Rule::include("strings"));
match grammar.to_json() {
    Err(Error::UndefinedInclude { path, name }) => {
        assert_eq!(path, "/patterns/0/include");
        assert_eq!(name, "strings");
    }
    other => panic!("unexpected {other:?}"),
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

InvalidRegex

A regular expression is outside the supported Oniguruma subset; see validate_regex and RegexErrorKind for the fix.

Fields

§path: String

Where the pattern is.

§error: RegexError

The byte offset in the pattern and what is wrong there.

§

EmptyRegex

A match, begin, end, while, or firstLineMatch pattern is empty. An empty pattern matches everywhere without consuming text, which tokenizers either loop on or detect and skip.

Give the pattern something to match; to end a region at once, use a look-ahead such as (?=.) or $.

Fields

§path: String

Where the pattern is.

§

InvalidScope

A scope name is malformed: empty, with an empty segment, with a character outside ASCII letters, digits, _, +, and -, with a malformed $n substitution, or with a substitution where none is allowed (scopeName, external includes).

Scopes are dot-separated segments such as keyword.control.demo; a rule’s name may list several separated by single spaces.

Fields

§path: String

Where the scope is.

§scope: String

The scope as given.

§offset: usize

Byte offset of the problem in scope.

§reason: &'static str

What is wrong.

§

InvalidSelector

A scope selector (injectionSelector or an injections key) is malformed, in the syntax VS Code’s vscode-textmate reads: scopes combined with ,, | (inside parentheses), -, and (...), each top-level entry optionally prefixed with L: or R:.

Fields

§path: String

Where the selector is.

§selector: String

The selector as given.

§offset: usize

Byte offset of the problem in selector.

§reason: &'static str

What is wrong.

§

InvalidName

A repository name (defined or included) or a file type is malformed. Repository names are non-empty ASCII letters, digits, _, -, and .; file types are non-empty.

Fields

§path: String

Where the name is.

§name: String

The name as given.

§reason: &'static str

What is wrong.

§

DuplicateRepository

Two repository entries share a name. The JSON object could hold only one, so the second would silently replace the first.

Fields

§name: String

The name defined more than once.

§

DuplicateInjection

Two injections share a selector.

Fields

§selector: String

The selector given more than once.

§

DuplicateCapture

A captures map sets the same group twice.

Fields

§path: String

The captures map.

§group: u32

The repeated group number.

§

CaptureOutOfRange

A capture or a $n substitution names a group the pattern does not have. For captures on a region, the group must exist in every pattern the captures apply to (begin, and end or while, unless those have their own captures); for a region’s name and contentName, in begin.

Fields

§path: String

Where the capture or the substitution is.

§group: u32

The group named.

§groups: u32

How many groups the pattern has.

§

ShadowedCaptures

A region’s captures can never apply: the region has both beginCaptures and endCaptures (or whileCaptures), which take precedence. Move the captures into those, or remove them.

Fields

§path: String

Where the region is.

§

UndefinedInclude

An include names a repository entry this grammar does not define.

Fields

§path: String

Where the include is.

§name: String

The entry it names.

§

IncludeCycle

Includes form a cycle in which no rule consumes text: an entry that is only a list of patterns (or one include) includes itself through other such entries, or through $self / $base from the top-level patterns. Tokenizers expand these lists when building their scanners and recurse forever: vscode-textmate collects them with a recursion that keeps no record of lists already visited.

Recursion through a region is fine — a begin/end rule whose patterns include the entry that contains it is how nested constructs are written — and so is recursion through captures.

cycle lists the entries on the cycle, $self for the top-level patterns and #name for repository entries, starting and ending with the same one.

Fields

§cycle: Vec<String>

The entries on the cycle.

§

TooDeep

Rules nest more than MAX_RULE_DEPTH deep (regions and captures inside regions and captures). Editors build their rule tables recursively, so a deeper grammar can crash them; use repository entries and includes instead.

Fields

§path: String

Where the limit was crossed.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Eq for Error

Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.