2022-12-26 15:33:04 -05:00
|
|
|
use std::{cell::Cell, collections::BTreeMap, sync::Arc};
|
|
|
|
|
|
|
|
use crate::common::{Identifier, ListSeparator};
|
|
|
|
|
|
|
|
use super::Value;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
2023-02-18 15:05:51 -05:00
|
|
|
pub struct ArgList {
|
2022-12-26 15:33:04 -05:00
|
|
|
pub elems: Vec<Value>,
|
|
|
|
were_keywords_accessed: Arc<Cell<bool>>,
|
|
|
|
// todo: special wrapper around this field to avoid having to make it private?
|
|
|
|
keywords: BTreeMap<Identifier, Value>,
|
|
|
|
pub separator: ListSeparator,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for ArgList {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.elems == other.elems
|
|
|
|
&& self.keywords == other.keywords
|
|
|
|
&& self.separator == other.separator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for ArgList {}
|
|
|
|
|
|
|
|
impl ArgList {
|
|
|
|
pub fn new(
|
|
|
|
elems: Vec<Value>,
|
|
|
|
were_keywords_accessed: Arc<Cell<bool>>,
|
|
|
|
keywords: BTreeMap<Identifier, Value>,
|
|
|
|
separator: ListSeparator,
|
|
|
|
) -> Self {
|
|
|
|
debug_assert!(
|
|
|
|
!(*were_keywords_accessed).get(),
|
|
|
|
"expected args to initialize with unaccessed keywords"
|
|
|
|
);
|
|
|
|
|
|
|
|
Self {
|
|
|
|
elems,
|
|
|
|
were_keywords_accessed,
|
|
|
|
keywords,
|
|
|
|
separator,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn len(&self) -> usize {
|
2023-01-03 04:09:42 +00:00
|
|
|
self.elems.len()
|
2022-12-26 15:33:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
self.len() == 0
|
|
|
|
}
|
|
|
|
|
2023-01-07 04:17:05 +00:00
|
|
|
pub fn is_blank(&self) -> bool {
|
|
|
|
!self.is_empty() && (self.elems.iter().all(Value::is_blank))
|
2022-12-26 15:33:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn keywords(&self) -> &BTreeMap<Identifier, Value> {
|
|
|
|
(*self.were_keywords_accessed).set(true);
|
|
|
|
&self.keywords
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn into_keywords(self) -> BTreeMap<Identifier, Value> {
|
|
|
|
(*self.were_keywords_accessed).set(true);
|
|
|
|
self.keywords
|
|
|
|
}
|
|
|
|
}
|