# Path: wikitextparser/_wikitext.py
# class SubWikiText(WikiText):
#     """Define a class to be inherited by some subclasses of WikiText.
# 
#     Allow to focus on a particular part of WikiText.
#     """
# 
#     __slots__ = '_type'
# 
#     def __init__(
#         self,
#         string: Union[str, MutableSequence[str]],
#         _type_to_spans: Optional[Dict[str, List[List[int]]]] = None,
#         _span: Optional[List[int]] = None,
#         _type: Optional[Union[str, int]] = None,
#     ) -> None:
#         """Initialize the object."""
#         if _type is None:
#             # assert _span is None
#             # assert _type_to_spans is None
#             self._type = _type = type(self).__name__
#             super().__init__(string)
#         else:
#             # assert _span is not None
#             # assert _type_to_spans is not None
#             self._type = _type
#             super().__init__(string, _type_to_spans)
#             self._span_data = _span
# 
#     def _subspans(self, _type: str) -> Generator[int, None, None]:
#         """Yield all the sub-span indices excluding self._span."""
#         ss, se, _, _ = self._span_data
#         spans = self._type_to_spans[_type]
#         # Do not yield self._span by bisecting for s < ss.
#         # The second bisect is an optimization and should be on [se + 1],
#         # but empty spans are not desired thus [se] is used.
#         b = bisect_left(spans, [ss])
#         for span in spans[b:bisect_right(spans, [se], b)]:
#             if span[1] <= se:
#                 yield span
# 
#     # noinspection PyProtectedMember
#     def ancestors(self, type_: Optional[str] = None) -> List['WikiText']:
#         """Return the ancestors of the current node.
# 
#         :param type_: the type of the desired ancestors as a string.
#             Currently the following types are supported: {Template,
#             ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
#             The default is None and means all the ancestors of any type above.
#         """
#         if type_ is None:
#             types = SPAN_PARSER_TYPES
#         else:
#             types = type_,
#         lststr = self._lststr
#         type_to_spans = self._type_to_spans
#         ss, se, _, _ = self._span_data
#         ancestors = []
#         ancestors_append = ancestors.append
#         for type_ in types:
#             cls = globals()[type_]
#             spans = type_to_spans[type_]
#             for span in spans[:bisect_right(spans, [ss])]:
#                 if se < span[1]:
#                     ancestors_append(cls(lststr, type_to_spans, span, type_))
#         return sorted(ancestors, key=lambda i: ss - i._span_data[0])
# 
#     def parent(self, type_: Optional[str] = None) -> Optional['WikiText']:
#         """Return the parent node of the current object.
# 
#         :param type_: the type of the desired parent object.
#             Currently the following types are supported: {Template,
#             ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
#             The default is None and means the first parent, of any type above.
#         :return: parent WikiText object or None if no parent with the desired
#             `type_` is found.
#         """
#         ancestors = self.ancestors(type_)
#         if ancestors:
#             return ancestors[0]
#         return None


from typing import Dict, List, MutableSequence, Optional, Union
from regex import DOTALL, MULTILINE, compile as regex_compile
from ._wikitext import SubWikiText


COMMENT_PATTERN = r'<!--[\s\S]*?(?>-->|\Z)'
COMMA_COMMENT = "'(?>" + COMMENT_PATTERN + ")*+"
COMMENT_COMMA = "(?>" + COMMENT_PATTERN + ")*+'"
BOLD_FULLMATCH = regex_compile(
    COMMA_COMMENT * 2 + "'(.*?)(?>'" + COMMENT_COMMA * 2 + "|$)",
    MULTILINE | DOTALL).fullmatch
ITALIC_FULLMATCH = regex_compile(
    COMMA_COMMENT + "'(.*?)(?>'" + COMMENT_COMMA + "|$)", DOTALL).fullmatch
ITALIC_NOEND_FULLMATCH = regex_compile(
    COMMA_COMMENT + "'(.*)", DOTALL).fullmatch


class Comment(SubWikiText):
    __slots__ = ()

    @property
    def contents(self) -> str:
        """Return contents of this comment."""
        s = self.string
        if s[-3:] == '-->':
            return s[4:-3]
        return s[4:]

    @property
    def comments(self) -> List['Comment']:
        return []



# Path: wikitextparser/_wikitext.py
# class SubWikiText(WikiText):
#     """Define a class to be inherited by some subclasses of WikiText.
# 
#     Allow to focus on a particular part of WikiText.
#     """
# 
#     __slots__ = '_type'
# 
#     def __init__(
#         self,
#         string: Union[str, MutableSequence[str]],
#         _type_to_spans: Optional[Dict[str, List[List[int]]]] = None,
#         _span: Optional[List[int]] = None,
#         _type: Optional[Union[str, int]] = None,
#     ) -> None:
#         """Initialize the object."""
#         if _type is None:
#             # assert _span is None
#             # assert _type_to_spans is None
#             self._type = _type = type(self).__name__
#             super().__init__(string)
#         else:
#             # assert _span is not None
#             # assert _type_to_spans is not None
#             self._type = _type
#             super().__init__(string, _type_to_spans)
#             self._span_data = _span
# 
#     def _subspans(self, _type: str) -> Generator[int, None, None]:
#         """Yield all the sub-span indices excluding self._span."""
#         ss, se, _, _ = self._span_data
#         spans = self._type_to_spans[_type]
#         # Do not yield self._span by bisecting for s < ss.
#         # The second bisect is an optimization and should be on [se + 1],
#         # but empty spans are not desired thus [se] is used.
#         b = bisect_left(spans, [ss])
#         for span in spans[b:bisect_right(spans, [se], b)]:
#             if span[1] <= se:
#                 yield span
# 
#     # noinspection PyProtectedMember
#     def ancestors(self, type_: Optional[str] = None) -> List['WikiText']:
#         """Return the ancestors of the current node.
# 
#         :param type_: the type of the desired ancestors as a string.
#             Currently the following types are supported: {Template,
#             ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
#             The default is None and means all the ancestors of any type above.
#         """
#         if type_ is None:
#             types = SPAN_PARSER_TYPES
#         else:
#             types = type_,
#         lststr = self._lststr
#         type_to_spans = self._type_to_spans
#         ss, se, _, _ = self._span_data
#         ancestors = []
#         ancestors_append = ancestors.append
#         for type_ in types:
#             cls = globals()[type_]
#             spans = type_to_spans[type_]
#             for span in spans[:bisect_right(spans, [ss])]:
#                 if se < span[1]:
#                     ancestors_append(cls(lststr, type_to_spans, span, type_))
#         return sorted(ancestors, key=lambda i: ss - i._span_data[0])
# 
#     def parent(self, type_: Optional[str] = None) -> Optional['WikiText']:
#         """Return the parent node of the current object.
# 
#         :param type_: the type of the desired parent object.
#             Currently the following types are supported: {Template,
#             ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
#             The default is None and means the first parent, of any type above.
#         :return: parent WikiText object or None if no parent with the desired
#             `type_` is found.
#         """
#         ancestors = self.ancestors(type_)
#         if ancestors:
#             return ancestors[0]
#         return None


# Path: wikitextparser/_comment_bold_italic.py
from typing import Dict, List, MutableSequence, Optional, Union
from regex import DOTALL, MULTILINE, compile as regex_compile
from ._wikitext import SubWikiText



COMMENT_PATTERN = r'<!--[\s\S]*?(?>-->|\Z)'
COMMA_COMMENT = "'(?>" + COMMENT_PATTERN + ")*+"
COMMENT_COMMA = "(?>" + COMMENT_PATTERN + ")*+'"
BOLD_FULLMATCH = regex_compile(
    COMMA_COMMENT * 2 + "'(.*?)(?>'" + COMMENT_COMMA * 2 + "|$)",
    MULTILINE | DOTALL).fullmatch
ITALIC_FULLMATCH = regex_compile(
    COMMA_COMMENT + "'(.*?)(?>'" + COMMENT_COMMA + "|$)", DOTALL).fullmatch
ITALIC_NOEND_FULLMATCH = regex_compile(
    COMMA_COMMENT + "'(.*)", DOTALL).fullmatch


class Comment(SubWikiText):
    __slots__ = ()

    @property
    def contents(self) -> str:
        """Return contents of this comment."""
        s = self.string
        if s[-3:] == '-->':
            return s[4:-3]
        return s[4:]

    @property
    def comments(self) -> List['Comment']:
        return []



class BoldItalic(SubWikiText):