%{ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client * Copyright (c) 2001-2002 by Hiroyuki Yamamoto & The Sylpheed Claws Team. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include "matcher.h" #include "matcher_parser_lex.h" #include "matcher_parser_parse.h" #define MAX_STR_CONST 512 #define YY_NO_UNPUT 1 static char string_buf[MAX_STR_CONST]; static char *string_buf_ptr; static void add_char(char ch) { if (string_buf_ptr - string_buf < sizeof(string_buf)) *string_buf_ptr++ = ch; } /* this function will reinitializes the parser */ void matcher_parser_init(void) { BEGIN(0); } %} %option prefix="matcher_parser" %option outfile="lex.yy.c" %option yylineno %x string %x section %% /* * a keyword consists of alpha and underscore * characters, possibly preceded by a tilde (~) */ (~|[a-z])[a-z_]* { gint id; if (-1 == (id = get_matchparser_tab_id(yytext))) { REJECT; } else return id; } [ \t]+ "\n" return MATCHER_EOL; "&" return MATCHER_AND; "|" return MATCHER_OR; \" { BEGIN(string); string_buf_ptr = string_buf; } \" { /* get out of the state: string ends. */ BEGIN(0); *string_buf_ptr = '\0'; yylval.str = string_buf; return MATCHER_STRING; } \\. { /* take care of quoted characters */ add_char(yytext[1]); } . { add_char(yytext[0]); } \[[^\[\]]*\] { /* for section name in configuration file */ BEGIN(0); yylval.str = yytext + 1; yytext[strlen(yytext) - 1] = '\0'; return MATCHER_SECTION; } [-+]?[0-9]+ { yylval.str = yytext; return MATCHER_INTEGER; } %%