ways.parsing.engine module¶
A collection of functions for the parse types in Ways.
Maybe in the future this module will be a place where users can “register” their own engines but, for right now, lets just K.I.S.S and assume people will want regex for over 90% of their needs.
-
ways.parsing.engine.
get_token_parse
(name, parser, parse_type)[source]¶ Get the parse token for some token name, using a given parse_type.
Parameters: - name (str) – The token to get the token parse of.
- parser (
ways.api.ContextParser
) – The parser which presumably contains any information needed to retrieve a token parse value. - parse_type (str) – The engine to use when getting our token parse information. Example: ‘regex’.
Returns: The token parse.
Return type: str
-
ways.parsing.engine.
get_token_parse_regex
(name, parser, groups=False)[source]¶ Get the parse token for some token name, using regex.
Parameters: - name (str) – The token to get the token parse of.
- parser (
ways.api.ContextParser
) – The parser which presumably contains any information needed to retrieve a token parse value. - groups (
bool
, optional) – Whether or not to include (?P<{foo}>) around every value in the returned dict. Warning: Using this on a nested token can cause nested groups so it’s not always recommended to enable this. Default is False.
Returns: The token parse.
Return type: str
-
ways.parsing.engine.
get_value_from_parent
(name, parent, parser, parse_type)[source]¶ Use a token or its parent to get some stored value from a parser.
Parameters: - name (str) – The token to get the value of. If no value is found for this token, parent is used to parse and return a value.
- parent (str) – The token which is a parent of the name token. This parent should have a value or be able to get a value which we then parse and return.
- parser (
ways.api.ContextParser
) – The parser which presumably contains any information needed to retrieve the name token’s value. - parse_type (str) – The engine to use when getting our token parse information. Example: ‘regex’.
Returns: The value for the name token.
Return type: str
-
ways.parsing.engine.
get_value_from_parent_regex
(name, parent, parser)[source]¶ Do a Parent-Search using regex and return its value.
Parameters: - name (str) – The token to get the value of. If no value is found for this token, parent is used to parse and return a value.
- parent (str) – The token which is a parent of the name token. This parent should have a value or be able to get a value which we then parse and return.
- parser (
ways.api.ContextParser
) – The parser which presumably contains any information needed to retrieve the name token’s value.
Returns: The value for the name token.
Return type: str