Code beautification with uncrustify
[alexxy/gromacs.git] / src / gromacs / selection / scanner_internal.h
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
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.
13
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.
18  *
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.
25  *
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.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \internal \file
32  * \brief Internal header file used by the selection tokenizer.
33  *
34  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
35  * \ingroup module_selection
36  */
37 #ifndef SELECTION_SCANNER_INTERNAL_H
38 #define SELECTION_SCANNER_INTERNAL_H
39
40 #include <boost/exception_ptr.hpp>
41
42 #include "parser.h"
43
44 namespace gmx
45 {
46 class MessageStringCollector;
47 }
48
49 /* These need to be defined before including scanner_flex.h, because it
50  * uses YY_EXTRA_TYPE. But we also need to include it before defining
51  * gmx_sel_lexer_t; hence the forward declaration. */
52 struct gmx_sel_lexer_t;
53 #define YY_EXTRA_TYPE struct gmx_sel_lexer_t *
54
55 /* We cannot include scanner_flex.h from the scanner itself, because it
56  * seems to break everything. */
57 /* And we need to define YY_NO_UNISTD_H here as well, otherwise unistd.h
58  * gets included in other files than scanner.cpp... */
59 #ifndef FLEX_SCANNER
60 #define YY_NO_UNISTD_H
61 #include "scanner_flex.h"
62 #endif
63
64 /*! \internal \brief
65  * Internal data structure for the selection tokenizer state.
66  */
67 typedef struct gmx_sel_lexer_t
68 {
69     //! Selection collection to put parsed selections in.
70     struct gmx_ana_selcollection_t  *sc;
71     //! Error reporter object.
72     gmx::MessageStringCollector     *errors;
73     //! Stores an exception that occurred during parsing.
74     boost::exception_ptr             exception;
75     //! Whether external index groups have been set.
76     bool                             bGroups;
77     //! External index groups for resolving \c group keywords.
78     struct gmx_ana_indexgrps_t      *grps;
79     //! Number of selections at which the parser should stop.
80     int                              nexpsel;
81
82     //! Whether the parser is interactive.
83     bool                             bInteractive;
84
85     //! Pretty-printed version of the string parsed since last clear.
86     char                            *pselstr;
87     //! Length of the string in \a pselstr.
88     int                              pslen;
89     //! Number of bytes allocated for \a pselstr.
90     int                              nalloc_psel;
91
92     //! Stack of methods in which parameters should be looked up.
93     struct gmx_ana_selmethod_t     **mstack;
94     //! Index of the top of the stack in \a mstack.
95     int                              msp;
96     //! Number of elements allocated for \a mstack.
97     int                              mstack_alloc;
98
99     //! Number of END_OF_METHOD tokens to return before \a nextparam.
100     int                              neom;
101     //! Parameter symbol to return before resuming scanning.
102     struct gmx_ana_selparam_t       *nextparam;
103     //! Whether \a nextparam was a boolean parameter with a 'no' prefix.
104     bool                             bBoolNo;
105     /*! \brief
106      * Method symbol to return before resuming scanning
107      *
108      * Only used when \p nextparam is NULL.
109      */
110     struct gmx_ana_selmethod_t      *nextmethod;
111     //! Used to track whether the previous token was a position modifier.
112     int                              prev_pos_kw;
113
114     //! Whether the 'of' keyword is acceptable as the next token.
115     bool                             bMatchOf;
116     //! Whether boolean values (yes/no/on/off) are acceptable as the next token.
117     bool                             bMatchBool;
118     //! Whether the next token starts a new selection.
119     bool                             bCmdStart;
120
121     //! Whether an external buffer is set for the scanner.
122     bool                             bBuffer;
123     //! The current buffer for the scanner.
124     YY_BUFFER_STATE                  buffer;
125 } gmx_sel_lexer_t;
126
127 /* Because Flex defines yylval, yytext, and yyleng as macros,
128  * and this file is included from scanner.l,
129  * we cannot have them here as parameter names... */
130 /** Internal function for cases where several tokens need to be returned. */
131 int
132 _gmx_sel_lexer_process_pending(YYSTYPE *, gmx_sel_lexer_t *state);
133 /** Internal function that processes identifier tokens. */
134 int
135     _gmx_sel_lexer_process_identifier(YYSTYPE *, char *, size_t,
136                                       gmx_sel_lexer_t *state);
137 /** Internal function to add a token to the pretty-printed selection text. */
138 void
139 _gmx_sel_lexer_add_token(const char *str, int len, gmx_sel_lexer_t *state);
140
141 #endif