Gromacs
2025.0-dev-20241011-013a99c
|
#include <exception>
#include <list>
#include <memory>
#include <string>
#include <utility>
#include "gromacs/math/vec.h"
#include "gromacs/math/vectypes.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/real.h"
#include "selelem.h"
#include "selvalue.h"
Handling of intermediate selection parser data.
The data types declared in this header are used by the parser to store intermediate data when constructing method expressions. In particular, the parameters for the method are stored. The intermediate data is freed once a gmx::SelectionTreeElement object can be constructed.
This is an implementation header: there should be no need to use it outside this directory.
Classes | |
class | gmx::SelectionParserValue |
Describes a parsed value, possibly resulting from expression evaluation. More... | |
class | gmx::SelectionParserParameter |
Describes a parsed method parameter. More... | |
Typedefs | |
typedef std::list < SelectionParserValue > | gmx::SelectionParserValueList |
Container for a list of SelectionParserValue objects. | |
typedef std::unique_ptr < SelectionParserValueList > | gmx::SelectionParserValueListPointer |
Smart pointer type for managing a SelectionParserValueList. | |
typedef std::list < SelectionParserParameter > | gmx::SelectionParserParameterList |
Container for a list of SelectionParserParameter objects. | |
typedef std::unique_ptr < SelectionParserParameterList > | gmx::SelectionParserParameterListPointer |
Smart pointer type for managing a SelectionParserParameterList. | |
Enumerations | |
enum | gmx::SelectionStringMatchType { gmx::eStringMatchType_Auto, gmx::eStringMatchType_Exact, gmx::eStringMatchType_Wildcard, gmx::eStringMatchType_RegularExpression } |
String matching mode for string keyword expressions. More... | |
gmx::SelectionTreeElementPointer _gmx_sel_append_selection | ( | const gmx::SelectionTreeElementPointer & | sel, |
gmx::SelectionTreeElementPointer | last, | ||
yyscan_t | scanner | ||
) |
Appends a root gmx::SelectionTreeElement to a selection collection.
sel | Selection to append (can be NULL, in which case nothing is done). |
last | Last selection, or NULL if not present or not known. |
scanner | Scanner data structure. |
Appends sel
after the last root element, and returns either sel
(if it was non-NULL) or the last element (if sel
was NULL).
gmx::SelectionTreeElementPointer _gmx_sel_assign_variable | ( | const char * | name, |
const gmx::SelectionTreeElementPointer & | expr, | ||
yyscan_t | scanner | ||
) |
Creates a root gmx::SelectionTreeElement elements for a variable assignment.
[in] | name | Name of the variable. |
[in] | expr | The selection element that evaluates the variable. |
scanner | Scanner data structure. |
This function handles the creation of root gmx::SelectionTreeElement objects for variable assignments. A SEL_ROOT element and a SEL_SUBEXPR element are both created.
gmx::SelectionTreeElementPointer _gmx_sel_init_arithmetic | ( | const gmx::SelectionTreeElementPointer & | left, |
const gmx::SelectionTreeElementPointer & | right, | ||
char | op, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for arithmetic expression evaluation.
[in] | left | Selection element for the left hand side. |
[in] | right | Selection element for the right hand side. |
[in] | op | String representation of the operator. |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for arithmetic expressions.
gmx::SelectionTreeElementPointer _gmx_sel_init_comparison | ( | const gmx::SelectionTreeElementPointer & | left, |
const gmx::SelectionTreeElementPointer & | right, | ||
const char * | cmpop, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for comparsion expression evaluation.
[in] | left | Selection element for the left hand side. |
[in] | right | Selection element for the right hand side. |
[in] | cmpop | String representation of the comparison operator. |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for comparison expressions.
gmx::SelectionTreeElementPointer _gmx_sel_init_const_position | ( | real | x, |
real | y, | ||
real | z, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a constant position.
[in] | x,y,z | Coordinates for the position. |
[in] | scanner | Scanner data structure. |
gmx::SelectionTreeElementPointer _gmx_sel_init_group_by_id | ( | int | id, |
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a index group expression using group index.
[in] | id | Zero-based index number of the group to extract. |
[in] | scanner | Scanner data structure. |
gmx::SelectionTreeElementPointer _gmx_sel_init_group_by_name | ( | const char * | name, |
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a index group expression using group name.
[in] | name | Name of an index group to search for. |
[in] | scanner | Scanner data structure. |
See gmx_ana_indexgrps_find() for information on how name
is matched against the index groups.
gmx::SelectionTreeElementPointer _gmx_sel_init_keyword | ( | gmx_ana_selmethod_t * | method, |
gmx::SelectionParserValueListPointer | args, | ||
const char * | rpost, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a keyword expression from the parsed data.
[in] | method | Method to use. |
[in] | args | Pointer to the first argument. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for selection methods that do not take parameters.
gmx::SelectionTreeElementPointer _gmx_sel_init_keyword_of | ( | gmx_ana_selmethod_t * | method, |
const gmx::SelectionTreeElementPointer & | group, | ||
const char * | rpost, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for "keyword of" expression.
[in] | method | Method to use for initialization. |
[in] | group | Selection in which the keyword should be evaluated. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for expressions like "z of ...".
gmx::SelectionTreeElementPointer _gmx_sel_init_keyword_strmatch | ( | gmx_ana_selmethod_t * | method, |
gmx::SelectionStringMatchType | matchType, | ||
gmx::SelectionParserValueListPointer | args, | ||
const char * | rpost, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for string-matching keyword expression.
[in] | method | Method to use. |
[in] | matchType | String matching type. |
[in] | args | Pointer to the first argument. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for keyword string matching.
gmx::SelectionTreeElementPointer _gmx_sel_init_method | ( | gmx_ana_selmethod_t * | method, |
gmx::SelectionParserParameterListPointer | params, | ||
const char * | rpost, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a method expression from the parsed data.
[in] | method | Method to use for initialization. |
[in] | params | Pointer to the first parameter. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for selection methods that take parameters.
Part of the behavior of the same
selection keyword is hardcoded into this function (or rather, into _gmx_selelem_custom_init_same()) to allow the use of any keyword in "same KEYWORD as"
without requiring special handling somewhere else (or sacrificing the simple syntax).
gmx::SelectionTreeElementPointer _gmx_sel_init_modifier | ( | gmx_ana_selmethod_t * | method, |
gmx::SelectionParserParameterListPointer | params, | ||
const gmx::SelectionTreeElementPointer & | sel, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a modifier expression from the parsed data.
[in] | method | Modifier to use for initialization. |
[in] | params | Pointer to the first parameter. |
[in] | sel | Selection element that the modifier should act on. |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for selection modifiers.
gmx::SelectionTreeElementPointer _gmx_sel_init_position | ( | const gmx::SelectionTreeElementPointer & | expr, |
const char * | type, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for evaluation of reference positions.
[in] | expr | Input selection element for the position calculation. |
[in] | type | Reference position type or NULL for default. |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for evaluation of reference positions.
gmx::SelectionTreeElementPointer _gmx_sel_init_selection | ( | const char * | name, |
const gmx::SelectionTreeElementPointer & | sel, | ||
yyscan_t | scanner | ||
) |
Creates a root gmx::SelectionTreeElement for a selection.
[in] | name | Name for the selection (if NULL, a default name is constructed). |
[in] | sel | The selection element that evaluates the selection. |
scanner | Scanner data structure. |
This function handles the creation of root (SEL_ROOT) gmx::SelectionTreeElement objects for selections.
gmx::SelectionTreeElementPointer _gmx_sel_init_variable_ref | ( | const gmx::SelectionTreeElementPointer & | sel, |
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a variable reference.
[in,out] | sel | Value of the variable. |
scanner | Scanner data structure. |
sel
.The reference count of sel
is updated, but no other modifications are made.
void _gmx_sel_parse_params | ( | const gmx::SelectionParserParameterList & | pparams, |
int | nparam, | ||
gmx_ana_selparam_t * | params, | ||
const gmx::SelectionTreeElementPointer & | root, | ||
void * | scanner | ||
) |
Initializes an array of parameters based on input from the selection parser.
pparams | List of parameters from the selection parser. | |
[in] | nparam | Number of parameters in params . |
params | Array of parameters to parse. | |
root | Selection element to which child expressions are added. | |
[in] | scanner | Scanner data structure. |
Initializes the params
array based on the parameters in pparams
. See the documentation of gmx_ana_selparam_t
for different options available for parsing.
The list pparams
and any associated values are freed after the parameters have been processed, no matter is there was an error or not.
bool _gmx_sel_parser_should_finish | ( | yyscan_t | scanner | ) |
Check whether the parser should finish.
[in] | scanner | Scanner data structure. |
This function is called always after _gmx_sel_append_selection() to check whether a sufficient number of selections has already been provided. This is used to terminate interactive parsers when the correct number of selections has been provided.
void _gmx_selelem_init_method_params | ( | const gmx::SelectionTreeElementPointer & | sel, |
yyscan_t | scanner | ||
) |
Initializes the method parameter data of SEL_EXPRESSION and SEL_MODIFIER elements.
[in,out] | sel | Selection element to initialize. |
[in] | scanner | Scanner data structure. |
A deep copy of the parameters is made to allow several expressions with the same method to coexist peacefully. Calls sel_datafunc() if one is specified for the method.
void _gmx_selelem_set_method | ( | const gmx::SelectionTreeElementPointer & | sel, |
gmx_ana_selmethod_t * | method, | ||
yyscan_t | scanner | ||
) |
Initializes the method for a SEL_EXPRESSION selection element.
[in,out] | sel | Selection element to initialize. |
[in] | method | Selection method to set. |
[in] | scanner | Scanner data structure. |
Makes a copy of method
and stores it in sel->u.expr.method
, and calls _gmx_selelem_init_method_params();
void _gmx_selelem_update_flags | ( | const gmx::SelectionTreeElementPointer & | sel | ) |
Propagates the flags for selection elements.
[in,out] | sel | Root of the selection element tree to initialize. |
Propagates the SEL_DYNAMIC flag from the children of sel
to sel
(if any child of sel
is dynamic, sel
is also marked as such). The SEL_DYNAMIC flag is also set for SEL_EXPRESSION elements with a dynamic method. Also, sets one of the SEL_SINGLEVAL, SEL_ATOMVAL, or SEL_VARNUMVAL flags, either based on the children or on the type of the selection method. If the types of the children conflict, an error is returned.
The flags of the children of sel
are also updated if not done earlier. The flags are initialized only once for any element; if SEL_FLAGSSET is set for an element, the function returns immediately, and the recursive operation does not descend beyond such elements.
bool _gmx_selparser_handle_error | ( | void * | scanner | ) |
Handles errors in the selection parser.
true
if parsing can continue with the next selection. std::bad_alloc | if out of memory during the error processing. |
unspecified | Can throw the stored exception if recovery from that exception is not possible. |
This function is called during error recovery, after Bison has discarded all the symbols for the erroneous selection. At this point, the full selection that caused the error is known, and can be added to the error context.
For an interactive parser, this function returns true
to let the parsing continue with the next selection, or to let the user enter the next selection, if it was possible to recover from the exception. For other cases, this will either rethrow the original exception with added context, or return false
after adding the context to the error reporter. Any exceptions thrown from this method are again caught by Bison and result in termination of the parsing; the caller can then rethrow them.
bool _gmx_selparser_handle_exception | ( | void * | scanner, |
std::exception * | ex | ||
) |
Handles exceptions caught within the Bison code.
<tt>true</tt> | if the parser should attempt error recovery. |
<tt>false</tt> | if the parser should immediately abort. |
This function is called whenever an exception is caught within Bison actions. Since exceptions cannot propagate through Bison code, the exception is saved (potentially with some extra context information) so that the caller of the parser can rethrow the exception.
If it is possible to recover from the exception, then the function returns true
, and Bison enters error recovery state. At the end of the recovery, _gmx_selparser_handle_error() is called. If this function returns false, then Bison immediately aborts the parsing so that the caller can rethrow the exception.