maha.rexy.templates.expression_group#

Module Contents#

Classes#

ExpressionGroup

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().

  • expressions (rx.Expression | ExpressionGroup) –

compile_expressions(self)[source]#
add(self, *expression)[source]#

Add an expression to the group.

Parameters
Return type

None

join(self)[source]#

Returns non capturing group of the expressions.

Returns

Non capturing group of the patterns.

Return type

str

get_matched_expression(self, 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

Expression

parse(self, text)[source]#

Parses the text.

Parameters

text (str) – Text to parse.

Yields

ExpressionResult – Extracted value.

Return type

Iterable[maha.rexy.ExpressionResult]

normal_parse(self, text)[source]#

Parse the input text and return the extracted values.

Parameters

text (str) – Text to parse.

Yields

ExpressionResult – Extracted value.

Return type

Iterable[maha.rexy.ExpressionResult]

smart_parse(self, 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]