#[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
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.
HoleKind
A hole used in positions of two different kinds (${x} as an
expression and as a pattern).
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.