Accept idents as KW args (#6644)
Support kw arg/local variable shorthand Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -59,7 +59,9 @@ impl Arg {
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct KwArgs {
|
||||
/// Unlabeled keyword args. Currently only the first arg can be unlabeled.
|
||||
pub unlabeled: Option<Arg>,
|
||||
/// If the argument was a local variable, then the first element of the tuple is its name
|
||||
/// which may be used to treat this arg as a labelled arg.
|
||||
pub unlabeled: Option<(Option<String>, Arg)>,
|
||||
/// Labeled args.
|
||||
pub labeled: IndexMap<String, Arg>,
|
||||
pub errors: Vec<Arg>,
|
||||
@ -342,6 +344,7 @@ impl Args {
|
||||
self.kw_args
|
||||
.unlabeled
|
||||
.as_ref()
|
||||
.map(|(_, a)| a)
|
||||
.or(self.args.first())
|
||||
.or(self.pipe_value.as_ref())
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ async fn call_map_closure(
|
||||
ctxt: &ExecutorContext,
|
||||
) -> Result<KclValue, KclError> {
|
||||
let kw_args = KwArgs {
|
||||
unlabeled: Some(Arg::new(input, source_range)),
|
||||
unlabeled: Some((None, Arg::new(input, source_range))),
|
||||
labeled: Default::default(),
|
||||
errors: Vec::new(),
|
||||
};
|
||||
@ -104,7 +104,7 @@ async fn call_reduce_closure(
|
||||
let mut labeled = IndexMap::with_capacity(1);
|
||||
labeled.insert("accum".to_string(), Arg::new(accum, source_range));
|
||||
let kw_args = KwArgs {
|
||||
unlabeled: Some(Arg::new(elem, source_range)),
|
||||
unlabeled: Some((None, Arg::new(elem, source_range))),
|
||||
labeled,
|
||||
errors: Vec::new(),
|
||||
};
|
||||
|
@ -424,7 +424,7 @@ async fn make_transform<T: GeometryTrait>(
|
||||
meta: vec![source_range.into()],
|
||||
};
|
||||
let kw_args = KwArgs {
|
||||
unlabeled: Some(Arg::new(repetition_num, source_range)),
|
||||
unlabeled: Some((None, Arg::new(repetition_num, source_range))),
|
||||
labeled: Default::default(),
|
||||
errors: Vec::new(),
|
||||
};
|
||||
|
Reference in New Issue
Block a user