Enum yash_syntax::source::Source
source · [−]#[non_exhaustive]
pub enum Source {
Unknown,
Stdin,
Alias {
original: Location,
alias: Rc<Alias>,
},
CommandSubst {
original: Location,
},
Trap {
condition: String,
origin: Location,
},
}
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.
Alias
Fields
original: Location
Position of the original word that was replaced
Alias substitution.
This applies to a code fragment that replaced another as a result of alias substitution.
CommandSubst
Fields
original: Location
Command substitution.
Trap
Fields
condition: String
Trap condition name, typically the signal name.
origin: Location
Location of the simple command that has set this trap command.
Trap command.
Implementations
sourceimpl 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.
sourceimpl 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 mut 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: original.clone(), alias};
let alias = Rc::new(yash_syntax::alias::Alias{
name: "bar".to_string(),
replacement: "".to_string(),
global: false,
origin: original.clone()
});
Rc::make_mut(&mut original.code).source = 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 StructuralEq for Source
impl StructuralPartialEq for Source
Auto Trait Implementations
impl !RefUnwindSafe for Source
impl !Send for Source
impl !Sync for Source
impl Unpin for Source
impl !UnwindSafe for Source
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more