re-organize matcher part 2; more to come but this should
[claws.git] / src / matcher_parser_lex.l
1 %{
2 #include <string.h>
3 #include <glib.h>
4
5 #include "matcher_parser_lex.h"
6 #include "matcher_parser_parse.h"
7
8 #define MAX_STR_CONST 512
9 #define YY_NO_UNPUT 1
10
11 char string_buf[MAX_STR_CONST];
12 char * string_buf_ptr;
13
14 static void add_char(char ch)
15 {
16         if (string_buf_ptr - string_buf < sizeof(string_buf))
17                 *string_buf_ptr++ = ch;
18 }
19
20
21 /* this function will reinitializes the parser */
22
23 void matcher_parser_init(void)
24 {
25         BEGIN(0);
26 }
27 %}
28
29 %option prefix="matcher_parser"
30 %option outfile="lex.yy.c"
31 %option yylineno
32
33 %x string
34 %x section
35
36 %%
37                         
38                         /*
39                          * a keyword consists of alpha and underscore 
40                          * characters, possibly preceded by a tilde (~)
41                          */
42
43 (~|[a-z])[a-z_]*        {
44                                 gint id;
45
46                                 if (-1 == (id = get_matchparser_tab_id(yytext))) { 
47                                         REJECT;
48                                 } else                                  
49                                         return id;
50                         }
51 [ \t]+
52 "\n"            return MATCHER_EOL;
53 "&"             return MATCHER_AND;
54 "|"             return MATCHER_OR;
55 \"              {
56                 BEGIN(string);
57                 string_buf_ptr = string_buf;
58                 }
59                 /* alfons - OK, the new attempt is to just swallow 
60                  * *EVERYTHING* and make sure everything is escaped
61                  * when actually performing things. */
62 <string>\\\"    {
63                 /* take care of escaped \" because this means the
64                  * quote char should be skipped */
65                 add_char('\\');
66                 add_char('\"');
67                 }
68 <string>\"      {
69                 /* get out of the state: string ends. */
70                 BEGIN(0);
71                 *string_buf_ptr = '\0';
72                 yylval.str = string_buf;
73                 return MATCHER_STRING;
74                 }
75                 /* put everything else in the output. */
76 <string>.       {
77                 add_char(yytext[0]);
78                 }
79 \[[^\[\]]*\]    {
80                 BEGIN(0);
81                 yylval.str = yytext + 1;
82                 yytext[strlen(yytext) - 1] = '\0';
83                 return MATCHER_SECTION;
84                 }
85 [-+]?[0-9]+     {
86                 yylval.str = yytext;
87                 return MATCHER_INTEGER;
88                 }
89
90 %%