forked from extern/nushell
Add "fall-through" signatures (#7527)
Fixes https://github.com/nushell/nushell/issues/4659 Fixes https://github.com/nushell/nushell/issues/5294 Fixes https://github.com/nushell/nushell/issues/6124 fix https://github.com/nushell/nushell/issues/5103
This commit is contained in:
@ -7,6 +7,7 @@ use crate::{DeclId, Span, Spanned};
|
||||
pub enum Argument {
|
||||
Positional(Expression),
|
||||
Named((Spanned<String>, Option<Spanned<String>>, Option<Expression>)),
|
||||
Unknown(Expression), // unknown argument used in "fall-through" signatures
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
@ -36,6 +37,7 @@ impl Call {
|
||||
self.arguments.iter().filter_map(|arg| match arg {
|
||||
Argument::Named(named) => Some(named),
|
||||
Argument::Positional(_) => None,
|
||||
Argument::Unknown(_) => None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -46,6 +48,7 @@ impl Call {
|
||||
self.arguments.iter_mut().filter_map(|arg| match arg {
|
||||
Argument::Named(named) => Some(named),
|
||||
Argument::Positional(_) => None,
|
||||
Argument::Unknown(_) => None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -64,10 +67,15 @@ impl Call {
|
||||
self.arguments.push(Argument::Positional(positional));
|
||||
}
|
||||
|
||||
pub fn add_unknown(&mut self, unknown: Expression) {
|
||||
self.arguments.push(Argument::Unknown(unknown));
|
||||
}
|
||||
|
||||
pub fn positional_iter(&self) -> impl Iterator<Item = &Expression> {
|
||||
self.arguments.iter().filter_map(|arg| match arg {
|
||||
Argument::Named(_) => None,
|
||||
Argument::Positional(positional) => Some(positional),
|
||||
Argument::Unknown(unknown) => Some(unknown),
|
||||
})
|
||||
}
|
||||
|
||||
@ -75,6 +83,7 @@ impl Call {
|
||||
self.arguments.iter_mut().filter_map(|arg| match arg {
|
||||
Argument::Named(_) => None,
|
||||
Argument::Positional(positional) => Some(positional),
|
||||
Argument::Unknown(unknown) => Some(unknown),
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user