lib_ruby_parser/
current_arg_stack.rs1use std::cell::RefCell;
2use std::rc::Rc;
3#[derive(Debug, Clone, Default)]
13pub(crate) struct CurrentArgStack {
14 stack: Rc<RefCell<Vec<Option<String>>>>,
15}
16
17impl CurrentArgStack {
18 pub(crate) fn new() -> Self {
19 Self {
20 stack: Rc::new(RefCell::new(vec![])),
21 }
22 }
23
24 pub(crate) fn is_empty(&self) -> bool {
25 self.stack.borrow().is_empty()
26 }
27
28 pub(crate) fn push(&self, value: Option<String>) {
29 self.stack.borrow_mut().push(value)
30 }
31
32 pub(crate) fn set(&self, value: Option<String>) {
33 self.pop();
34 self.push(value)
35 }
36
37 pub(crate) fn pop(&self) {
38 self.stack.borrow_mut().pop();
39 }
40
41 pub(crate) fn top(&self) -> Option<String> {
42 match self.stack.borrow().last() {
43 Some(Some(value)) => Some(value.clone()),
44 _ => None,
45 }
46 }
47}