use std::{cell::Cell, collections::BTreeMap, sync::Arc}; use crate::common::{Identifier, ListSeparator}; use super::Value; #[derive(Debug, Clone)] pub struct ArgList { pub elems: Vec, were_keywords_accessed: Arc>, // todo: special wrapper around this field to avoid having to make it private? keywords: BTreeMap, 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, were_keywords_accessed: Arc>, keywords: BTreeMap, 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 { self.elems.len() } pub fn is_empty(&self) -> bool { self.len() == 0 } pub fn is_blank(&self) -> bool { !self.is_empty() && (self.elems.iter().all(Value::is_blank)) } pub fn keywords(&self) -> &BTreeMap { (*self.were_keywords_accessed).set(true); &self.keywords } pub fn into_keywords(self) -> BTreeMap { (*self.were_keywords_accessed).set(true); self.keywords } }