Enum Source

Source
#[non_exhaustive]
pub enum Source {
Show 13 variants Unknown, Stdin, CommandString, CommandFile { path: String, }, Alias { original: Location, alias: Rc<Alias>, }, CommandSubst { original: Location, }, Arith { original: Location, }, Eval { original: Location, }, DotScript { name: String, origin: Location, }, Trap { condition: String, origin: Location, }, VariableValue { name: String, }, InitFile { path: String, }, Other { label: String, },
}
Expand description

Origin of source code

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

Unknown

Source code of unknown origin

Normally you should not use this value, but it may be useful for quick debugging.

§

Stdin

Standard input

§

CommandString

Command string specified with the -c option on the shell startup

§

CommandFile

File specified on the shell startup

Fields

§path: String
§

Alias

Alias substitution

This applies to a code fragment that replaced another as a result of alias substitution.

Fields

§original: Location

Position of the original word that was replaced

§alias: Rc<Alias>

Definition of the alias that was substituted

§

CommandSubst

Command substitution

Fields

§original: Location
§

Arith

Arithmetic expansion

Fields

§original: Location
§

Eval

Command string executed by the eval built-in

Fields

§original: Location
§

DotScript

File executed by the . (source) built-in

Fields

§name: String

Pathname of the file

§origin: Location

Location of the simple command that invoked the . built-in

§

Trap

Trap command

Fields

§condition: String

Trap condition name, typically the signal name

§origin: Location

Location of the simple command that has set this trap command

§

VariableValue

Value of a variable

Fields

§name: String

Variable name

§

InitFile

File executed during shell startup

Fields

§path: String
§

Other

Other source

Fields

§label: String

Label that describes the source

Implementations§

Source§

impl Source

Source

pub fn complement_annotations<'a, 's: 'a, T: Extend<Annotation<'a>>>( &'s self, result: &mut T, )

Appends complementary annotations describing this source.

Source§

impl Source

Source

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

Tests if this source is alias substitution for the given name.

Returns true if self is Source::Alias with the name or such an original, recursively.

// `is_alias_for` returns false for sources other than an Alias
assert_eq!(Source::Unknown.is_alias_for("foo"), false);
// `is_alias_for` returns true if the names match
let original = Location::dummy("");
let alias = std::rc::Rc::new(yash_syntax::alias::Alias {
    name: "foo".to_string(),
    replacement: "".to_string(),
    global: false,
    origin: original.clone()
});
let source = Source::Alias { original, alias };
assert_eq!(source.is_alias_for("foo"), true);
assert_eq!(source.is_alias_for("bar"), false);
// `is_alias_for` checks aliases recursively.
let original = Location::dummy("");
let alias = Rc::new(yash_syntax::alias::Alias {
    name: "foo".to_string(),
    replacement: "".to_string(),
    global: false,
    origin: original.clone(),
});
let source = Source::Alias { original, alias };
let alias = Rc::new(yash_syntax::alias::Alias {
    name: "bar".to_string(),
    replacement: "".to_string(),
    global: false,
    origin: Location::dummy(""),
});
let mut original = Location::dummy("");
Rc::make_mut(&mut original.code).source = Rc::new(source);
let source = Source::Alias { original, alias };
assert_eq!(source.is_alias_for("foo"), true);
assert_eq!(source.is_alias_for("bar"), true);
assert_eq!(source.is_alias_for("baz"), false);
Source

pub fn label(&self) -> &str

Returns a label that describes the source.

Trait Implementations§

Source§

impl Clone for Source

Source§

fn clone(&self) -> Source

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Source

Source§

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

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

impl PartialEq for Source

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Source

Source§

impl StructuralPartialEq for Source

Auto Trait Implementations§

§

impl Freeze for Source

§

impl !RefUnwindSafe for Source

§

impl !Send for Source

§

impl !Sync for Source

§

impl Unpin for Source

§

impl !UnwindSafe for Source

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