httk.core.optimade.filter¶
The OPTIMADE filter language as a first-class httk citizen.
This package makes the OPTIMADE filter language a standard httk query
feature: parse_optimade_filter() parses a filter string into a nested
tuple abstract syntax tree (the “ojf” format, FilterAst), e.g.:
('AND', ('HAS_ALL', ('=', '='), ('Identifier', 'elements'),
(('String', 'Ga'), ('String', 'Ti'))),
('OR', ('=', ('Identifier', 'nelements'), ('Number', '3')),
('=', ('Identifier', 'nelements'), ('Number', '2'))))
It is the sibling of the vendored OPTIMADE property definitions in
httk.registry.schemas.core — two halves of the same standard: the property
definitions describe what can be queried, and this package parses the query
language itself. The grammar is loaded from the packaged
optimade_filter_grammar.ebnf (see the adjacent README.md for
provenance) and parsed by the vendored LR(1) parser generator in
_miniparser.
Errors raised on bad user input are ParserSyntaxError; grammar
problems raise ParserGrammarError; parser bugs raise
ParserInternalError. All are subclasses of ParserError.
Submodules¶
Attributes¶
Exceptions¶
Common base class for all non-exit exceptions. |
|
Common base class for all non-exit exceptions. |
|
Common base class for all non-exit exceptions. |
|
Common base class for all non-exit exceptions. |
Functions¶
Convert a raw OPTIMADE parse tree into the public AST format. |
|
|
Parse an OPTIMADE filter into the public abstract syntax tree format. |
|
Parse an OPTIMADE filter and return its raw grammar parse tree. |
Package Contents¶
- exception httk.core.optimade.filter.ParserError[source]¶
Bases:
ExceptionCommon base class for all non-exit exceptions.
- exception httk.core.optimade.filter.ParserGrammarError[source]¶
Bases:
ParserErrorCommon base class for all non-exit exceptions.
- exception httk.core.optimade.filter.ParserInternalError[source]¶
Bases:
ParserErrorCommon base class for all non-exit exceptions.
- exception httk.core.optimade.filter.ParserSyntaxError(*args)[source]¶
Bases:
ParserErrorCommon base class for all non-exit exceptions.
- info¶
- line¶
- pos¶
- linestr¶
- httk.core.optimade.filter.optimade_parse_tree_to_ojf(ast)[source]¶
Convert a raw OPTIMADE parse tree into the public AST format.
- Parameters:
ast (tuple[Any, ...]) – Raw parse tree rooted at
Filter.- Returns:
Nested tuple abstract syntax tree in
ojfformat.- Raises:
ParserSyntaxError – If the tree uses an unsupported or invalid construct, or is too deeply nested to convert within the recursion limit.
ParserInternalError – If the tree has an invalid internal shape.
- Return type:
- httk.core.optimade.filter.parse_optimade_filter(filter_string, verbosity=0)[source]¶
Parse an OPTIMADE filter into the public abstract syntax tree format.
- Parameters:
- Returns:
Nested tuple abstract syntax tree in
ojfformat.- 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:
- httk.core.optimade.filter.parse_optimade_filter_raw(filter_string, verbosity=0)[source]¶
Parse an OPTIMADE filter and return its raw grammar parse tree.
- Parameters:
- Returns:
Raw nested tuple parse tree before
ojfconversion.- 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, …]