httk.core.optimade.filter.parser

Parser for the OPTIMADE filter language.

Parses an OPTIMADE filter string into a nested tuple abstract syntax tree (the “ojf” format), e.g.:

('AND', ('HAS_ALL', ('=', '='), ('Identifier', 'elements'),
         (('String', 'Ga'), ('String', 'Ti'))),
        ('OR', ('=', ('Identifier', 'nelements'), ('Number', '3')),
               ('=', ('Identifier', 'nelements'), ('Number', '2'))))

Attributes

Exceptions

ParserError

Common base class for all non-exit exceptions.

ParserSyntaxError

Common base class for all non-exit exceptions.

Functions

parse_optimade_filter(filter_string[, verbosity])

Parse an OPTIMADE filter into the public abstract syntax tree format.

parse_optimade_filter_raw(filter_string[, verbosity])

Parse an OPTIMADE filter and return its raw grammar parse tree.

Module Contents

exception httk.core.optimade.filter.parser.ParserError[source]

Bases: Exception

Common base class for all non-exit exceptions.

exception httk.core.optimade.filter.parser.ParserSyntaxError(*args)[source]

Bases: ParserError

Common base class for all non-exit exceptions.

info
line
pos
linestr
type httk.core.optimade.filter.parser.FilterAst = tuple[Any, ...]
httk.core.optimade.filter.parser.parse_optimade_filter(filter_string, verbosity=0)[source]

Parse an OPTIMADE filter into the public abstract syntax tree format.

Parameters:
  • filter_string (str) – OPTIMADE filter expression to parse.

  • verbosity (int | Any) – Diagnostic verbosity setting passed to the parser.

Returns:

Nested tuple abstract syntax tree in ojf format.

Raises:
  • ParserSyntaxError – If the filter cannot be parsed, or is too long or too deeply nested to parse within the interpreter’s recursion limit.

  • ParserError – If the filter cannot be parsed.

Return type:

FilterAst

httk.core.optimade.filter.parser.parse_optimade_filter_raw(filter_string, verbosity=0)[source]

Parse an OPTIMADE filter and return its raw grammar parse tree.

Parameters:
  • filter_string (str) – OPTIMADE filter expression to parse.

  • verbosity (int | Any) – Diagnostic verbosity setting passed to the parser.

Returns:

Raw nested tuple parse tree before ojf conversion.

Raises:
  • ParserSyntaxError – If the filter cannot be parsed, or is too long or too deeply nested to parse within the interpreter’s recursion limit.

  • ParserError – If the filter cannot be parsed.

Return type:

tuple[Any, …]