rigging.parsing
Parsing helpers for extracting rigging models from text
parse(text: str, model_type: type[ModelT]) -> tuple[ModelT, slice]
#
Parses a single model from text.
Parameters:
-
text
(str
) –The content to parse.
-
model_type
(type[ModelT]
) –The type of model to parse.
Returns:
-
tuple[ModelT, slice]
–The parsed model.
Raises:
-
ValueError
–If no models of the given type are found and
fail_on_missing
is set toTrue
.
Source code in rigging/parsing.py
parse_many(text: str, *types: type[ModelT]) -> list[tuple[ModelT, slice]]
#
Parses multiple models of the specified non-identical types from text.
Parameters:
-
text
(str
) –The content to parse.
-
*types
(type[ModelT]
, default:()
) –The types of models to parse.
Returns:
-
list[tuple[ModelT, slice]]
–A list of parsed models.
Raises:
-
MissingModelError
–If any of the models are missing.
Source code in rigging/parsing.py
parse_set(text: str, model_type: type[ModelT], *, minimum: int | None = None) -> list[tuple[ModelT, slice]]
#
Parses a set of models with the specified identical type from text.
Parameters:
-
text
(str
) –The content to parse.
-
model_type
(type[ModelT]
) –The type of models to parse.
-
minimum
(int | None
, default:None
) –The minimum number of models required.
Returns:
-
list[tuple[ModelT, slice]]
–A list of parsed models.
Raises:
-
MissingModelError
–If the minimum number of models is not met.
Source code in rigging/parsing.py
try_parse(text: str, model_type: type[ModelT]) -> tuple[ModelT, slice] | None
#
Tries to parse a model from text.
Parameters:
-
text
(str
) –The content to parse.
-
model_type
(type[ModelT]
) –The type of model to search for.
Returns:
-
tuple[ModelT, slice] | None
–The first model that matches the given model type, or None if no match is found.
Source code in rigging/parsing.py
try_parse_many(text: str, *types: type[ModelT], fail_on_missing: bool = False) -> list[tuple[ModelT, slice]]
#
Tries to parses multiple models of the specified non-identical types from text.
Parameters:
-
text
(str
) –The content to parse.
-
*types
(type[ModelT]
, default:()
) –The types of models to parse.
-
fail_on_missing
(bool
, default:False
) –Whether to raise an exception if a model type is missing.
Returns:
-
list[tuple[ModelT, slice]]
–A list of parsed models.
Raises:
-
MissingModelError
–If a model type is missing and
fail_on_missing
is True. -
Exception
–If the model is malformed and
fail_on_missing
is True.
Source code in rigging/parsing.py
try_parse_set(text: str, model_type: type[ModelT], *, minimum: int | None = None, fail_on_missing: bool = False) -> list[tuple[ModelT, slice]]
#
Tries to parse a set of models with the specified identical type from text.
Parameters:
-
text
(str
) –The content to parse.
-
model_type
(type[ModelT]
) –The type of model to parse.
-
minimum
(int | None
, default:None
) –The minimum number of models expected.
-
fail_on_missing
(bool
, default:False
) –Whether to raise an exception if models are missing.
Returns:
-
list[tuple[ModelT, slice]]
–The parsed models.
Raises:
-
MissingModelError
–If the number of parsed models is less than the minimum required.