tok_grammar/ast/complete_command.rs
1use super::*;
2
3#[derive(Debug, PartialEq)]
4pub struct CompleteCommand<'a> {
5 pub and_ors: Vec<(TermOp, AndOr<'a>)>,
6}
7
8impl<'a> CompleteCommand<'a> {
9 pub fn push(mut self, op: TermOp, element: AndOr<'a>) -> CompleteCommand<'a> {
10 // update the TermOp of the previous list entry
11 self.update_last(op);
12 // add the new entry and assume it ends with a semicolon
13 self.and_ors.push((TermOp::Semi, element));
14 self
15 }
16
17 pub fn update_last(&mut self, op: TermOp) {
18 if let Some((_, e)) = self.and_ors.pop() {
19 self.and_ors.push((op, e));
20 }
21 }
22}