Gromacs  5.1.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Typedefs | Enumerations | Functions
#include <exception>
#include <list>
#include <string>
#include "gromacs/math/vec.h"
#include "gromacs/math/vectypes.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/real.h"
#include "gromacs/utility/uniqueptr.h"
#include "selelem.h"
#include "selvalue.h"
+ Include dependency graph for parsetree.h:
+ This graph shows which files directly or indirectly include this file:

Description

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.

Author
Teemu Murtola teemu.nosp@m..mur.nosp@m.tola@.nosp@m.gmai.nosp@m.l.com

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 gmx::gmx_unique_ptr
< SelectionParserValueList >
::type 
gmx::SelectionParserValueListPointer
 Smart pointer type for managing a SelectionParserValueList.
 
typedef std::list
< SelectionParserParameter > 
gmx::SelectionParserParameterList
 Container for a list of SelectionParserParameter objects.
 
typedef gmx::gmx_unique_ptr
< SelectionParserParameterList >
::type 
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...
 

Functions

bool _gmx_selparser_handle_exception (void *scanner, std::exception *ex)
 Handles exceptions caught within the Bison code. More...
 
bool _gmx_selparser_handle_error (void *scanner)
 Handles errors in the selection parser. More...
 
void _gmx_selelem_update_flags (const gmx::SelectionTreeElementPointer &sel)
 Propagates the flags for selection elements. More...
 
void _gmx_selelem_init_method_params (const gmx::SelectionTreeElementPointer &sel, void *scanner)
 Initializes the method parameter data of SEL_EXPRESSION and SEL_MODIFIER elements. More...
 
void _gmx_selelem_set_method (const gmx::SelectionTreeElementPointer &sel, struct gmx_ana_selmethod_t *method, void *scanner)
 Initializes the method for a SEL_EXPRESSION selection element. More...
 
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. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_comparison (const gmx::SelectionTreeElementPointer &left, const gmx::SelectionTreeElementPointer &right, const char *cmpop, void *scanner)
 Creates a gmx::SelectionTreeElement for comparsion expression evaluation. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_keyword (struct gmx_ana_selmethod_t *method, gmx::SelectionParserValueListPointer args, const char *rpost, void *scanner)
 Creates a gmx::SelectionTreeElement for a keyword expression from the parsed data. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_keyword_strmatch (struct gmx_ana_selmethod_t *method, gmx::SelectionStringMatchType matchType, gmx::SelectionParserValueListPointer args, const char *rpost, void *scanner)
 Creates a gmx::SelectionTreeElement for string-matching keyword expression. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_keyword_of (struct gmx_ana_selmethod_t *method, const gmx::SelectionTreeElementPointer &group, const char *rpost, void *scanner)
 Creates a gmx::SelectionTreeElement for "keyword of" expression. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_method (struct gmx_ana_selmethod_t *method, gmx::SelectionParserParameterListPointer params, const char *rpost, void *scanner)
 Creates a gmx::SelectionTreeElement for a method expression from the parsed data. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_modifier (struct gmx_ana_selmethod_t *mod, gmx::SelectionParserParameterListPointer params, const gmx::SelectionTreeElementPointer &sel, void *scanner)
 Creates a gmx::SelectionTreeElement for a modifier expression from the parsed data. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_position (const gmx::SelectionTreeElementPointer &expr, const char *type, void *scanner)
 Creates a gmx::SelectionTreeElement for evaluation of reference positions. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_const_position (real x, real y, real z, void *scanner)
 Creates a gmx::SelectionTreeElement for a constant position. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_group_by_name (const char *name, void *scanner)
 Creates a gmx::SelectionTreeElement for a index group expression using group name. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_group_by_id (int id, void *scanner)
 Creates a gmx::SelectionTreeElement for a index group expression using group index. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_variable_ref (const gmx::SelectionTreeElementPointer &sel, void *scanner)
 Creates a gmx::SelectionTreeElement for a variable reference. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_init_selection (const char *name, const gmx::SelectionTreeElementPointer &sel, void *scanner)
 Creates a root gmx::SelectionTreeElement for a selection. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_assign_variable (const char *name, const gmx::SelectionTreeElementPointer &expr, void *scanner)
 Creates a root gmx::SelectionTreeElement elements for a variable assignment. More...
 
gmx::SelectionTreeElementPointer _gmx_sel_append_selection (const gmx::SelectionTreeElementPointer &sel, gmx::SelectionTreeElementPointer last, void *scanner)
 Appends a root gmx::SelectionTreeElement to a selection collection. More...
 
bool _gmx_sel_parser_should_finish (void *scanner)
 Check whether the parser should finish. More...
 
void _gmx_sel_parse_params (const gmx::SelectionParserParameterList &params, int nparam, struct gmx_ana_selparam_t *param, const gmx::SelectionTreeElementPointer &root, void *scanner)
 Initializes an array of parameters based on input from the selection parser. More...
 

Function Documentation

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.

Parameters
selSelection to append (can be NULL, in which case nothing is done).
lastLast selection, or NULL if not present or not known.
scannerScanner data structure.
Returns
The last selection after the append.

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.

Parameters
[in]nameName of the variable.
[in]exprThe selection element that evaluates the variable.
scannerScanner data structure.
Returns
The created root selection element.

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.

Parameters
[in]leftSelection element for the left hand side.
[in]rightSelection element for the right hand side.
[in]opString representation of the operator.
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]leftSelection element for the left hand side.
[in]rightSelection element for the right hand side.
[in]cmpopString representation of the comparison operator.
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]x,y,zCoordinates for the position.
[in]scannerScanner data structure.
Returns
The creates selection element.
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.

Parameters
[in]idZero-based index number of the group to extract.
[in]scannerScanner data structure.
Returns
The created selection element.
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.

Parameters
[in]nameName of an index group to search for.
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]methodMethod to use.
[in]argsPointer to the first argument.
[in]rpostReference position type to use (NULL = default).
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]methodMethod to use for initialization.
[in]groupSelection in which the keyword should be evaluated.
[in]rpostReference position type to use (NULL = default).
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]methodMethod to use.
[in]matchTypeString matching type.
[in]argsPointer to the first argument.
[in]rpostReference position type to use (NULL = default).
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]methodMethod to use for initialization.
[in]paramsPointer to the first parameter.
[in]rpostReference position type to use (NULL = default).
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]methodModifier to use for initialization.
[in]paramsPointer to the first parameter.
[in]selSelection element that the modifier should act on.
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]exprInput selection element for the position calculation.
[in]typeReference position type or NULL for default.
[in]scannerScanner data structure.
Returns
The created selection element.

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.

Parameters
[in]nameName for the selection (if NULL, a default name is constructed).
[in]selThe selection element that evaluates the selection.
scannerScanner data structure.
Returns
The created root selection element.

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.

Parameters
[in,out]selValue of the variable.
scannerScanner data structure.
Returns
The created selection element that references 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.

Parameters
pparamsList of parameters from the selection parser.
[in]nparamNumber of parameters in params.
paramsArray of parameters to parse.
rootSelection element to which child expressions are added.
[in]scannerScanner 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.

Parameters
[in]scannerScanner data structure.
Returns
true if the parser should finish, false if parsing should continue.

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.

Parameters
[in,out]selSelection element to initialize.
[in]scannerScanner 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.

Parameters
[in,out]selSelection element to initialize.
[in]methodSelection method to set.
[in]scannerScanner 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.

Parameters
[in,out]selRoot 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.

Returns
true if parsing can continue with the next selection.
Exceptions
std::bad_allocif out of memory during the error processing.
unspecifiedCan 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.

Return values
<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.