3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
32 * \brief Handling of intermediate selection parser data.
34 * The data types declared in this header are used by the parser to store
35 * intermediate data when constructing method expressions.
36 * In particular, the parameters for the method are stored.
37 * The intermediate data is freed once a \c t_selelem object can be
40 * This is an implementation header: there should be no need to use it outside
43 #ifndef SELECTION_PARSETREE_H
44 #define SELECTION_PARSETREE_H
51 struct gmx_ana_indexgrps_t
;
52 struct gmx_ana_selmethod_t
;
53 struct gmx_ana_selparam_t
;
56 * Describes a parsed value, possibly resulting from expression evaluation.
58 typedef struct t_selexpr_value
60 /** Type of the value. */
62 /** TRUE if the value is the result of an expression. */
65 /** The integer value/range (\p type INT_VALUE); */
67 /** Beginning of the range. */
69 /** End of the range; equals \p i1 for a single integer. */
72 /** The real value/range (\p type REAL_VALUE); */
74 /** Beginning of the range. */
76 /** End of the range; equals \p r1 for a single number. */
79 /** The string value (\p type STR_VALUE); */
81 /** The position value (\p type POS_VALUE); */
83 /** The expression if \p bExpr is TRUE. */
84 struct t_selelem
*expr
;
86 /** Pointer to the next value. */
87 struct t_selexpr_value
*next
;
91 * Describes a parsed method parameter.
93 typedef struct t_selexpr_param
95 /** Name of the parameter. */
97 /** Number of values given for this parameter. */
99 /** Pointer to the first value. */
100 struct t_selexpr_value
*value
;
101 /** Pointer to the next parameter. */
102 struct t_selexpr_param
*next
;
105 /** Error reporting function for the selection parser. */
107 _gmx_selparser_error(const char *fmt
, ...);
109 /** Allocates and initializes a constant \c t_selexpr_value. */
111 _gmx_selexpr_create_value(e_selvalue_t type
);
112 /** Allocates and initializes an expression \c t_selexpr_value. */
114 _gmx_selexpr_create_value_expr(struct t_selelem
*expr
);
115 /** Allocates and initializes a \c t_selexpr_param. */
117 _gmx_selexpr_create_param(char *name
);
119 /** Frees the memory allocated for a chain of values. */
121 _gmx_selexpr_free_values(t_selexpr_value
*value
);
122 /** Frees the memory allocated for a chain of parameters. */
124 _gmx_selexpr_free_params(t_selexpr_param
*param
);
126 /** Propagates the flags for selection elements. */
128 _gmx_selelem_update_flags(struct t_selelem
*sel
);
130 /** Creates a \c t_selelem for comparsion expression evaluation. */
132 _gmx_sel_init_comparison(struct t_selelem
*left
, struct t_selelem
*right
,
133 char *cmpop
, void *scanner
);
134 /** Creates a \c t_selelem for a keyword expression from the parsed data. */
136 _gmx_sel_init_keyword(struct gmx_ana_selmethod_t
*method
,
137 t_selexpr_value
*args
, const char *rpost
, void *scanner
);
138 /** Creates a \c t_selelem for a method expression from the parsed data. */
140 _gmx_sel_init_method(struct gmx_ana_selmethod_t
*method
,
141 t_selexpr_param
*params
, const char *rpost
,
143 /** Creates a \c t_selelem for a modifier expression from the parsed data. */
145 _gmx_sel_init_modifier(struct gmx_ana_selmethod_t
*mod
, t_selexpr_param
*params
,
146 struct t_selelem
*sel
, void *scanner
);
147 /** Creates a \c t_selelem for evaluation of reference positions. */
149 _gmx_sel_init_position(struct t_selelem
*expr
, const char *type
, void *scanner
);
151 /** Creates a \c t_selelem for a constant position. */
153 _gmx_sel_init_const_position(real x
, real y
, real z
);
154 /** Creates a \c t_selelem for a index group expression using group name. */
156 _gmx_sel_init_group_by_name(const char *name
, void *scanner
);
157 /** Creates a \c t_selelem for a index group expression using group index. */
159 _gmx_sel_init_group_by_id(int id
, void *scanner
);
160 /** Creates a \c t_selelem for a variable reference */
162 _gmx_sel_init_variable_ref(struct t_selelem
*sel
);
164 /** Creates a root \c t_selelem for a selection. */
166 _gmx_sel_init_selection(char *name
, struct t_selelem
*sel
, void *scanner
);
167 /** Creates a root \c t_selelem elements for a variable assignment. */
169 _gmx_sel_assign_variable(char *name
, struct t_selelem
*expr
, void *scanner
);
170 /** Appends a root \c t_selelem to a selection collection. */
172 _gmx_sel_append_selection(struct t_selelem
*sel
, struct t_selelem
*last
,
174 /** Check whether the parser should finish. */
176 _gmx_sel_parser_should_finish(void *scanner
);
178 /** Handle empty commands. */
180 _gmx_sel_handle_empty_cmd(void *scanner
);
181 /** Process help commands. */
183 _gmx_sel_handle_help_cmd(char *topic
, void *scanner
);
186 /** Initializes an array of parameters based on input from the selection parser. */
188 _gmx_sel_parse_params(t_selexpr_param
*pparams
, int nparam
,
189 struct gmx_ana_selparam_t
*param
, struct t_selelem
*root
,