rfc3987_syntax2
Submodules
Attributes
All supported RFC 3987 grammar rule names exposed by this module. |
|
Top-level RFC 3987 parser start terms accepted by |
|
Callable validator for one RFC 3987 grammar rule. |
|
Lark grammar text for RFC 3987. |
|
Lazily initialized parser for RFC 3987 syntax. |
Functions
|
Parse text as one of the top-level RFC 3987 syntax terms. |
|
Check whether text is valid for a top-level RFC 3987 syntax term. |
|
Create a validator function for a specific RFC 3987 grammar rule. |
Package Contents
- rfc3987_syntax2.RFC3987_SYNTAX_PARSER_TYPE: str = 'earley'
- rfc3987_syntax2.RFC3987_SYNTAX_GRAMMAR_PATH: pathlib.Path
- rfc3987_syntax2.RFC3987_SYNTAX_TERMS: list[str] = ['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
RFC3987_SYNTAX_TERM_VALIDATORSand correspond to rules defined in the RFC 3987 Lark grammar.
- rfc3987_syntax2.T_SYNTAX_PARSER_TERM
Top-level RFC 3987 parser start terms accepted by
parse()andcheck().Allowed values are
"iri","iri_reference", and"absolute_iri".
- rfc3987_syntax2.parse(term: T_SYNTAX_PARSER_TERM, value: str) lark.ParseTree
Parse text as one of the top-level RFC 3987 syntax terms.
- Parameters:
term – Start rule used for parsing. Must be one of
"iri","iri_reference", or"absolute_iri".value – Input text to parse.
- Returns:
The Lark parse tree for
valueunder the selected start rule.- Raises:
lark.exceptions.LarkError – If parser initialization fails or parsing cannot be completed.
- rfc3987_syntax2.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
parse().Warning
Emits a
RuntimeWarning(viawarnings.warn()) when a non-UnexpectedInputlark.exceptions.LarkErroroccurs.- Parameters:
term – Start rule used for validation. Must be one of
"iri","iri_reference", or"absolute_iri".value – Input text to validate.
- Returns:
Trueif parsing succeeds; otherwiseFalse.
- rfc3987_syntax2.T_SYNTAX_VALIDATOR
Callable validator for one RFC 3987 grammar rule.
- Parameters:
text – Input text to validate.
- Returns:
Trueiftextmatches the target rule, otherwiseFalse.
- rfc3987_syntax2.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
lark.Larkparser configured withstart=rule_nameandparser=RFC3987_SYNTAX_PARSER_TYPE.- Parameters:
rule_name – Grammar rule name to validate against. Must be a value from
RFC3987_SYNTAX_TERMS.- Returns:
A callable
(text: str) -> boolthat returnsTruewhen parsing succeeds andFalseif alark.exceptions.LarkErroris raised.
- rfc3987_syntax2.grammar: str
Lark grammar text for RFC 3987.
- rfc3987_syntax2.syntax_parser: lark.Lark
Lazily initialized parser for RFC 3987 syntax.