def _drop_syntactic_errors(self, tokens):
        opening_tags = []
        for index, token in enumerate(tokens):
            if token.is_start_tag:
                tag_options = self.bbcodes[token.tag_name]._options
                if tag_options.same_tag_closes and len(opening_tags) > 0 and opening_tags[-1][0].tag_name == token.tag_name:
                    opening_tags.pop()
                if not tag_options.standalone:
                    opening_tags.append((token, index))
            elif token.is_end_tag:
                tag_options = self.bbcodes[token.tag_name]._options
                if len(opening_tags) > 0:
                    previous_tag, _ = opening_tags[-1]
                    previous_tag_options = self.bbcodes[previous_tag.tag_name]._options
                    if previous_tag_options.end_tag_closes:
                        opening_tags.pop()

                    if not opening_tags:
                        continue

                    if (opening_tags[-1][0].tag_name != token.tag_name and
                       token.tag_name in [x[0].tag_name for x in opening_tags] and tag_options.render_embedded):
                        # In this case, we iterate to the first opening of the current tag : all the tags between the current tag
                        # and its opening are converted to textual tokens
                        for tag in reversed(opening_tags):
                            tk, index = tag
                            if tk.tag_name == token.tag_name:
                                opening_tags.pop()
                                break
                            else:
                                tokens[index] = BBCodeToken(BBCodeToken.TK_DATA, None, None, tk.text)
                                opening_tags.pop()
                    elif opening_tags[-1][0].tag_name != token.tag_name:
                        tokens[index] = BBCodeToken(BBCodeToken.TK_DATA, None, None, token.text)
                    else:
                        opening_tags.pop()
                else:
                    tokens[index] = BBCodeToken(BBCodeToken.TK_DATA, None, None, token.text)
            elif token.is_newline:
                if len(opening_tags) > 0:
                    previous_tag, _ = opening_tags[-1]
                else:
                    previous_tag = None
                if previous_tag:
                    previous_tag_options = self.bbcodes[previous_tag.tag_name]._options
                    if previous_tag_options.newline_closes:
                        opening_tags.pop()
        # The remaining tags do not have a closing tag, they must be converted to testual tokens)
        for tag in opening_tags:
            token, index = tag
            tokens[index] = BBCodeToken(BBCodeToken.TK_DATA, None, None, token.text)
        return tokens
Given a list of lexical tokens, find the tags that are not closed or not started
dataset/ETHPy150Open ellmetha/django-precise-bbcode/precise_bbcode/bbcode/parser.py/BBCodeParser._drop_syntactic_errors