Better selection stdin handling.
[gromacs/qmmm-gamess-us.git] / src / gmxlib / selection / parsetree.h
blob66a4c570a9475528fc7fe678fc5d9242e955ced6
1 /*
3 * This source code is part of
5 * G R O M A C S
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
31 /*! \internal \file
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
38 * constructed.
40 * This is an implementation header: there should be no need to use it outside
41 * this directory.
43 #ifndef SELECTION_PARSETREE_H
44 #define SELECTION_PARSETREE_H
46 /*#include <typedefs.h>*/
47 #include <types/simple.h>
50 #include <selvalue.h>
52 struct t_selelem;
53 struct gmx_ana_indexgrps_t;
54 struct gmx_ana_selmethod_t;
55 struct gmx_ana_selparam_t;
57 /*! \internal \brief
58 * Describes a parsed value, possibly resulting from expression evaluation.
60 typedef struct t_selexpr_value
62 /** Type of the value. */
63 e_selvalue_t type;
64 /** TRUE if the value is the result of an expression. */
65 bool bExpr;
66 union {
67 /** The integer value/range (\p type INT_VALUE); */
68 struct {
69 /** Beginning of the range. */
70 int i1;
71 /** End of the range; equals \p i1 for a single integer. */
72 int i2;
73 } i;
74 /** The real value/range (\p type REAL_VALUE); */
75 struct {
76 /** Beginning of the range. */
77 real r1;
78 /** End of the range; equals \p r1 for a single number. */
79 real r2;
80 } r;
81 /** The string value (\p type STR_VALUE); */
82 char *s;
83 /** The position value (\p type POS_VALUE); */
84 rvec x;
85 /** The expression if \p bExpr is TRUE. */
86 struct t_selelem *expr;
87 } u;
88 /** Pointer to the next value. */
89 struct t_selexpr_value *next;
90 } t_selexpr_value;
92 /*! \internal \brief
93 * Describes a parsed method parameter.
95 typedef struct t_selexpr_param
97 /** Name of the parameter. */
98 char *name;
99 /** Number of values given for this parameter. */
100 int nval;
101 /** Pointer to the first value. */
102 struct t_selexpr_value *value;
103 /** Pointer to the next parameter. */
104 struct t_selexpr_param *next;
105 } t_selexpr_param;
107 /** Error reporting function for the selection parser. */
108 void
109 _gmx_selparser_error(const char *fmt, ...);
111 /** Allocates and initializes a constant \c t_selexpr_value. */
112 t_selexpr_value *
113 _gmx_selexpr_create_value(e_selvalue_t type);
114 /** Allocates and initializes an expression \c t_selexpr_value. */
115 t_selexpr_value *
116 _gmx_selexpr_create_value_expr(struct t_selelem *expr);
117 /** Allocates and initializes a \c t_selexpr_param. */
118 t_selexpr_param *
119 _gmx_selexpr_create_param(char *name);
121 /** Frees the memory allocated for a chain of values. */
122 void
123 _gmx_selexpr_free_values(t_selexpr_value *value);
124 /** Frees the memory allocated for a chain of parameters. */
125 void
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. */
133 struct t_selelem *
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. */
137 struct t_selelem *
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. */
141 struct t_selelem *
142 _gmx_sel_init_method(struct gmx_ana_selmethod_t *method,
143 t_selexpr_param *params, const char *rpost,
144 void *scanner);
145 /** Creates a \c t_selelem for a modifier expression from the parsed data. */
146 struct t_selelem *
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. */
150 struct t_selelem *
151 _gmx_sel_init_position(struct t_selelem *expr, const char *type, void *scanner);
153 /** Creates a \c t_selelem for a constant position. */
154 struct t_selelem *
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. */
157 struct t_selelem *
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. */
160 struct t_selelem *
161 _gmx_sel_init_group_by_id(int id, void *scanner);
162 /** Creates a \c t_selelem for a variable reference */
163 struct t_selelem *
164 _gmx_sel_init_variable_ref(struct t_selelem *sel);
166 /** Creates a root \c t_selelem for a selection. */
167 struct t_selelem *
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. */
170 struct t_selelem *
171 _gmx_sel_assign_variable(char *name, struct t_selelem *expr, void *scanner);
172 /** Appends a root \c t_selelem to a selection collection. */
173 struct t_selelem *
174 _gmx_sel_append_selection(struct t_selelem *sel, struct t_selelem *last,
175 void *scanner);
176 /** Check whether the parser should finish. */
177 bool
178 _gmx_sel_parser_should_finish(void *scanner);
180 /** Handle empty commands. */
181 void
182 _gmx_sel_handle_empty_cmd(void *scanner);
183 /** Process help commands. */
184 void
185 _gmx_sel_handle_help_cmd(char *topic, void *scanner);
187 /* In params.c */
188 /** Initializes an array of parameters based on input from the selection parser. */
189 bool
190 _gmx_sel_parse_params(t_selexpr_param *pparams, int nparam,
191 struct gmx_ana_selparam_t *param, struct t_selelem *root,
192 void *scanner);
194 #endif