# Path: wikitextparser/_config.py
# def _plant_trie(strings: _Iterable[str]) -> dict:
# def _pattern(trie: dict) -> str:
# def regex_pattern(words: _Iterable[str]) -> bytes:
# _HTML_TAG_NAME = regex_pattern(_valid_html_tag_names) + br'\b'


from functools import partial
from typing import Callable, Dict, Optional
from regex import DOTALL, REVERSE, compile as regex_compile, IGNORECASE
from ._config import (
    _HTML_TAG_NAME, _bare_external_link_schemes, _parsable_tag_extensions,
    _parser_functions, _unparsable_tag_extensions, regex_pattern)



# According to https://www.mediawiki.org/wiki/Manual:$wgLegalTitleChars
# illegal title characters are: r'[]{}|#<>[\u0000-\u0020]'
VALID_TITLE_CHARS = rb'[^\1-\6\|\{\}\[\]<>\n]++'
# Parser functions
# According to https://www.mediawiki.org/wiki/Help:Magic_words
# See also:
# https://translatewiki.net/wiki/MediaWiki:Sp-translate-data-MagicWords/fa
ARGS = rb'(?:\|(?>[^{}]++|{(?!{)|}(?!}))*+)?+'
PF_TL_FINDITER = regex_compile(  # noqa
    rb'\{\{(?>'
        rb'[\s\0]*+'
        rb'(?>'
            rb'\#[^{}\s:|]++'  # parser function
            rb'|' + regex_pattern(_parser_functions)[3:] +  # )
        # should not have any arguments or the arg should start with a :
        rb'(?:'
            rb':(?>[^{}]*+|}(?!})|{(?!{))*+'
        rb')?+'
        rb'\}\}()'
        rb'|'  # invalid template name
        rb'[\s\0_]*+' + ARGS +
        rb'\}\}()'
        rb'|'  # template
        rb'[\s\0]*+' + VALID_TITLE_CHARS +  # template name
        rb'[\s\0]*+' + ARGS +
    rb'\}\})').finditer
# External links

# Path: wikitextparser/_config.py
# def _plant_trie(strings: _Iterable[str]) -> dict:
# def _pattern(trie: dict) -> str:
# def regex_pattern(words: _Iterable[str]) -> bytes:
# _HTML_TAG_NAME = regex_pattern(_valid_html_tag_names) + br'\b'


# Path: wikitextparser/_spans.py
from functools import partial
from typing import Callable, Dict, Optional
from regex import DOTALL, REVERSE, compile as regex_compile, IGNORECASE
from ._config import (
    _HTML_TAG_NAME, _bare_external_link_schemes, _parsable_tag_extensions,
    _parser_functions, _unparsable_tag_extensions, regex_pattern)




# According to https://www.mediawiki.org/wiki/Manual:$wgLegalTitleChars
# illegal title characters are: r'[]{}|#<>[\u0000-\u0020]'
VALID_TITLE_CHARS = rb'[^\1-\6\|\{\}\[\]<>\n]++'
# Parser functions
# According to https://www.mediawiki.org/wiki/Help:Magic_words
# See also:
# https://translatewiki.net/wiki/MediaWiki:Sp-translate-data-MagicWords/fa
ARGS = rb'(?:\|(?>[^{}]++|{(?!{)|}(?!}))*+)?+'
PF_TL_FINDITER = regex_compile(  # noqa
    rb'\{\{(?>'
        rb'[\s\0]*+'
        rb'(?>'
            rb'\#[^{}\s:|]++'  # parser function
            rb'|' + regex_pattern(_parser_functions)[3:] +  # )
        # should not have any arguments or the arg should start with a :
        rb'(?:'
            rb':(?>[^{}]*+|}(?!})|{(?!{))*+'
        rb')?+'
        rb'\}\}()'
        rb'|'  # invalid template name
        rb'[\s\0_]*+' + ARGS +
        rb'\}\}()'
        rb'|'  # template
        rb'[\s\0]*+' + VALID_TITLE_CHARS +  # template name
        rb'[\s\0]*+' + ARGS +
    rb'\}\})').finditer
# External links

INVALID_URL_CHARS = rb' \t\n"<>\[\]'