0220dbd0764a5702be182992faff6dae296d8951
[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,2014,2015,2019, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source 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  * \author Teemu Murtola <teemu.murtola@gmail.com>
43  * \ingroup module_selection
44  */
45 #ifndef SELECTION_SCANNER_H
46 #define SELECTION_SCANNER_H
47
48 #include <exception>
49 #include <string>
50
51 #include "parser.h"
52
53 namespace gmx
54 {
55 class TextWriter;
56 }
57
58 struct gmx_ana_indexgrps_t;
59 struct gmx_ana_selcollection_t;
60
61 #ifndef YY_TYPEDEF_YY_SCANNER_T
62 #    define YY_TYPEDEF_YY_SCANNER_T
63 typedef void* yyscan_t;
64 #endif
65
66 /** Initializes the selection scanner. */
67 void _gmx_sel_init_lexer(yyscan_t*                       scannerp,
68                          struct gmx_ana_selcollection_t* sc,
69                          gmx::TextWriter*                statusWriter,
70                          int                             maxnr,
71                          bool                            bGroups,
72                          struct gmx_ana_indexgrps_t*     grps);
73 /** Frees memory allocated for the selection scanner. */
74 void _gmx_sel_free_lexer(yyscan_t scanner);
75 /** Stores an exception that is caught during parsing. */
76 void _gmx_sel_lexer_set_exception(yyscan_t scanner, const std::exception_ptr& ex);
77 /** Rethrows and clears the stored exception if one is present. */
78 // TODO: The semantics is a bit confusing, need to be thought more,
79 // but easier to do as part of larger refactoring of the parsing.
80 void _gmx_sel_lexer_rethrow_exception_if_occurred(yyscan_t scanner);
81
82 /** Returns writer for status output (if not NULL, the scanner is interactive). */
83 gmx::TextWriter* _gmx_sel_lexer_get_status_writer(yyscan_t scanner);
84 /** Returns the selection collection for the scanner. */
85 struct gmx_ana_selcollection_t* _gmx_sel_lexer_selcollection(yyscan_t scanner);
86 /** Returns true if the external index groups for the scanner are set. */
87 bool _gmx_sel_lexer_has_groups_set(yyscan_t scanner);
88 /** Returns the external index groups for the scanner. */
89 struct gmx_ana_indexgrps_t* _gmx_sel_lexer_indexgrps(yyscan_t scanner);
90 /** Returns the number of selections after which the parser should stop. */
91 int _gmx_sel_lexer_exp_selcount(yyscan_t scanner);
92
93 /** Returns a pretty string of the current selection.  */
94 const char* _gmx_sel_lexer_pselstr(yyscan_t scanner);
95 /*! \brief
96  * Sets the current parser context location.
97  *
98  * This location is set while Bison reductions are being processed, and
99  * identifies the location of the current rule/reduction.
100  */
101 void _gmx_sel_lexer_set_current_location(yyscan_t scanner, const gmx::SelectionLocation& location);
102 /*! \brief
103  * Returns the current parser context location.
104  *
105  * This returns the location last set with
106  * _gmx_sel_lexer_set_current_location().
107  */
108 const gmx::SelectionLocation& _gmx_sel_lexer_get_current_location(yyscan_t scanner);
109 /*! \brief
110  * Returns the selection text for the current parser context.
111  *
112  * This returns the selection text that corresponds to the position set last
113  * with _gmx_sel_lexer_set_current_location().
114  */
115 std::string _gmx_sel_lexer_get_current_text(yyscan_t scanner);
116 /*! \brief
117  * Returns the selection text at the given location.
118  */
119 std::string _gmx_sel_lexer_get_text(yyscan_t scanner, const gmx::SelectionLocation& location);
120 /** Clears the current selection string.  */
121 void _gmx_sel_lexer_clear_pselstr(yyscan_t scanner);
122 /** Clears the method stack in the scanner in error situations. */
123 void _gmx_sel_lexer_clear_method_stack(yyscan_t scanner);
124 /** Notifies the scanner that a complete method expression has been parsed. */
125 void _gmx_sel_finish_method(yyscan_t scanner);
126 /** Initializes the scanner to scan a file. */
127 void _gmx_sel_set_lex_input_file(yyscan_t scanner, FILE* fp);
128 /** Initializes the scanner to scan a string. */
129 void _gmx_sel_set_lex_input_str(yyscan_t scanner, const char* str);
130
131 /** The scanning function generated by Flex. */
132 #define YY_DECL int _gmx_sel_yylex(YYSTYPE* yylval, YYLTYPE* yylloc, yyscan_t yyscanner)
133 YY_DECL;
134
135 #endif