Merge branch 'master' of git://git.gromacs.org/gromacs
[gromacs/adressmacs.git] / src / gmxlib / selection / scanner.l
blobb23b2b3389b6369004f845b9c3fec8270d3ff40e
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.
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 /*! \cond \internal \file scanner.l
32  * \brief
33  * Tokenizer for the selection language.
34  * \endcond
35  */
36 /*! \internal \file scanner.c
37  * \brief
38  * Generated (from scanner.l by Flex) tokenizer for the selection language.
39  */
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
45 #include <string2.h>
47 #include "parser.h"
48 #include "scanner.h"
49 #include "scanner_internal.h"
51 /* This macro is here to make the actions a bit shorter, since nearly every
52  * action needs this call. */
53 #define ADD_TOKEN _gmx_sel_lexer_add_token(yytext, yyleng, state)
57 INTEGER    [[:digit:]]+
58 DSEQ       ([[:digit:]]+)
59 FRAC       (([[:digit:]]*"."{DSEQ})|{DSEQ}".")
60 EXP        ([eE][+-]?{DSEQ})
61 REAL       (({FRAC}{EXP}?)|({DSEQ}{EXP}))
62 STRING     (\"([^\"\\\n]|(\\\"))*\")
63 IDENTIFIER ([[:alpha:]][_[:alnum:]]*)
64 CMPOP      (([<>]=?)|([!=]=))
65 COMMENT    (#.*)
67 %option nodefault
68 %option noyywrap
69 %option reentrant
70 %option prefix="_gmx_sel_yy"
71 %option header-file="scanner_flex.h"
72 %option nounistd
73 %option never-interactive
75 %s matchof
76 %s matchbool
77 %s cmdstart
78 %x help
83     gmx_sel_lexer_t *state = yyget_extra(yyscanner);
84     int              retval;
85     /* Return a token if one is pending */
86     retval = _gmx_sel_lexer_process_pending(yylval, state);
87     if (retval != 0)
88     {
89         return retval;
90     }
91     /* Handle the start conditions for 'of' matching */
92     if (state->bMatchOf)
93     {
94         BEGIN(matchof);
95         state->bMatchOf = FALSE;
96     }
97     else if (state->bMatchBool)
98     {
99         BEGIN(matchbool);
100         state->bMatchBool = FALSE;
101     }
102     else if (state->bCmdStart)
103     {
104         BEGIN(cmdstart);
105     }
106     else if (YYSTATE != help)
107     {
108         BEGIN(0);
109     }
112 {COMMENT}
113 {INTEGER}       { yylval->i   = strtol(yytext, NULL, 10);    ADD_TOKEN; return TOK_INT; }
114 {REAL}          { yylval->r   = strtod(yytext, NULL);        ADD_TOKEN; return TOK_REAL; }
115 {STRING}        { yylval->str = gmx_strndup(yytext+1, yyleng-2); ADD_TOKEN; return STR;  }
117 \\\n            { _gmx_sel_lexer_add_token(" ", 1, state); }
118 ";"|\n          {
119                     if (yytext[0] == ';' || state->bInteractive)
120                     {
121                         rtrim(state->pselstr);
122                         return CMD_SEP;
123                     }
124                     else
125                     {
126                         _gmx_sel_lexer_add_token(" ", 1, state);
127                     }
128                 }
130 <cmdstart>help  { BEGIN(help); return HELP; }
131 <help>{
132 [[:blank:]]+
133 {IDENTIFIER}    { yylval->str = gmx_strndup(yytext, yyleng); return HELP_TOPIC; }
134 ";"|\n          { return CMD_SEP; }
135 .               { return INVALID; }
138 <matchbool>{
139 yes|on          { ADD_TOKEN; yylval->i = 1; return TOK_INT; }
140 no|off          { ADD_TOKEN; yylval->i = 0; return TOK_INT; }
142 group           { ADD_TOKEN; return GROUP; }
143 to              { ADD_TOKEN; return TO; }
144 <matchof>of     { ADD_TOKEN; BEGIN(0); return OF; }
145 and|"&&"        { ADD_TOKEN; return AND; }
146 or|"||"         { ADD_TOKEN; return OR; }
147 xor             { ADD_TOKEN; return XOR; }
148 not|"!"         { ADD_TOKEN; return NOT; }
149 {CMPOP}         { yylval->str = gmx_strndup(yytext, yyleng); ADD_TOKEN; return CMP_OP; }
151 {IDENTIFIER}    { return _gmx_sel_lexer_process_identifier(yylval, yytext, yyleng, state); }
153 [[:blank:]]+    { _gmx_sel_lexer_add_token(" ", 1, state); }
154 [_[:alnum:]]+   { yylval->str = gmx_strndup(yytext, yyleng); ADD_TOKEN; return STR; }
155 .               { ADD_TOKEN; return yytext[0]; }