sync with 0.8.11cvs14
[claws.git] / src / matcher_parser_lex.l
1 %{
2 /*
3  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
4  * Copyright (c) 2001-2002 by Hiroyuki Yamamoto & The Sylpheed Claws Team.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #include <string.h>
22 #include <glib.h>
23
24 #include "matcher_parser_lex.h"
25 #include "matcher_parser_parse.h"
26
27 #define MAX_STR_CONST 512
28 #define YY_NO_UNPUT 1
29
30 static char string_buf[MAX_STR_CONST];
31 static char *string_buf_ptr;
32
33 static void add_char(char ch)
34 {
35         if (string_buf_ptr - string_buf < sizeof(string_buf))
36                 *string_buf_ptr++ = ch;
37 }
38
39
40 /* this function will reinitializes the parser */
41
42 void matcher_parser_init(void)
43 {
44         BEGIN(0);
45 }
46 %}
47
48 %option prefix="matcher_parser"
49 %option outfile="lex.yy.c"
50 %option yylineno
51
52 %x string
53 %x section
54
55 %%
56                         
57                         /*
58                          * a keyword consists of alpha and underscore 
59                          * characters, possibly preceded by a tilde (~)
60                          */
61
62 (~|[a-z])[a-z_]*        {
63                                 gint id;
64
65                                 if (-1 == (id = get_matchparser_tab_id(yytext))) { 
66                                         REJECT;
67                                 } else                                  
68                                         return id;
69                         }
70 [ \t]+
71 "\n"            return MATCHER_EOL;
72 "&"             return MATCHER_AND;
73 "|"             return MATCHER_OR;
74 \"              {
75                 BEGIN(string);
76                 string_buf_ptr = string_buf;
77                 }
78                 /* alfons - OK, the new attempt is to just swallow 
79                  * *EVERYTHING* and make sure everything is escaped
80                  * when actually performing things. */
81 <string>\\\"    {
82                 /* take care of escaped \" because this means the
83                  * quote char should be skipped */
84                 add_char('\\');
85                 add_char('\"');
86                 }
87 <string>\"      {
88                 /* get out of the state: string ends. */
89                 BEGIN(0);
90                 *string_buf_ptr = '\0';
91                 yylval.str = string_buf;
92                 return MATCHER_STRING;
93                 }
94                 /* put everything else in the output. */
95 <string>.       {
96                 add_char(yytext[0]);
97                 }
98 \[[^\[\]]*\]    {
99                 BEGIN(0);
100                 yylval.str = yytext + 1;
101                 yytext[strlen(yytext) - 1] = '\0';
102                 return MATCHER_SECTION;
103                 }
104 [-+]?[0-9]+     {
105                 yylval.str = yytext;
106                 return MATCHER_INTEGER;
107                 }
108
109 %%