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
46 /*#include <typedefs.h>*/
47 #include <types/simple.h>
53 struct gmx_ana_indexgrps_t
;
54 struct gmx_ana_selmethod_t
;
55 struct gmx_ana_selparam_t
;
58 * Describes a parsed value, possibly resulting from expression evaluation.
60 typedef struct t_selexpr_value
62 /** Type of the value. */
64 /** TRUE if the value is the result of an expression. */
67 /** The integer value/range (\p type INT_VALUE); */
69 /** Beginning of the range. */
71 /** End of the range; equals \p i1 for a single integer. */
74 /** The real value/range (\p type REAL_VALUE); */
76 /** Beginning of the range. */
78 /** End of the range; equals \p r1 for a single number. */
81 /** The string value (\p type STR_VALUE); */
83 /** The position value (\p type POS_VALUE); */
85 /** The expression if \p bExpr is TRUE. */
86 struct t_selelem
*expr
;
88 /** Pointer to the next value. */
89 struct t_selexpr_value
*next
;
93 * Describes a parsed method parameter.
95 typedef struct t_selexpr_param
97 /** Name of the parameter. */
99 /** Number of values given for this parameter. */
101 /** Pointer to the first value. */
102 struct t_selexpr_value
*value
;
103 /** Pointer to the next parameter. */
104 struct t_selexpr_param
*next
;
107 /** Error reporting function for the selection parser. */
109 _gmx_selparser_error(const char *fmt
, ...);
111 /** Allocates and initializes a constant \c t_selexpr_value. */
113 _gmx_selexpr_create_value(e_selvalue_t type
);
114 /** Allocates and initializes an expression \c t_selexpr_value. */
116 _gmx_selexpr_create_value_expr(struct t_selelem
*expr
);
117 /** Allocates and initializes a \c t_selexpr_param. */
119 _gmx_selexpr_create_param(char *name
);
121 /** Frees the memory allocated for a chain of values. */
123 _gmx_selexpr_free_values(t_selexpr_value
*value
);
124 /** Frees the memory allocated for a chain of parameters. */
126 _gmx_selexpr_free_params(t_selexpr_param
*param
);
128 /** Propagates the flags for selection elements. */
130 _gmx_selelem_update_flags(struct t_selelem
*sel
);
132 /** Creates a \c t_selelem for comparsion expression evaluation. */
134 _gmx_sel_init_comparison(struct t_selelem
*left
, struct t_selelem
*right
,
135 char *cmpop
, void *scanner
);
136 /** Creates a \c t_selelem for a keyword expression from the parsed data. */
138 _gmx_sel_init_keyword(struct gmx_ana_selmethod_t
*method
,
139 t_selexpr_value
*args
, const char *rpost
, void *scanner
);
140 /** Creates a \c t_selelem for a method expression from the parsed data. */
142 _gmx_sel_init_method(struct gmx_ana_selmethod_t
*method
,
143 t_selexpr_param
*params
, const char *rpost
,
145 /** Creates a \c t_selelem for a modifier expression from the parsed data. */
147 _gmx_sel_init_modifier(struct gmx_ana_selmethod_t
*mod
, t_selexpr_param
*params
,
148 struct t_selelem
*sel
, void *scanner
);
149 /** Creates a \c t_selelem for evaluation of reference positions. */
151 _gmx_sel_init_position(struct t_selelem
*expr
, const char *type
, void *scanner
);
153 /** Creates a \c t_selelem for a constant position. */
155 _gmx_sel_init_const_position(real x
, real y
, real z
);
156 /** Creates a \c t_selelem for a index group expression using group name. */
158 _gmx_sel_init_group_by_name(const char *name
, void *scanner
);
159 /** Creates a \c t_selelem for a index group expression using group index. */
161 _gmx_sel_init_group_by_id(int id
, void *scanner
);
162 /** Creates a \c t_selelem for a variable reference */
164 _gmx_sel_init_variable_ref(struct t_selelem
*sel
);
166 /** Creates a root \c t_selelem for a selection. */
168 _gmx_sel_init_selection(char *name
, struct t_selelem
*sel
, void *scanner
);
169 /** Creates a root \c t_selelem elements for a variable assignment. */
171 _gmx_sel_assign_variable(char *name
, struct t_selelem
*expr
, void *scanner
);
172 /** Appends a root \c t_selelem to a selection collection. */
174 _gmx_sel_append_selection(struct t_selelem
*sel
, struct t_selelem
*last
,
176 /** Check whether the parser should finish. */
178 _gmx_sel_parser_should_finish(void *scanner
);
180 /** Handle empty commands. */
182 _gmx_sel_handle_empty_cmd(void *scanner
);
183 /** Process help commands. */
185 _gmx_sel_handle_help_cmd(char *topic
, void *scanner
);
188 /** Initializes an array of parameters based on input from the selection parser. */
190 _gmx_sel_parse_params(t_selexpr_param
*pparams
, int nparam
,
191 struct gmx_ana_selparam_t
*param
, struct t_selelem
*root
,