2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2009, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
39 * \brief Handling of intermediate selection parser data.
41 * The data types declared in this header are used by the parser to store
42 * intermediate data when constructing method expressions.
43 * In particular, the parameters for the method are stored.
44 * The intermediate data is freed once a \c t_selelem object can be
47 * This is an implementation header: there should be no need to use it outside
50 #ifndef SELECTION_PARSETREE_H
51 #define SELECTION_PARSETREE_H
53 /*#include <typedefs.h>*/
54 #include <types/simple.h>
60 struct gmx_ana_indexgrps_t;
61 struct gmx_ana_selmethod_t;
62 struct gmx_ana_selparam_t;
65 * Describes a parsed value, possibly resulting from expression evaluation.
67 typedef struct t_selexpr_value
69 /** Type of the value. */
71 /** TRUE if the value is the result of an expression. */
74 /** The integer value/range (\p type INT_VALUE); */
76 /** Beginning of the range. */
78 /** End of the range; equals \p i1 for a single integer. */
81 /** The real value/range (\p type REAL_VALUE); */
83 /** Beginning of the range. */
85 /** End of the range; equals \p r1 for a single number. */
88 /** The string value (\p type STR_VALUE); */
90 /** The position value (\p type POS_VALUE); */
92 /** The expression if \p bExpr is TRUE. */
93 struct t_selelem *expr;
95 /** Pointer to the next value. */
96 struct t_selexpr_value *next;
100 * Describes a parsed method parameter.
102 typedef struct t_selexpr_param
104 /** Name of the parameter. */
106 /** Number of values given for this parameter. */
108 /** Pointer to the first value. */
109 struct t_selexpr_value *value;
110 /** Pointer to the next parameter. */
111 struct t_selexpr_param *next;
114 /** Error reporting function for the selection parser. */
116 _gmx_selparser_error(const char *fmt, ...);
118 /** Allocates and initializes a constant \c t_selexpr_value. */
120 _gmx_selexpr_create_value(e_selvalue_t type);
121 /** Allocates and initializes an expression \c t_selexpr_value. */
123 _gmx_selexpr_create_value_expr(struct t_selelem *expr);
124 /** Allocates and initializes a \c t_selexpr_param. */
126 _gmx_selexpr_create_param(char *name);
128 /** Frees the memory allocated for a chain of values. */
130 _gmx_selexpr_free_values(t_selexpr_value *value);
131 /** Frees the memory allocated for a chain of parameters. */
133 _gmx_selexpr_free_params(t_selexpr_param *param);
135 /** Propagates the flags for selection elements. */
137 _gmx_selelem_update_flags(struct t_selelem *sel);
139 /** Initializes the method parameter data of \ref SEL_EXPRESSION and
140 * \ref SEL_MODIFIER elements. */
142 _gmx_selelem_init_method_params(struct t_selelem *sel, void *scanner);
143 /** Initializes the method for a \ref SEL_EXPRESSION selection element. */
145 _gmx_selelem_set_method(struct t_selelem *sel,
146 struct gmx_ana_selmethod_t *method, void *scanner);
148 /** Creates a \c t_selelem for arithmetic expression evaluation. */
150 _gmx_sel_init_arithmetic(struct t_selelem *left, struct t_selelem *right,
151 char op, void *scanner);
152 /** Creates a \c t_selelem for comparsion expression evaluation. */
154 _gmx_sel_init_comparison(struct t_selelem *left, struct t_selelem *right,
155 char *cmpop, void *scanner);
156 /** Creates a \c t_selelem for a keyword expression from the parsed data. */
158 _gmx_sel_init_keyword(struct gmx_ana_selmethod_t *method,
159 t_selexpr_value *args, const char *rpost, void *scanner);
160 /** Creates a \c t_selelem for a method expression from the parsed data. */
162 _gmx_sel_init_method(struct gmx_ana_selmethod_t *method,
163 t_selexpr_param *params, const char *rpost,
165 /** Creates a \c t_selelem for a modifier expression from the parsed data. */
167 _gmx_sel_init_modifier(struct gmx_ana_selmethod_t *mod, t_selexpr_param *params,
168 struct t_selelem *sel, void *scanner);
169 /** Creates a \c t_selelem for evaluation of reference positions. */
171 _gmx_sel_init_position(struct t_selelem *expr, const char *type, void *scanner);
173 /** Creates a \c t_selelem for a constant position. */
175 _gmx_sel_init_const_position(real x, real y, real z);
176 /** Creates a \c t_selelem for a index group expression using group name. */
178 _gmx_sel_init_group_by_name(const char *name, void *scanner);
179 /** Creates a \c t_selelem for a index group expression using group index. */
181 _gmx_sel_init_group_by_id(int id, void *scanner);
182 /** Creates a \c t_selelem for a variable reference */
184 _gmx_sel_init_variable_ref(struct t_selelem *sel);
186 /** Creates a root \c t_selelem for a selection. */
188 _gmx_sel_init_selection(char *name, struct t_selelem *sel, void *scanner);
189 /** Creates a root \c t_selelem elements for a variable assignment. */
191 _gmx_sel_assign_variable(char *name, struct t_selelem *expr, void *scanner);
192 /** Appends a root \c t_selelem to a selection collection. */
194 _gmx_sel_append_selection(struct t_selelem *sel, struct t_selelem *last,
196 /** Check whether the parser should finish. */
198 _gmx_sel_parser_should_finish(void *scanner);
200 /** Handle empty commands. */
202 _gmx_sel_handle_empty_cmd(void *scanner);
203 /** Process help commands. */
205 _gmx_sel_handle_help_cmd(char *topic, void *scanner);
208 /** Initializes an array of parameters based on input from the selection parser. */
210 _gmx_sel_parse_params(t_selexpr_param *pparams, int nparam,
211 struct gmx_ana_selparam_t *param, struct t_selelem *root,