Skip to main content

SyntaxError

Enum SyntaxError 

Source
#[non_exhaustive]
pub enum SyntaxError {
Show 98 variants IncompleteEscape, InvalidEscape, UnclosedParen { opening_location: Location, }, UnclosedSingleQuote { opening_location: Location, }, UnclosedDoubleQuote { opening_location: Location, }, UnclosedDollarSingleQuote { opening_location: Location, }, UnclosedParam { opening_location: Location, }, EmptyParam, InvalidParam, InvalidModifier, MultipleModifier, UnclosedCommandSubstitution { opening_location: Location, }, UnclosedBackquote { opening_location: Location, }, UnclosedArith { opening_location: Location, }, InvalidCommandToken, MissingSeparator, FdOutOfRange, InvalidIoLocation, MissingRedirOperand, MissingHereDocDelimiter, MissingHereDocContent, UnclosedHereDocContent { redir_op_location: Location, }, UnclosedArrayValue { opening_location: Location, }, UnopenedGrouping, UnclosedGrouping { opening_location: Location, }, EmptyGrouping, UnopenedSubshell, UnclosedSubshell { opening_location: Location, }, EmptySubshell, UnopenedLoop, UnopenedDoClause, UnclosedDoClause { opening_location: Location, }, EmptyDoClause, MissingForName, InvalidForName, InvalidForValue, MissingForBody { opening_location: Location, }, UnclosedWhileClause { opening_location: Location, }, EmptyWhileCondition, UnclosedUntilClause { opening_location: Location, }, EmptyUntilCondition, IfMissingThen { if_location: Location, }, EmptyIfCondition, EmptyIfBody, ElifMissingThen { elif_location: Location, }, EmptyElifCondition, EmptyElifBody, EmptyElse, UnopenedIf, UnclosedIf { opening_location: Location, }, MissingCaseSubject, InvalidCaseSubject, MissingIn { opening_location: Location, }, UnclosedPatternList, MissingPattern, InvalidPattern, EsacAsPattern, UnopenedCase, UnclosedCase { opening_location: Location, }, UnmatchedParenthesis, MissingFunctionBody, InvalidFunctionBody, InAsCommandName, CloseBracketBracketAsCommandName, MissingPipeline(AndOr), DoubleNegation, BangAfterBar, MissingCommandAfterBang, MissingCommandAfterBar, RedundantToken, IncompleteControlEscape, IncompleteControlBackslashEscape, InvalidControlEscape, OctalEscapeOutOfRange, IncompleteHexEscape, IncompleteShortUnicodeEscape, IncompleteLongUnicodeEscape, UnicodeEscapeOutOfRange, UnsupportedFunctionDefinitionSyntax, UnsupportedDoubleBracketCommand, UnsupportedNamespaceCommand, UnsupportedSelectCommand, UnsupportedProcessRedirection, UnsupportedArithmeticCommand, UnsupportedExtendedGlob, NonPortableCaseTerminator(Operator), NonPortableRedirOperator(RedirOp), IoTokenAsRedirOperand, MissingSeparatorBeforeReservedWord, ColonSuffixedCommandName, NonPortableEscape, TooLongHexEscape, NonPortableForName, NonPortableFunctionName, NonPortableAssignmentName, ArrayAssignment, SpecialBuiltinFunctionName, NonPortableParamModifier,
}
Expand description

Types of syntax errors

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

IncompleteEscape

A backslash is at the end of the input.

§

InvalidEscape

A backslash is not followed by a character that makes a valid escape.

§

UnclosedParen

A ( lacks a closing ).

Fields

§opening_location: Location
§

UnclosedSingleQuote

A single quotation lacks a closing '.

Fields

§opening_location: Location
§

UnclosedDoubleQuote

A double quotation lacks a closing ".

Fields

§opening_location: Location
§

UnclosedDollarSingleQuote

A $' lacks a closing '.

Fields

§opening_location: Location
§

UnclosedParam

A parameter expansion lacks a closing }.

Fields

§opening_location: Location
§

EmptyParam

A parameter expansion lacks a name.

§

InvalidParam

A parameter expansion has an invalid name.

§

InvalidModifier

A modifier does not have a valid form in a parameter expansion.

§

MultipleModifier

A braced parameter expansion has both a prefix and suffix modifier.

§

UnclosedCommandSubstitution

A command substitution started with $( but lacks a closing ).

Fields

§opening_location: Location
§

UnclosedBackquote

A command substitution started with ` but lacks a closing `.

Fields

§opening_location: Location
§

UnclosedArith

An arithmetic expansion lacks a closing )).

Fields

§opening_location: Location
§

InvalidCommandToken

A command begins with an inappropriate keyword or operator token.

§

MissingSeparator

A separator is missing between commands.

§

FdOutOfRange

The file descriptor specified for a redirection cannot be used.

§

InvalidIoLocation

An I/O location prefix attached to a redirection has an unsupported format.

§

MissingRedirOperand

A redirection operator is missing its operand.

§

MissingHereDocDelimiter

A here-document operator is missing its delimiter token.

§

MissingHereDocContent

A here-document operator is missing its corresponding content.

§

UnclosedHereDocContent

A here-document content is missing its delimiter.

Fields

§redir_op_location: Location
§

UnclosedArrayValue

An array assignment started with =( but lacks a closing ).

Fields

§opening_location: Location
§

UnopenedGrouping

A } appears without a matching {.

§

UnclosedGrouping

A grouping is not closed.

Fields

§opening_location: Location
§

EmptyGrouping

A grouping contains no commands.

§

UnopenedSubshell

A ) appears without a matching (.

§

UnclosedSubshell

A subshell is not closed.

Fields

§opening_location: Location
§

EmptySubshell

A subshell contains no commands.

§

UnopenedLoop

A do appears outside a loop.

§

UnopenedDoClause

A done appears outside a loop.

§

UnclosedDoClause

A do clause is not closed.

Fields

§opening_location: Location
§

EmptyDoClause

A do clause contains no commands.

§

MissingForName

The variable name is missing in a for loop.

§

InvalidForName

The variable name is not a valid word in a for loop.

§

InvalidForValue

A value is not a valid word in a for loop.

§

MissingForBody

A for loop is missing a do clause.

Fields

§opening_location: Location
§

UnclosedWhileClause

A while loop is missing a do clause.

Fields

§opening_location: Location
§

EmptyWhileCondition

A while loop’s condition is empty.

§

UnclosedUntilClause

An until loop is missing a do clause.

Fields

§opening_location: Location
§

EmptyUntilCondition

An until loop’s condition is empty.

§

IfMissingThen

An if command is missing the then clause.

Fields

§if_location: Location
§

EmptyIfCondition

An if command’s condition is empty.

§

EmptyIfBody

An if command’s body is empty.

§

ElifMissingThen

An elif clause is missing the then clause.

Fields

§elif_location: Location
§

EmptyElifCondition

An elif clause’s condition is empty.

§

EmptyElifBody

An elif clause’s body is empty.

§

EmptyElse

An else clause is empty.

§

UnopenedIf

An elif, else, then, or fi appears outside an if command.

§

UnclosedIf

An if command is not closed.

Fields

§opening_location: Location
§

MissingCaseSubject

The case command is missing its subject.

§

InvalidCaseSubject

The subject of the case command is not a valid word.

§

MissingIn

The case command is missing in after the subject.

Fields

§opening_location: Location
§

UnclosedPatternList

The ) is missing in a case item.

§

MissingPattern

The pattern is missing in a case item.

§

InvalidPattern

The pattern is not a valid word token.

§

EsacAsPattern

👎Deprecated since 0.12.1:

this error no longer occurs

The first pattern of a case item is esac.

§

UnopenedCase

An esac or ;; appears outside a case command.

§

UnclosedCase

A case command is not closed.

Fields

§opening_location: Location
§

UnmatchedParenthesis

The ( is not followed by ) in a function definition.

§

MissingFunctionBody

The function body is missing in a function definition command.

§

InvalidFunctionBody

A function body is not a compound command.

§

InAsCommandName

The keyword in is used as a command name.

§

CloseBracketBracketAsCommandName

The keyword ]] is used as a command name.

§

MissingPipeline(AndOr)

A pipeline is missing after a && or || token.

§

DoubleNegation

Two successive ! tokens.

§

BangAfterBar

A | token is followed by a !.

§

MissingCommandAfterBang

A command is missing after a ! token.

§

MissingCommandAfterBar

A command is missing after a | token.

§

RedundantToken

There is a redundant token.

§

IncompleteControlEscape

A control escape (\c...) is incomplete in a dollar-single-quoted string.

§

IncompleteControlBackslashEscape

A control-backslash escape (\c\\) is incomplete in a dollar-single-quoted string.

§

InvalidControlEscape

A control escape (\c...) does not have a valid control character.

§

OctalEscapeOutOfRange

An octal escape is out of range (greater than \377) in a dollar-single-quoted string.

§

IncompleteHexEscape

An hexadecimal escape (\x...) is incomplete in a dollar-single-quoted string.

§

IncompleteShortUnicodeEscape

A Unicode escape (\u...) is incomplete in a dollar-single-quoted string.

§

IncompleteLongUnicodeEscape

A Unicode escape (\U...) is incomplete in a dollar-single-quoted string.

§

UnicodeEscapeOutOfRange

A Unicode escape (\u... or \U...) is out of range in a dollar-single-quoted string.

§

UnsupportedFunctionDefinitionSyntax

The unsupported version of function definition syntax is used.

§

UnsupportedDoubleBracketCommand

A [[ ... ]] command is used.

§

UnsupportedNamespaceCommand

A namespace command is used.

§

UnsupportedSelectCommand

A select command is used.

§

UnsupportedProcessRedirection

A process redirection (>(...) or <(...)) is used.

§

UnsupportedArithmeticCommand

A ((...)) arithmetic command is used at the beginning of a command while the portable option is on.

yash-rs parses (( as nested subshells, but other shells parse it as an arithmetic command, which yash-rs does not support. The portable option rejects this ambiguous form; insert a space (( () for nested subshells.

§

UnsupportedExtendedGlob

A !(...) extended glob is used at the beginning of a command while the portable option is on.

yash-rs parses !( as the ! reserved word followed by a subshell, but other shells parse it as an extended glob, which yash-rs does not support. The portable option rejects this ambiguous form; insert a space (! ().

§

NonPortableCaseTerminator(Operator)

A ;;& or ;| case terminator is used while the portable option is on.

The operator is the offending terminator (SemicolonSemicolonAnd or SemicolonBar).

§

NonPortableRedirOperator(RedirOp)

A non-portable redirection operator (>>| or <<<) is used while the portable option is on.

The operator is the offending redirection operator (Pipe or String).

§

IoTokenAsRedirOperand

An IO_NUMBER or IO_LOCATION token appears as a redirection operand while the portable option is on.

This happens when a token that should be a redirection operand is immediately followed by a redirection operator without a separating space, so yash-rs lexes it as an IO_NUMBER or IO_LOCATION token (as in the 1 in < 1>file). POSIX does not recognize such a token as a redirection operand, so this form is not portable.

§

MissingSeparatorBeforeReservedWord

A reserved word follows a subshell or a redirection without a separator while the portable option is on (as in { ( : ) } or for i in 1; do ( : ) done).

POSIX recognizes a reserved word only when it is the first word of a command or follows another reserved word. A subshell ends with the ) operator and a redirection ends with a word, so a clause-delimiting reserved word (such as }, done, or fi) that immediately follows one is not portably recognized.

§

ColonSuffixedCommandName

A command name ends with a : while the portable option is on.

POSIX reserves words whose final character is a : for possible future use, so such a word produces unspecified results when used where a reserved word would be recognized (such as a command name). The lone : (the colon built-in) is not affected.

§

NonPortableEscape

A non-portable escape sequence is used in a dollar-single-quoted string while the portable option is on.

POSIX specifies a limited set of escape sequences for $'...'. This is raised for yash extensions such as \E, \?, \u, \U, and \c@.

§

TooLongHexEscape

A \x escape in a dollar-single-quoted string is followed by more than two hexadecimal digits while the portable option is on.

POSIX leaves the result unspecified if more than two hexadecimal digits follow \x, so such an escape is not portable.

§

NonPortableForName

A for loop variable name is not a portable name while the portable option is on.

POSIX requires the name to be an unquoted NAME token consisting solely of underscores, digits, and alphabetics from the portable character set, not starting with a digit. This is raised when the name is quoted, contains an expansion, or otherwise does not meet this requirement.

§

NonPortableFunctionName

A function name is not a portable name while the portable option is on.

POSIX requires the name to be an unquoted NAME token consisting solely of underscores, digits, and alphabetics from the portable character set, not starting with a digit. This is raised when the name is quoted, contains an expansion, or otherwise does not meet this requirement.

§

NonPortableAssignmentName

An assignment name is not a portable name while the portable option is on.

A portable name consists solely of underscores, digits, and alphabetics from the portable character set, not starting with a digit. This is raised when the assignment name does not meet this form, since other POSIX-conforming shells may not support it.

§

ArrayAssignment

An array assignment (name=(...)) is used while the portable option is on.

Array assignment is a yash extension that POSIX does not specify, so other POSIX-conforming shells may not support it.

§

SpecialBuiltinFunctionName

A function name is the same as a special built-in utility name while the portable option is on.

POSIX does not allow a function to have the same name as a special built-in utility. See POSIX_SPECIAL_BUILTIN_NAMES for the list of names this applies to.

§

NonPortableParamModifier

A parameter expansion combines a special parameter with a modifier whose result POSIX leaves unspecified, while the portable option is on.

POSIX leaves the result unspecified for a length or switch modifier applied to the special parameter * or @ (as in ${#*} or ${@:-x}), and for a trim modifier applied to the special parameter #, *, or @ (as in ${#%x} or ${*#x}).

Implementations§

Source§

impl SyntaxError

Source

pub fn message(&self) -> &'static str

Returns an error message describing the error.

Source

pub fn label(&self) -> &'static str

Returns a label for annotating the error location.

Source

pub fn footnotes(&self) -> &'static [(FootnoteType, &'static str)]

Returns footnotes that supplement the error message.

Each item pairs a FootnoteType with its text. The footnotes are to be rendered after the error’s source code snippet. The slice is empty for errors that need no footnote.

Source

pub fn related_location(&self) -> Option<(&Location, &'static str)>

Returns a location related with the error cause and a message describing the location.

Trait Implementations§

Source§

impl Clone for SyntaxError

Source§

fn clone(&self) -> SyntaxError

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 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, __formatter: &mut Formatter<'_>) -> Result

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

impl Eq for SyntaxError

Source§

impl Error for SyntaxError

1.30.0 · 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 From<SyntaxError> for ErrorCause

Source§

fn from(source: SyntaxError) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for SyntaxError

Source§

fn eq(&self, other: &SyntaxError) -> 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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