1 %option nounput never-interactive
2
3 %{
4 /*
5 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
6 * Copyright (c) 2001-2007 by Hiroyuki Yamamoto & The Claws Mail Team
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include <string.h>
24 #include <glib.h>
25
26 #include "codeconv.h"
27 #include "matcher.h"
28 #include "matcher_parser_lex.h"
29
30 #ifndef YYSTYPE
31 #include "matcher_parser_parse.h"
32 #endif
33
34 #define MAX_STR_CONST 8192
35
36 static char string_buf[MAX_STR_CONST];
37 static char *string_buf_ptr;
38
add_char(char ch)39 static void add_char(char ch)
40 {
41 if (string_buf_ptr - string_buf < sizeof(string_buf))
42 *string_buf_ptr++ = ch;
43 }
44
45
46 /* this function will reinitializes the parser */
47
matcher_parser_init(void)48 void matcher_parser_init(void)
49 {
50 BEGIN(0);
51 }
52 %}
53
54 %option prefix="matcher_parser"
55 %option outfile="lex.yy.c"
56 %option yylineno
57
58 %x string
59 %x section
60
61 %%
62
63 "in" return MATCHER_IN;
64
65 /*
66 * a keyword consists of alpha and underscore
67 * characters, possibly preceded by a tilde (~)
68 */
69
70 (~|[a-z])[a-z_]* {
71 gint id;
72
73 if (-1 == (id = get_matchparser_tab_id(yytext))) {
74 REJECT;
75 } else
76 return id;
77 }
78 [ \t]+
79 "\n" return MATCHER_EOL;
80 "&" return MATCHER_AND;
81 "|" return MATCHER_OR;
82 \" {
83 BEGIN(string);
84 string_buf_ptr = string_buf;
85 }
86 <string>\" {
87 /* get out of the state: string ends. */
88 BEGIN(0);
89 *string_buf_ptr = '\0';
90 if (!g_utf8_validate(string_buf, -1, NULL)) {
91 gchar *tmp = conv_codeset_strdup(string_buf, conv_get_locale_charset_str(), CS_INTERNAL);
92 if (tmp) {
93 g_strlcpy(string_buf, tmp, sizeof(string_buf));
94 g_free(tmp);
95 }
96 }
97 yylval.str = string_buf;
98 return MATCHER_STRING;
99 }
100 <string>\\. {
101 /* take care of quoted characters */
102 add_char(yytext[1]);
103 }
104 <string>. {
105 add_char(yytext[0]);
106 }
107 ^\[.*\]$ {
108 /* for section name in configuration file */
109 BEGIN(0);
110 yylval.str = yytext + 1;
111 yytext[strlen(yytext) - 1] = '\0';
112 return MATCHER_SECTION;
113 }
114 [-+]?[0-9]+ {
115 yylval.str = yytext;
116 return MATCHER_INTEGER;
117 }
118 rulename {
119 return MATCHER_RULENAME;
120 }
121 disabled {
122 return MATCHER_DISABLED;
123 }
124 account {
125 return MATCHER_ACCOUNT;
126 }
127 enabled {
128 return MATCHER_ENABLED;
129 }
130 . { /* silently eat unmatched input at lexer level */ }
131 %%
132