3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
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.
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.
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.
29 * For more info, check our website at http://www.gromacs.org
31 /*! \cond \internal \file scanner.l
33 * Tokenizer for the selection language.
36 /*! \internal \file scanner.c
38 * Generated (from scanner.l by Flex) tokenizer for the selection language.
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)
59 FRAC (([[:digit:]]*"."{DSEQ})|{DSEQ}".")
61 REAL ("-"?(({FRAC}{EXP}?)|({DSEQ}{EXP})))
62 STRING (\"([^\"\\\n]|(\\\"))*\")
63 IDENTIFIER ([[:alpha:]][_[:alnum:]]*)
64 CMPOP (([<>]=?)|([!=]=))
70 %option prefix="_gmx_sel_yy"
71 %option header-file="scanner_flex.h"
73 %option never-interactive
83 gmx_sel_lexer_t *state = yyget_extra(yyscanner);
85 /* Return a token if one is pending */
86 retval = _gmx_sel_lexer_process_pending(yylval, state);
91 /* Handle the start conditions for 'of' matching */
95 state->bMatchOf = FALSE;
97 else if (state->bMatchBool)
100 state->bMatchBool = FALSE;
102 else if (state->bCmdStart)
105 state->bCmdStart = FALSE;
107 else if (YYSTATE != help)
114 {INTEGER} { yylval->i = strtol(yytext, NULL, 10); ADD_TOKEN; return TOK_INT; }
115 {REAL} { yylval->r = strtod(yytext, NULL); ADD_TOKEN; return TOK_REAL; }
116 {STRING} { yylval->str = strndup(yytext+1, yyleng-2); ADD_TOKEN; return STR; }
120 if (yytext[0] == ';' || state->bInteractive)
122 state->bCmdStart = TRUE;
123 rtrim(state->pselstr);
127 <cmdstart><<EOF>> { yyterminate(); }
128 <<EOF>> { state->bCmdStart = TRUE; return CMD_SEP; }
130 <cmdstart>help { BEGIN(help); return HELP; }
133 {IDENTIFIER} { yylval->str = strndup(yytext, yyleng); return HELP_TOPIC; }
134 ";"|\n { state->bCmdStart = TRUE; return CMD_SEP; }
135 . { return INVALID; }
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 = 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 = strndup(yytext, yyleng); ADD_TOKEN; return STR; }
155 . { _gmx_sel_lexer_add_token(yytext, 1, state); return yytext[0]; }