a4a9a6c4b77af0f6357bad3fb6a59fd7d00274fd
[alexxy/gromacs.git] / src / gromacs / selection / scanner.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2009,2010,2011,2012, by the GROMACS development team, led by
5  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6  * others, as listed in the AUTHORS file in the top-level source
7  * directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \internal \file
36  * \brief
37  * Parser/scanner interaction functions.
38  *
39  * This is an implementation header: there should be no need to use it outside
40  * this directory.
41  */
42 #ifndef SELECTION_SCANNER_H
43 #define SELECTION_SCANNER_H
44
45 #include <boost/exception_ptr.hpp>
46
47 #include "parser.h"
48
49 namespace gmx
50 {
51 class MessageStringCollector;
52 }
53
54 struct gmx_ana_indexgrps_t;
55 struct gmx_ana_selcollection_t;
56
57 #ifndef YY_TYPEDEF_YY_SCANNER_T
58 #define YY_TYPEDEF_YY_SCANNER_T
59 typedef void *yyscan_t;
60 #endif
61
62 /** Initializes the selection scanner. */
63 void
64 _gmx_sel_init_lexer(yyscan_t *scannerp, struct gmx_ana_selcollection_t *sc,
65                     bool bInteractive, int maxnr, bool bGroups,
66                     struct gmx_ana_indexgrps_t *grps);
67 /** Frees memory allocated for the selection scanner. */
68 void
69 _gmx_sel_free_lexer(yyscan_t scanner);
70 /** Sets the error reporter object for the selection scanner. */
71 void
72 _gmx_sel_set_lexer_error_reporter(yyscan_t                     scanner,
73                                   gmx::MessageStringCollector *errors);
74 /** Stores an exception that is caught during parsing. */
75 void
76 _gmx_sel_lexer_set_exception(yyscan_t                    scanner,
77                              const boost::exception_ptr &ex);
78 /** Rethrows and clears the stored exception if one is present. */
79 // TODO: The semantics is a bit confusing, need to be thought more,
80 // but easier to do as part of larger refactoring of the parsing.
81 void
82 _gmx_sel_lexer_rethrow_exception_if_occurred(yyscan_t scanner);
83
84 /** Returns true if the scanner is interactive. */
85 bool
86 _gmx_sel_is_lexer_interactive(yyscan_t scanner);
87 /** Returns the selection collection for the scanner. */
88 struct gmx_ana_selcollection_t *
89 _gmx_sel_lexer_selcollection(yyscan_t scanner);
90 /** Returns the error reporter for the scanner. */
91 gmx::MessageStringCollector *
92 _gmx_sel_lexer_error_reporter(yyscan_t scanner);
93 /** Returns true if the external index groups for the scanner are set. */
94 bool
95 _gmx_sel_lexer_has_groups_set(yyscan_t scanner);
96 /** Returns the external index groups for the scanner. */
97 struct gmx_ana_indexgrps_t *
98 _gmx_sel_lexer_indexgrps(yyscan_t scanner);
99 /** Returns the number of selections after which the parser should stop. */
100 int
101 _gmx_sel_lexer_exp_selcount(yyscan_t scanner);
102
103 /** Returns a pretty string of the current selection.  */
104 const char *
105 _gmx_sel_lexer_pselstr(yyscan_t scanner);
106 /** Clears the current selection string.  */
107 void
108 _gmx_sel_lexer_clear_pselstr(yyscan_t scanner);
109 /** Clears the method stack in the scanner in error situations. */
110 void
111 _gmx_sel_lexer_clear_method_stack(yyscan_t scanner);
112 /** Notifies the scanner that a complete method expression has been parsed. */
113 void
114 _gmx_sel_finish_method(yyscan_t scanner);
115 /** Initializes the scanner to scan a file. */
116 void
117 _gmx_sel_set_lex_input_file(yyscan_t scanner, FILE *fp);
118 /** Initializes the scanner to scan a string. */
119 void
120 _gmx_sel_set_lex_input_str(yyscan_t scanner, const char *str);
121
122 /** The scanning function generated by Flex. */
123 #define YY_DECL int _gmx_sel_yylex(YYSTYPE *yylval, yyscan_t yyscanner)
124 YY_DECL;
125
126 #endif