2007-02-20 [colin] 2.7.2cvs56
[claws.git] / src / matcher_parser_lex.l
index f3b7a559c391414f65f64e76454663ffaec49529..560293a38edbc2a5174cdf6b3afaf8353187ce97 100644 (file)
@@ -1,18 +1,54 @@
+%option nounput never-interactive
+
 %{
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (c) 2001-2007 by Hiroyuki Yamamoto & The Claws Mail 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <string.h>
+#include <glib.h>
+
+#include "codeconv.h"
+#include "matcher.h"
 #include "matcher_parser_lex.h"
+
+#ifndef YYSTYPE
 #include "matcher_parser_parse.h"
-#include <glib.h>
+#endif
 
 #define MAX_STR_CONST 512
 
-char string_buf[MAX_STR_CONST];
-char * string_buf_ptr;
+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"
@@ -23,64 +59,22 @@ static void add_char(char ch)
 %x section
 
 %%
+                       
+"in"   return MATCHER_IN; 
+
+                       /*
+                        * a keyword consists of alpha and underscore 
+                        * characters, possibly preceded by a tilde (~)
+                        */
+
+(~|[a-z])[a-z_]*       {
+                               gint id;
 
-"all"          return MATCHER_ALL;
-"unread"       return MATCHER_UNREAD;
-"~unread"      return MATCHER_NOT_UNREAD;
-"new"          return MATCHER_NEW;
-"~new"         return MATCHER_NOT_NEW;
-"marked"       return MATCHER_MARKED;
-"~marked"      return MATCHER_NOT_MARKED;
-"deleted"      return MATCHER_DELETED;
-"~deleted"     return MATCHER_NOT_DELETED;
-"replied"      return MATCHER_REPLIED;
-"~replied"     return MATCHER_NOT_REPLIED;
-"forwarded"    return MATCHER_FORWARDED;
-"~forwarded"   return MATCHER_NOT_FORWARDED;
-"subject"      return MATCHER_SUBJECT;
-"~subject"     return MATCHER_NOT_SUBJECT;
-"from"         return MATCHER_FROM;
-"~from"                return MATCHER_NOT_FROM;
-"to"           return MATCHER_TO;
-"~to"          return MATCHER_NOT_TO;
-"cc"           return MATCHER_CC;
-"~cc"          return MATCHER_NOT_CC;
-"to_or_cc"     return MATCHER_TO_OR_CC;
-"~to_or_cc"    return MATCHER_NOT_TO_AND_NOT_CC;
-"age_greater"  return MATCHER_AGE_GREATER;
-"age_lower"    return MATCHER_AGE_LOWER;
-"newsgroups"   return MATCHER_NEWSGROUPS;
-"~newsgroups"  return MATCHER_NOT_NEWSGROUPS;
-"inreplyto"    return MATCHER_INREPLYTO;
-"~inreplyto"   return MATCHER_NOT_INREPLYTO;
-"references"   return MATCHER_REFERENCES;
-"~references"  return MATCHER_NOT_REFERENCES;
-"score_greater"        return MATCHER_SCORE_GREATER;
-"score_lower"  return MATCHER_SCORE_LOWER;
-"header"       return MATCHER_HEADER;
-"~header"      return MATCHER_NOT_HEADER;
-"headers_part" return MATCHER_HEADERS_PART;
-"~headers_part"        return MATCHER_NOT_HEADERS_PART;
-"message"      return MATCHER_MESSAGE;
-"~message"     return MATCHER_NOT_MESSAGE;
-"body_part"    return MATCHER_BODY_PART;
-"~body_part"   return MATCHER_NOT_BODY_PART;
-"execute"      return MATCHER_EXECUTE;
-"~execute"     return MATCHER_NOT_EXECUTE;
-"matchcase"    return MATCHER_MATCHCASE;
-"match"                return MATCHER_MATCH;
-"regexpcase"   return MATCHER_REGEXPCASE;
-"regexp"       return MATCHER_REGEXP;
-"score"                return MATCHER_SCORE;
-"move"         return MATCHER_MOVE;
-"copy"         return MATCHER_COPY;
-"delete"       return MATCHER_DELETE;
-"mark"         return MATCHER_MARK;
-"unmark"       return MATCHER_UNMARK;
-"mark_as_read" return MATCHER_MARK_AS_READ;
-"mark_as_unread"       return MATCHER_MARK_AS_UNREAD;
-"forward"             return MATCHER_FORWARD;
-"forward_as_attachment"              return MATCHER_FORWARD_AS_ATTACHMENT;
+                               if (-1 == (id = get_matchparser_tab_id(yytext))) { 
+                                       REJECT;
+                               } else                                  
+                                       return id;
+                       }
 [ \t]+
 "\n"           return MATCHER_EOL;
 "&"            return MATCHER_AND;
@@ -89,28 +83,49 @@ static void add_char(char ch)
                BEGIN(string);
                string_buf_ptr = string_buf;
                }
-<string>\\n    add_char('\n');
-<string>\\t    add_char('\t');
-<string>\\r    add_char('\r');
-<string>\\b    add_char('\b');
-<string>\\f    add_char('\f');
-<string>\\.    add_char(yytext[1]);
 <string>\"     {
+               /* get out of the state: string ends. */
                BEGIN(0);
                *string_buf_ptr = '\0';
+               if (!g_utf8_validate(string_buf, -1, NULL)) {
+                       gchar *tmp = conv_codeset_strdup(string_buf, conv_get_locale_charset_str(), CS_INTERNAL);
+                       if (tmp) {
+                               strcpy(string_buf, tmp);
+                               g_free(tmp);
+                       }
+               }
                yylval.str = string_buf;
                return MATCHER_STRING;
                }
-<string>.      add_char(yytext[0]);
+<string>\\.    {
+                /* take care of quoted characters */
+               add_char(yytext[1]);
+               }
+<string>.      {
+               add_char(yytext[0]);
+               }
 \[[^\[\]]*\]   {
-                       BEGIN(0);
-                       yylval.str = yytext + 1;
-                       yytext[strlen(yytext) - 1] = '\0';
-                       return MATCHER_SECTION;
-                       }
+                /* 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;
                }
+rulename       {
+               return MATCHER_RULENAME;
+               }
+disabled       {
+               return MATCHER_DISABLED;
+               }
+account        {
+               return MATCHER_ACCOUNT;
+               }
+enabled        {
+               return MATCHER_ENABLED;
+               }
 
 %%