Skip to main content

SyntaxError

Enum SyntaxError 

Source
#[non_exhaustive]
pub enum SyntaxError {
Show 21 variants TooLong, TooDeep, UnexpectedChar, Unterminated, BadEscape, BadNumber, Expected(&'static str), UnknownName, BinderId, UnknownOp, BadPolicy, Arity { expected: usize, found: usize, }, HoleKind { first: HoleKind, here: HoleKind, }, HoleSuffix, HoleDefault, SpliceHere, BoundTwice, UnknownLabel, UnknownTemplate, ApplyArgs, Unsupported(&'static str),
}
Expand description

What is wrong with a template text. Carried by TemplateError::Syntax together with the byte range it is about.

§Examples

use lower_lang::{SyntaxError, Template, TemplateError};

let err = Template::parse("t", "add(1)").unwrap_err();
let TemplateError::Syntax { at, error } = err else { unreachable!() };
assert_eq!(error, SyntaxError::Arity { expected: 2, found: 1 });
assert_eq!((at.start().to_usize(), at.end().to_usize()), (0, 3));

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

TooLong

The text is longer than MAX_TEMPLATE_TEXT. Split the template, or build it with TemplateBuilder.

§

TooDeep

Nesting is deeper than MAX_TEMPLATE_DEPTH. Flatten the template (name intermediate values with let).

§

UnexpectedChar

A character that starts no token (templates are ASCII outside string literals).

§

Unterminated

A string, character literal, or hole that is not closed.

§

BadEscape

An unknown escape sequence in a string or character literal.

§

BadNumber

A malformed number, or one that does not fit i64 / a finite f64.

§

Expected(&'static str)

Something else was expected here; the payload says what.

§

UnknownName

A name that is neither a binder in scope nor an operation. Free names are written global:name, host symbols extern:name.

§

BinderId

A binder written with an id (x%0): template binders are written without one and are fresh per instantiation.

§

UnknownOp

An operation name that OPS does not define, or a conversion without its target type (int_cast<i32>(x)).

§

BadPolicy

A policy the operation does not consult, an unknown policy value, a repeated policy, or a target type on an operation that takes none.

§

Arity

An operation with the wrong number of operands.

Fields

§expected: usize

The operation’s arity.

§found: usize

The operands written.

§

HoleKind

A hole used in positions of two different kinds (${x} as an expression and as a pattern).

Fields

§first: HoleKind

The kind of its first use.

§here: HoleKind

The kind of this use.

§

HoleSuffix

Two uses of a hole give it different ? / ?=default suffixes.

§

HoleDefault

A default on a hole that cannot have one (only expression holes take ?=<literal>), or a default that is not a literal.

§

SpliceHere

An argument splice ${...name} outside a call’s arguments, a tuple’s or array’s elements, or a block’s statements.

§

BoundTwice

One pattern (or one closure’s parameters) binds the same name twice.

§

UnknownLabel

A label that no enclosing loop or block of the template defines.

§

UnknownTemplate

apply:<name> names no template registered before this one.

§

ApplyArgs

apply:<name>(...) arguments do not fit the applied template’s holes (too many, a required one missing, or the wrong kind).

§

Unsupported(&'static str)

A construct the template subset does not have; the payload names it.

Trait Implementations§

Source§

impl Clone for SyntaxError

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 Copy for SyntaxError

Source§

impl Debug for SyntaxError

Source§

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

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

impl Display for SyntaxError

Source§

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

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

impl Eq for SyntaxError

Source§

impl PartialEq for SyntaxError

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 SyntaxError

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