#[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
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
Alias
Alias substitution
This applies to a code fragment that replaced another as a result of alias substitution.
Fields
CommandSubst
Command substitution
Arith
Arithmetic expansion
Eval
Command string executed by the eval
built-in
DotScript
File executed by the .
(source
) built-in
Fields
Trap
Trap command
Fields
VariableValue
Value of a variable
InitFile
File executed during shell startup
Other
Other source
Implementations§
Source§impl Source
impl Source
Sourcepub fn complement_annotations<'a, 's: 'a, T: Extend<Annotation<'a>>>(
&'s self,
result: &mut T,
)
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
impl Source
Sourcepub fn is_alias_for(&self, name: &str) -> bool
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);
Trait Implementations§
impl Eq for 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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