rfc3987_syntax2 =============== .. py:module:: rfc3987_syntax2 Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/rfc3987_syntax2/is_valid_syntax_term/index Attributes ---------- .. autoapisummary:: rfc3987_syntax2.RFC3987_SYNTAX_PARSER_TYPE rfc3987_syntax2.RFC3987_SYNTAX_GRAMMAR_PATH rfc3987_syntax2.RFC3987_SYNTAX_TERMS rfc3987_syntax2.T_SYNTAX_PARSER_TERM rfc3987_syntax2.T_SYNTAX_VALIDATOR rfc3987_syntax2.grammar rfc3987_syntax2.syntax_parser Functions --------- .. autoapisummary:: rfc3987_syntax2.parse rfc3987_syntax2.is_valid_syntax rfc3987_syntax2.make_syntax_validator Package Contents ---------------- .. py:data:: RFC3987_SYNTAX_PARSER_TYPE :type: str :value: 'earley' .. py:data:: RFC3987_SYNTAX_GRAMMAR_PATH :type: pathlib.Path .. py:data:: RFC3987_SYNTAX_TERMS :type: list[str] :value: ['iri', 'iri_reference', 'absolute_iri', 'scheme', 'ihier_part', 'irelative_ref',... All supported RFC 3987 grammar rule names exposed by this module. These term names can be used to select validators from :data:`RFC3987_SYNTAX_TERM_VALIDATORS` and correspond to rules defined in the RFC 3987 Lark grammar. .. py:data:: T_SYNTAX_PARSER_TERM Top-level RFC 3987 parser start terms accepted by :func:`parse` and :func:`check`. Allowed values are ``"iri"``, ``"iri_reference"``, and ``"absolute_iri"``. .. py:function:: parse(term: T_SYNTAX_PARSER_TERM, value: str) -> lark.ParseTree Parse text as one of the top-level RFC 3987 syntax terms. :param term: Start rule used for parsing. Must be one of ``"iri"``, ``"iri_reference"``, or ``"absolute_iri"``. :param value: Input text to parse. :return: The Lark parse tree for ``value`` under the selected start rule. :raises lark.exceptions.LarkError: If parser initialization fails or parsing cannot be completed. .. py:function:: is_valid_syntax(term: T_SYNTAX_PARSER_TERM, value: str) -> bool Check whether text is valid for a top-level RFC 3987 syntax term. This is a boolean convenience wrapper around :func:`parse`. .. warning:: Emits a ``RuntimeWarning`` (via :func:`warnings.warn`) when a non-``UnexpectedInput`` ``lark.exceptions.LarkError`` occurs. :param term: Start rule used for validation. Must be one of ``"iri"``, ``"iri_reference"``, or ``"absolute_iri"``. :param value: Input text to validate. :return: ``True`` if parsing succeeds; otherwise ``False``. .. py:data:: T_SYNTAX_VALIDATOR Callable validator for one RFC 3987 grammar rule. :param text: Input text to validate. :return: ``True`` if ``text`` matches the target rule, otherwise ``False``. .. py:function:: make_syntax_validator(rule_name: str) -> T_SYNTAX_VALIDATOR Create a validator function for a specific RFC 3987 grammar rule. The returned callable lazily initializes and caches a dedicated :class:`lark.Lark` parser configured with ``start=rule_name`` and ``parser=RFC3987_SYNTAX_PARSER_TYPE``. :param rule_name: Grammar rule name to validate against. Must be a value from :data:`RFC3987_SYNTAX_TERMS`. :return: A callable ``(text: str) -> bool`` that returns ``True`` when parsing succeeds and ``False`` if a ``lark.exceptions.LarkError`` is raised. .. py:data:: grammar :type: str Lark grammar text for RFC 3987. .. py:data:: syntax_parser :type: lark.Lark Lazily initialized parser for RFC 3987 syntax.