Pop a group AST from the parser's internal stack and set the group's AST to the given concatenation. Return the concatenation containing the group. This assumes that the parser is currently positioned on the closing parenthesis and advances the parser to the character following the `)`. If no such group could be popped, then an unopened group error is returned.
(&self, mut group_concat: ast::Concat)
| 735 | /// If no such group could be popped, then an unopened group error is |
| 736 | /// returned. |
| 737 | fn pop_group(&self, mut group_concat: ast::Concat) -> Result<ast::Concat> { |
| 738 | use self::GroupState::*; |
| 739 | |
| 740 | assert_eq!(self.char(), ')'); |
| 741 | let mut stack = self.parser().stack_group.borrow_mut(); |
| 742 | let (mut prior_concat, mut group, ignore_whitespace, alt) = |
| 743 | match stack.pop() { |
| 744 | Some(Group { concat, group, ignore_whitespace }) => { |
| 745 | (concat, group, ignore_whitespace, None) |
| 746 | } |
| 747 | Some(Alternation(alt)) => { |
| 748 | match stack.pop() { |
| 749 | Some(Group { concat, group, ignore_whitespace }) => { |
| 750 | (concat, group, ignore_whitespace, Some(alt)) |
| 751 | } |
| 752 | None | Some(Alternation(_)) => { |
| 753 | return Err(self.error( |
| 754 | self.span_char(), |
| 755 | ast::ErrorKind::GroupUnopened, |
| 756 | )); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | None => { |
| 761 | return Err(self.error( |
| 762 | self.span_char(), |
| 763 | ast::ErrorKind::GroupUnopened, |
| 764 | )); |
| 765 | } |
| 766 | }; |
| 767 | self.parser().ignore_whitespace.set(ignore_whitespace); |
| 768 | group_concat.span.end = self.pos(); |
| 769 | self.bump(); |
| 770 | group.span.end = self.pos(); |
| 771 | match alt { |
| 772 | Some(mut alt) => { |
| 773 | alt.span.end = group_concat.span.end; |
| 774 | alt.asts.push(group_concat.into_ast()); |
| 775 | group.ast = Box::new(alt.into_ast()); |
| 776 | } |
| 777 | None => { |
| 778 | group.ast = Box::new(group_concat.into_ast()); |
| 779 | } |
| 780 | } |
| 781 | prior_concat.asts.push(Ast::Group(group)); |
| 782 | Ok(prior_concat) |
| 783 | } |
| 784 | |
| 785 | /// Pop the last state from the parser's internal stack, if it exists, and |
| 786 | /// add the given concatenation to it. There either must be no state or a |