MCPcopy Create free account
hub / github.com/davidblewett/rure-python / pop_group_end

Method pop_group_end

regex/regex-syntax/src/ast/parse.rs:791–824  ·  view source on GitHub ↗

Pop the last state from the parser's internal stack, if it exists, and add the given concatenation to it. There either must be no state or a single alternation item on the stack. Any other scenario produces an error. This assumes that the parser has advanced to the end.

(&self, mut concat: ast::Concat)

Source from the content-addressed store, hash-verified

789 ///
790 /// This assumes that the parser has advanced to the end.
791 fn pop_group_end(&self, mut concat: ast::Concat) -> Result<Ast> {
792 concat.span.end = self.pos();
793 let mut stack = self.parser().stack_group.borrow_mut();
794 let ast = match stack.pop() {
795 None => Ok(concat.into_ast()),
796 Some(GroupState::Alternation(mut alt)) => {
797 alt.span.end = self.pos();
798 alt.asts.push(concat.into_ast());
799 Ok(Ast::Alternation(alt))
800 }
801 Some(GroupState::Group { group, .. }) => {
802 return Err(self.error(
803 group.span,
804 ast::ErrorKind::GroupUnclosed,
805 ));
806 }
807 };
808 // If we try to pop again, there should be nothing.
809 match stack.pop() {
810 None => ast,
811 Some(GroupState::Alternation(_)) => {
812 // This unreachable is unfortunate. This case can't happen
813 // because the only way we can be here is if there were two
814 // `GroupState::Alternation`s adjacent in the parser's stack,
815 // which we guarantee to never happen because we never push a
816 // `GroupState::Alternation` if one is already at the top of
817 // the stack.
818 unreachable!()
819 }
820 Some(GroupState::Group { group, .. }) => {
821 Err(self.error(group.span, ast::ErrorKind::GroupUnclosed))
822 }
823 }
824 }
825
826 /// Parse the opening of a character class and push the current class
827 /// parsing context onto the parser's stack. This assumes that the parser

Callers 1

parse_with_commentsMethod · 0.80

Calls 7

AlternationClass · 0.85
parserMethod · 0.80
posMethod · 0.45
popMethod · 0.45
into_astMethod · 0.45
pushMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected