maha.rexy.templates.expression_group#
Module Contents#
Classes#
A group of expressions that match the same dimension. Expressions are evaluated |
- class ExpressionGroup(*expressions, smart=False)[source]#
A group of expressions that match the same dimension. Expressions are evaluated in the order they were added.
- Parameters
*expressions – List of expressions to match. High-priority expressions should be passed first.
smart (bool, optional) – Whether to parse the text in a smart way. See
smart_parse().
- add(*expression)[source]#
Add an expression to the group.
- Parameters
*expression (maha.rexy.Expression) – Expressions to add.
- Return type
None
- join()[source]#
Returns non capturing group of the expressions.
- Returns
Non capturing group of the patterns.
- Return type
str
- get_matched_expression(text)[source]#
Returns the expression that fully matches the text.
- Parameters
text (str) – Text to match.
- Returns
Expression that fully matches the text.
- Return type
- parse(text)[source]#
Parses the text.
- Parameters
text (str) – Text to parse.
- Yields
ExpressionResult– Extracted value.- Return type
Iterable[maha.rexy.ExpressionResult]
- normal_parse(text)[source]#
Parse the input
textand return the extracted values.- Parameters
text (str) – Text to parse.
- Yields
ExpressionResult– Extracted value.- Return type
Iterable[maha.rexy.ExpressionResult]
- smart_parse(text)[source]#
Parses the text. If a value matches two or more expressions, only the first expression parses the value, no value is matched more than once. This means high-priority expressions should be added to the group first.
- Parameters
text (str) – Text to parse.
- Yields
ExpressionResult– Extracted value.- Return type
Iterable[maha.rexy.ExpressionResult]