802c8f72130c7ffda1f458ff7afa3531b81a77f8
[alexxy/gromacs.git] / src / gmxlib / 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 #ifndef SELECTION_SCANNER_INTERNAL_H
35 #define SELECTION_SCANNER_INTERNAL_H
36
37 #include "parser.h"
38
39 /** The scanning function generated by Flex. */
40 #define YY_DECL int _gmx_sel_yylex(YYSTYPE *yylval, yyscan_t yyscanner)
41 YY_DECL;
42
43 /* These need to be defined before including scanner_flex.h, because it
44  * uses YY_EXTRA_TYPE. But we also need to include it before defining
45  * gmx_sel_lexer_t; hence the forward declaration. */
46 struct gmx_sel_lexer_t;
47 #define YY_EXTRA_TYPE struct gmx_sel_lexer_t *
48
49 /* We cannot include scanner_flex.h from the scanner itself, because it
50  * seems to break everything. */
51 /* And we need to define YY_NO_UNISTD_H here as well, otherwise unistd.h
52  * gets included in other files than scanner.c... */
53 #ifndef FLEX_SCANNER
54 #define YY_NO_UNISTD_H
55 #include "scanner_flex.h"
56 #endif
57
58 /*! \brief
59  * Internal data structure for the selection tokenizer state.
60  */
61 typedef struct gmx_sel_lexer_t
62 {
63     struct gmx_ana_selcollection_t  *sc;
64     struct gmx_ana_indexgrps_t      *grps;
65     int                              nexpsel;
66
67     gmx_bool                             bInteractive;
68     char                            *inputstr;
69     int                              nalloc_input;
70
71     char                            *pselstr;
72     int                              pslen;
73     int                              nalloc_psel;
74
75     struct gmx_ana_selmethod_t     **mstack;
76     int                              msp;
77     int                              mstack_alloc;
78
79     int                              neom;
80     struct gmx_ana_selparam_t       *nextparam;
81     gmx_bool                             bBoolNo;
82     struct gmx_ana_selmethod_t      *nextmethod;
83     int                              prev_pos_kw;
84
85     gmx_bool                             bMatchOf;
86     gmx_bool                             bMatchBool;
87     gmx_bool                             bCmdStart;
88
89     gmx_bool                             bBuffer;
90     YY_BUFFER_STATE                  buffer;
91 } gmx_sel_lexer_t;
92
93 /* Because Flex defines yylval, yytext, and yyleng as macros,
94  * and this file is included from scanner.l,
95  * we cannot have them here as parameter names... */
96 /** Internal function for cases where several tokens need to be returned. */
97 int
98 _gmx_sel_lexer_process_pending(YYSTYPE *, gmx_sel_lexer_t *state);
99 /** Internal function that processes identifier tokens. */
100 int
101 _gmx_sel_lexer_process_identifier(YYSTYPE *, char *, size_t,
102                                   gmx_sel_lexer_t *state);
103 /** Internal function to add a token to the pretty-printed selection text. */
104 void
105 _gmx_sel_lexer_add_token(const char *str, int len, gmx_sel_lexer_t *state);
106
107 #endif