Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / selection / scanner_internal.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2009-2018, The GROMACS development team.
5  * Copyright (c) 2019, by the GROMACS development team, led by
6  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7  * and including many others, as listed in the AUTHORS file in the
8  * top-level source directory and at http://www.gromacs.org.
9  *
10  * GROMACS is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * as published by the Free Software Foundation; either version 2.1
13  * of the License, or (at your option) any later version.
14  *
15  * GROMACS is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with GROMACS; if not, see
22  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24  *
25  * If you want to redistribute modifications to GROMACS, please
26  * consider that scientific software is very special. Version
27  * control is crucial - bugs must be traceable. We will be happy to
28  * consider code for inclusion in the official distribution, but
29  * derived work must not be called official GROMACS. Details are found
30  * in the README & COPYING files - if they are missing, get the
31  * official version at http://www.gromacs.org.
32  *
33  * To help us fund GROMACS development, we humbly ask that you cite
34  * the research papers on the package. Check out http://www.gromacs.org.
35  */
36 /*! \internal \file
37  * \brief Internal header file used by the selection tokenizer.
38  *
39  * \author Teemu Murtola <teemu.murtola@gmail.com>
40  * \ingroup module_selection
41  */
42 #ifndef SELECTION_SCANNER_INTERNAL_H
43 #define SELECTION_SCANNER_INTERNAL_H
44
45 #include <exception>
46 #include <string>
47
48 #include "parser.h"
49
50 namespace gmx
51 {
52 class SelectionParserSymbol;
53 class TextWriter;
54 } // namespace gmx
55
56 /* These need to be defined before including scanner_flex.h, because it
57  * uses YY_EXTRA_TYPE. But we also need to include it before defining
58  * gmx_sel_lexer_t; hence the forward declaration. */
59 struct gmx_sel_lexer_t;
60 #define YY_EXTRA_TYPE struct gmx_sel_lexer_t*
61
62 /* We cannot include scanner_flex.h from the scanner itself, because it
63  * seems to break everything. */
64 /* And we need to define YY_NO_UNISTD_H here as well, otherwise unistd.h
65  * gets included in other files than scanner.cpp... */
66 #ifndef FLEX_SCANNER
67 #    define YY_NO_UNISTD_H
68 #    include "scanner_flex.h"
69 #endif
70
71 /*! \internal \brief
72  * Internal data structure for the selection tokenizer state.
73  */
74 typedef struct gmx_sel_lexer_t
75 {
76     //! Selection collection to put parsed selections in.
77     struct gmx_ana_selcollection_t* sc;
78     //! Stores an exception that occurred during parsing.
79     std::exception_ptr exception;
80     //! Whether external index groups have been set.
81     bool bGroups;
82     //! External index groups for resolving \c group keywords.
83     struct gmx_ana_indexgrps_t* grps;
84     //! Number of selections at which the parser should stop.
85     int nexpsel;
86
87     //! Writer to use for status output (if not NULL, parser is interactive).
88     gmx::TextWriter* statusWriter;
89
90     //! Pretty-printed version of the string parsed since last clear.
91     std::string pselstr;
92     /*! \brief
93      * Position of the result of the current Bison action.
94      *
95      * This identifies the part of \a pselstr that corresponds to the
96      * subselection that is currently being reduced by Bison.
97      */
98     gmx::SelectionLocation currentLocation;
99
100     //! Stack of methods in which parameters should be looked up.
101     struct gmx_ana_selmethod_t** mstack;
102     //! Index of the top of the stack in \a mstack.
103     int msp;
104     //! Number of elements allocated for \a mstack.
105     int mstack_alloc;
106
107     //! Number of END_OF_METHOD tokens to return before \a nextparam.
108     int neom;
109     //! Parameter symbol to return before resuming scanning.
110     struct gmx_ana_selparam_t* nextparam;
111     //! Whether \a nextparam was a boolean parameter with a 'no' prefix.
112     bool bBoolNo;
113     /*! \brief
114      * Method symbol to return before resuming scanning
115      *
116      * Only used when \p nextparam is NULL.
117      */
118     const gmx::SelectionParserSymbol* nextMethodSymbol;
119     //! Used to track whether the previous token was a position modifier.
120     int prev_pos_kw;
121
122     //! Whether the 'of' keyword is acceptable as the next token.
123     bool bMatchOf;
124     //! Whether boolean values (yes/no/on/off) are acceptable as the next token.
125     bool bMatchBool;
126     //! Whether the next token starts a new selection.
127     bool bCmdStart;
128
129     //! Whether an external buffer is set for the scanner.
130     bool bBuffer;
131     //! The current buffer for the scanner.
132     YY_BUFFER_STATE buffer;
133 } gmx_sel_lexer_t;
134
135 /* Because Flex defines yylval, yytext, and yyleng as macros,
136  * and this file is included from scanner.l,
137  * we cannot have them here as parameter names... */
138 /** Internal function for cases where several tokens need to be returned. */
139 int _gmx_sel_lexer_process_pending(YYSTYPE* /*yylval*/, YYLTYPE*, gmx_sel_lexer_t* state);
140 /** Internal function that processes identifier tokens. */
141 int _gmx_sel_lexer_process_identifier(YYSTYPE* /*yylval*/,
142                                       YYLTYPE*,
143                                       char* /*yytext*/,
144                                       size_t /*yyleng*/,
145                                       gmx_sel_lexer_t* state);
146 /** Internal function to add a token to the pretty-printed selection text. */
147 void _gmx_sel_lexer_add_token(YYLTYPE*, const char* str, int len, gmx_sel_lexer_t* state);
148
149 #endif