/[mailutils]/mailutils/libsieve/sieve.y
ViewVC logotype

Diff of /mailutils/libsieve/sieve.y

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by gray, Thu Nov 7 14:48:23 2002 UTC revision 1.2 by gray, Fri Nov 8 15:53:37 2002 UTC
# Line 3  Line 3 
3     Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.     Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4    
5     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by     it under the terms of the GNU Lesser General Public License as published by
7     the Free Software Foundation; either version 2, or (at your option)     the Free Software Foundation; either version 2, or (at your option)
8     any later version.     any later version.
9    
10     This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.     GNU Lesser General Public License for more details.
14    
15     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU Lesser General Public License
16     along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
18    
# Line 20  Line 20 
20  # include <config.h>  # include <config.h>
21  #endif    #endif  
22  #include <stdio.h>  #include <stdio.h>
23    #include <stdlib.h>
24  #include <assert.h>  #include <assert.h>
25  #include <sieve.h>  #include <sieve.h>
   
26  %}  %}
27    
28  %token IDENT TAG NUMBER STRING MULTILINE  %union {
29  %token REQUIRE IF ELSIF ELSE ANYOF ALLOF TRUE FALSE NOT    char *string;
30      long number;
31      sieve_instr_t instr;
32      sieve_value_t *value;
33      list_t list;
34      struct {
35        char *ident;
36        list_t args;
37      } command;
38    }
39    
40    %token <string> IDENT TAG
41    %token <number> NUMBER
42    %token <string> STRING MULTILINE
43    %token REQUIRE IF ELSIF ELSE ANYOF ALLOF NOT
44    
45    %type <value> arg
46    %type <list> slist stringlist arglist maybe_arglist
47    %type <command> command
48    
49  %%  %%
50    
51  input        : /* empty */  input        : /* empty */
# Line 38  list         : statement Line 57  list         : statement
57               ;               ;
58    
59  statement    : REQUIRE stringlist ';'  statement    : REQUIRE stringlist ';'
60                   {
61                     sieve_require ($2);
62                     sieve_slist_destroy ($2);
63                   }
64               | action ';'               | action ';'
65               | IF cond block maybe_elsif maybe_else               | IF cond block maybe_elsif maybe_else
66               ;               ;
# Line 58  block        : '{' list '}' Line 81  block        : '{' list '}'
81               ;               ;
82    
83    
84  testlist     : test  testlist     : cond
85               | testlist ',' test               | testlist ',' cond
86               ;               ;
87    
88  cond         : test  cond         : test
# Line 68  cond         : test Line 91  cond         : test
91               | NOT cond               | NOT cond
92               ;               ;
93    
94  test         : FALSE  test         : command
95               | TRUE                 {
96               | command                   sieve_register_t *reg = sieve_test_lookup ($1.ident);
97                     if (!reg)
98                       sieve_error ("%s:%d: unknown test: %s",
99                                    sieve_filename, sieve_line_num,
100                                    $1.ident);
101                     else if (!reg->required)
102                       sieve_error ("%s:%d: test `%s' has not been required",
103                                    sieve_filename, sieve_line_num,
104                                    $1.ident);
105                     /*free unneeded memory */
106                   }
107               ;               ;
108    
109  command      : IDENT maybe_arglist  command      : IDENT maybe_arglist
110                   {
111                     $$.ident = $1;
112                     $$.args = $2;
113                   }
114               ;               ;
115    
116  action       : command  action       : command
117                   {
118                     sieve_register_t *reg = sieve_action_lookup ($1.ident);
119                     if (!reg)
120                       sieve_error ("%s:%d: unknown action: %s",
121                                    sieve_filename, sieve_line_num,
122                                    $1.ident);
123                     else if (!reg->required)
124                       sieve_error ("%s:%d: action `%s' has not been required",
125                                    sieve_filename, sieve_line_num,
126                                    $1.ident);
127                     /*free unneeded memory */
128                   }
129               ;               ;
130    
131  maybe_arglist: /* empty */  maybe_arglist: /* empty */
132                   {
133                     $$ = NULL;
134                   }
135               | arglist               | arglist
136               ;               ;
137    
138  arglist      : arg  arglist      : arg
139                   {
140                     list_create (&$$);
141                     list_append ($$, &$1);
142                   }                
143               | arglist arg               | arglist arg
144                   {
145                     list_append ($1, &$2);
146                     $$ = $1;
147                   }
148               ;               ;
149    
150  arg          : stringlist  arg          : stringlist
151                   {
152                     $$ = sieve_value_create (SVT_STRING_LIST, $1);
153                   }
154               | MULTILINE               | MULTILINE
155                   {
156                     $$ = sieve_value_create (SVT_STRING, $1);
157                   }
158               | NUMBER               | NUMBER
159                   {
160                     $$ = sieve_value_create (SVT_NUMBER, &$1);
161                   }
162               | TAG               | TAG
163                   {
164                     $$ = sieve_value_create (SVT_TAG, $1);
165                   }
166               ;               ;
167    
168  stringlist   : STRING  stringlist   : STRING
169                   {
170                     list_create (&$$);
171                     list_append ($$, $1);
172                   }
173               | '[' slist ']'               | '[' slist ']'
174                   {
175                     $$ = $2;
176                   }
177               ;               ;
178    
179  slist        : STRING  slist        : STRING
180                   {
181                     list_create (&$$);
182                     list_append ($$, $1);
183                   }
184               | slist ',' STRING               | slist ',' STRING
185                   {
186                     list_append ($1, $3);
187                     $$ = $1;
188                   }
189               ;               ;
190    
191  %%  %%
# Line 106  slist        : STRING Line 193  slist        : STRING
193  int  int
194  yyerror (char *s)  yyerror (char *s)
195  {  {
196    fprintf (stderr, "%s:%d: ", sieve_filename, sieve_line_num);    sieve_error ("%s:%d: %s", sieve_filename, sieve_line_num, s);
197    fprintf (stderr, "%s\n", s);    return 0;
198  }  }
199    
200  int  int
201  sieve_parse (const char *name)  sieve_parse (const char *name)
202  {  {
203      sieve_register_standard_actions ();
204      sieve_register_standard_tests ();
205    sieve_open_source (name);    sieve_open_source (name);
206    return yyparse ();    return yyparse ();
207  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26