Jakub Žádník
2022-12-22 00:33:26 +02:00
committed by GitHub
parent 440feaf74a
commit 757d7479af
13 changed files with 379 additions and 151 deletions

View File

@ -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),
})
}

View File

@ -118,6 +118,7 @@ pub struct Signature {
pub allow_variants_without_examples: bool,
pub is_filter: bool,
pub creates_scope: bool,
pub allows_unknown_args: bool,
// Signature category used to classify commands stored in the list of declarations
pub category: Category,
}
@ -220,6 +221,7 @@ impl Signature {
is_filter: false,
creates_scope: false,
category: Category::Default,
allows_unknown_args: false,
}
}
@ -274,6 +276,12 @@ impl Signature {
self
}
/// Allow unknown signature parameters
pub fn allows_unknown_args(mut self) -> Signature {
self.allows_unknown_args = true;
self
}
/// Add a required positional argument to the signature
pub fn required(
mut self,