2001-07-08 17:34:02 +02:00
|
|
|
%{
|
2002-12-27 21:55:50 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-09-29 15:43:33 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
#include "matcher.h"
|
2001-07-08 17:34:02 +02:00
|
|
|
#include "matcher_parser_lex.h"
|
|
|
|
#include "matcher_parser_parse.h"
|
|
|
|
|
|
|
|
#define MAX_STR_CONST 512
|
2002-11-21 01:54:52 +01:00
|
|
|
#define YY_NO_UNPUT 1
|
2001-07-08 17:34:02 +02:00
|
|
|
|
2002-12-27 21:55:50 +01:00
|
|
|
static char string_buf[MAX_STR_CONST];
|
|
|
|
static char *string_buf_ptr;
|
2001-07-08 17:34:02 +02:00
|
|
|
|
|
|
|
static void add_char(char ch)
|
|
|
|
{
|
|
|
|
if (string_buf_ptr - string_buf < sizeof(string_buf))
|
|
|
|
*string_buf_ptr++ = ch;
|
|
|
|
}
|
2002-11-10 17:10:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* this function will reinitializes the parser */
|
|
|
|
|
|
|
|
void matcher_parser_init(void)
|
|
|
|
{
|
|
|
|
BEGIN(0);
|
|
|
|
}
|
2001-07-08 17:34:02 +02:00
|
|
|
%}
|
|
|
|
|
|
|
|
%option prefix="matcher_parser"
|
|
|
|
%option outfile="lex.yy.c"
|
|
|
|
%option yylineno
|
|
|
|
|
|
|
|
%x string
|
|
|
|
%x section
|
|
|
|
|
|
|
|
%%
|
2002-12-27 18:00:27 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* a keyword consists of alpha and underscore
|
|
|
|
* characters, possibly preceded by a tilde (~)
|
|
|
|
*/
|
2001-07-08 17:34:02 +02:00
|
|
|
|
2002-12-27 18:00:27 +01:00
|
|
|
(~|[a-z])[a-z_]* {
|
|
|
|
gint id;
|
|
|
|
|
|
|
|
if (-1 == (id = get_matchparser_tab_id(yytext))) {
|
|
|
|
REJECT;
|
|
|
|
} else
|
|
|
|
return id;
|
|
|
|
}
|
2001-07-08 17:34:02 +02:00
|
|
|
[ \t]+
|
|
|
|
"\n" return MATCHER_EOL;
|
|
|
|
"&" return MATCHER_AND;
|
|
|
|
"|" return MATCHER_OR;
|
|
|
|
\" {
|
|
|
|
BEGIN(string);
|
|
|
|
string_buf_ptr = string_buf;
|
|
|
|
}
|
|
|
|
<string>\" {
|
2001-12-12 23:05:46 +01:00
|
|
|
/* get out of the state: string ends. */
|
2001-07-08 17:34:02 +02:00
|
|
|
BEGIN(0);
|
|
|
|
*string_buf_ptr = '\0';
|
|
|
|
yylval.str = string_buf;
|
|
|
|
return MATCHER_STRING;
|
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
<string>\\. {
|
|
|
|
/* take care of quoted characters */
|
|
|
|
add_char(yytext[1]);
|
|
|
|
}
|
2001-07-09 18:06:03 +02:00
|
|
|
<string>. {
|
2001-12-12 23:05:46 +01:00
|
|
|
add_char(yytext[0]);
|
|
|
|
}
|
2001-07-08 17:34:02 +02:00
|
|
|
\[[^\[\]]*\] {
|
2004-01-12 22:28:31 +01:00
|
|
|
/* for section name in configuration file */
|
2001-12-12 23:05:46 +01:00
|
|
|
BEGIN(0);
|
|
|
|
yylval.str = yytext + 1;
|
|
|
|
yytext[strlen(yytext) - 1] = '\0';
|
|
|
|
return MATCHER_SECTION;
|
|
|
|
}
|
2001-07-08 17:34:02 +02:00
|
|
|
[-+]?[0-9]+ {
|
|
|
|
yylval.str = yytext;
|
|
|
|
return MATCHER_INTEGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
%%
|