aboutsummaryrefslogtreecommitdiffstats
path: root/libical/src/libical/icalyacc.y
blob: 982682d331074da1aaaf3213b32613cbb1e983bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
%{
/* -*- Mode: C -*-
  ======================================================================
  FILE: icalitip.y
  CREATOR: eric 10 June 1999
  
  DESCRIPTION:
  
  $Id: icalyacc.y,v 1.11 2001/01/23 20:22:33 jpr Exp $
  $Locker:  $

  (C) COPYRIGHT 1999 Eric Busboom 
  http://www.softwarestudio.org

  The contents of this file are subject to the Mozilla Public License
  Version 1.0 (the "License"); you may not use this file except in
  compliance with the License. You may obtain a copy of the License at
  http://www.mozilla.org/MPL/
 
  Software distributed under the License is distributed on an "AS IS"
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  the License for the specific language governing rights and
  limitations under the License.

  The original author is Eric Busboom
  The original code is icalitip.y



  =======================================================================*/

#include <stdlib.h>
#include <string.h> /* for strdup() */
#include "icalparser.h"
#include "pvl.h"

icalvalue *icalparser_yy_value; /* Current Value */

void ical_yyerror(char* s);
void icalparser_clear_flex_input();  
int ical_yy_lex(void);

/* Globals for UTCOFFSET values */
int utc; 
int utc_b; 
int utcsign;

/* Globals for DURATION values */
struct icaldurationtype duration;

/* Globals for TRIGGER values */
struct icaltriggertype trigger;

void copy_list(short* array, size_t size);
void add_prop(icalproperty_kind);
void icalparser_fill_date(struct tm* t, char* dstr);
void icalparser_fill_time(struct tm* t, char* tstr);
void set_value_type(icalvalue_kind kind);
void set_parser_value_state();
struct icaltimetype fill_datetime(char* d, char* t);
void ical_yy_error(char *s); /* Don't know why I need this.... */
int yylex(void); /* Or this. */



/* Set the state of the lexer so it will interpret values ( iCAL
   VALUEs, that is, ) correctly. */

%}

%union {
    float v_float;
    int   v_int;
    char* v_string;
}


  /* Renaming hack */

/*
#define    yymaxdepth ical_yy_maxdepth
#define    yyparse ical_yy_parse
#define    yyerror ical_yy_error
#define    yylval  ical_yy_lval
#define    yychar  ical_yy_char
#define    yydebug ical_yy_debug
#define    yypact  ical_yy_pact
#define    yyr1    ical_yy_r1
#define    yyr2    ical_yy_r2
#define    yydef   ical_yy_def
#define    yychk   ical_yy_chk
#define    yypgo   ical_yy_pgo
#define    yyact   ical_yy_act
#define    yyexca  ical_yy_exca
#define yyerrflag ical_yy_errflag
#define yynerrs    ical_yy_nerrs
#define    yyps    ical_yy_ps
#define    yypv    ical_yy_pv
#define    yys     ical_yy_s
#define    yy_yys  ical_yy_yys
#define    yystate ical_yy_state
#define    yytmp   ical_yy_tmp
#define    yyv     ical_yy_v
#define    yy_yyv  ical_yy_yyv
#define    yyval   ical_yy_val
#define    yylloc  ical_yy_lloc
#define yyreds     ical_yy_reds
#define yytoks     ical_yy_toks
#define yylhs      ical_yy_yylhs
#define yylen      ical_yy_yylen
#define yydefred ical_yy_yydefred
#define yydgoto    ical_yy_yydgoto
#define yydefred ical_yy_yydefred
#define yydgoto    ical_yy_yydgoto
#define yysindex ical_yy_yysindex
#define yyrindex ical_yy_yyrindex
#define yygindex ical_yy_yygindex
#define yytable     ical_yy_yytable
#define yycheck     ical_yy_yycheck
#define yyname   ical_yy_yyname
#define yyrule   ical_yy_yyrule
#define yy_scan_bytes ical_yy_scan_bytes
#define yy_scan_string ical_yy_scan_string
#define yy_scan_buffer ical_yy_scan_buffer
*/

/* These are redefined with the -P option to flex */
/*
#define yy_create_buffer  ical_yy_create_buffer 
#define yy_delete_buffer ical_yy_delete_buffer
#define yy_flex_debug ical_yy_flex_debug
#define yy_init_buffer ical_yy_init_buffer
#define yy_flush_buffer ical_yy_flush_buffer
#define yy_load_buffer_state ical_yy_load_buffer_state
#define yy_switch_to_buffer ical_yy_switch_to_buffer
#define yyin ical_yyin
#define yyleng ical_yyleng
#define yylex ical_yylex
#define yylineno ical_yylineno
#define yyout ical_yyout
#define yyrestart ical_yyrestart
#define yytext ical_yytext
#define yywrap ical_yywrap             
*/


%token <v_string> DIGITS
%token <v_int> INTNUMBER
%token <v_float> FLOATNUMBER
%token <v_string> STRING   
%token EOL EQUALS CHARACTER COLON COMMA SEMICOLON MINUS TIMESEPERATOR 

%token TRUE FALSE

%token FREQ BYDAY BYHOUR BYMINUTE BYMONTH BYMONTHDAY BYSECOND BYSETPOS BYWEEKNO
%token BYYEARDAY DAILY MINUTELY MONTHLY SECONDLY WEEKLY HOURLY YEARLY
%token INTERVAL COUNT UNTIL WKST MO SA SU TU WE TH FR 

%token BIT8 ACCEPTED ADD AUDIO BASE64 BINARY BOOLEAN BUSY BUSYTENTATIVE
%token BUSYUNAVAILABLE CALADDRESS CANCEL CANCELLED CHAIR CHILD COMPLETED
%token CONFIDENTIAL CONFIRMED COUNTER DATE DATETIME DECLINECOUNTER DECLINED
%token DELEGATED DISPLAY DRAFT DURATION EMAIL END FINAL FLOAT FREE GREGORIAN
%token GROUP INDIVIDUAL INPROCESS INTEGER NEEDSACTION NONPARTICIPANT
%token OPAQUE OPTPARTICIPANT PARENT PERIOD PRIVATE PROCEDURE PUBLIC PUBLISH
%token RECUR REFRESH REPLY REQPARTICIPANT REQUEST RESOURCE ROOM SIBLING
%token START TENTATIVE TEXT THISANDFUTURE THISANDPRIOR TIME TRANSPAENT
%token UNKNOWN UTCOFFSET XNAME

%token ALTREP CN CUTYPE DAYLIGHT DIR ENCODING EVENT FBTYPE FMTTYPE LANGUAGE 
%token MEMBER PARTSTAT RANGE RELATED RELTYPE ROLE RSVP SENTBY STANDARD URI

%token TIME_CHAR UTC_CHAR


%%

value:
    date_value
    | datetime_value
    | duration_value
    | period_value
        | utcoffset_value
        | error { 
                  icalparser_yy_value = 0;
          icalparser_clear_flex_input();
                  yyclearin;
                  }


date_value: DIGITS
        {
        struct icaltimetype stm;

        stm = fill_datetime($1,0);

        stm.hour = -1;
        stm.minute = -1;
        stm.second = -1;
        stm.is_utc = 0;
        stm.is_date = 1;

        icalparser_yy_value = icalvalue_new_date(stm);
    }

utc_char: 
    /*empty*/  {utc = 0;}
    | UTC_CHAR {utc = 1;}

/* This is used in the period_value, where there may be two utc characters per rule. */
utc_char_b: 
    /*empty*/  {utc_b = 0;}
    | UTC_CHAR {utc_b = 1;}

datetime_value: 
    DIGITS TIME_CHAR DIGITS utc_char
        {
        struct  icaltimetype stm;
        stm = fill_datetime($1, $3);
        stm.is_utc = utc;
        stm.is_date = 0;

        icalparser_yy_value = 
        icalvalue_new_datetime(stm);
    }


/* Duration */


dur_date: dur_day
    | dur_day dur_time

dur_week: DIGITS 'W'
    {
        duration.weeks = atoi($1);
    }

dur_time: TIME_CHAR dur_hour 
    {
    }
    | TIME_CHAR dur_minute
    {
    }
    | TIME_CHAR dur_second
    {
    }

dur_hour: DIGITS 'H'
    {
        duration.hours = atoi($1);
    }
    | DIGITS 'H' dur_minute
    {
        duration.hours = atoi($1);
    }

dur_minute: DIGITS 'M'
    {
        duration.minutes = atoi($1);
    }
    | DIGITS 'M' dur_second
    {
        duration.minutes = atoi($1);
    }

dur_second: DIGITS 'S'
    {
        duration.seconds = atoi($1);
    }

dur_day: DIGITS 'D'
    {
        duration.days = atoi($1);
    }

dur_prefix: /* empty */
    {
        duration.is_neg = 0;
    } 
    | '+'
    {
        duration.is_neg = 0;
    }
    | '-'
    { 
        duration.is_neg = 1;
    }

duration_value: dur_prefix 'P' dur_date
    { 
        icalparser_yy_value = icalvalue_new_duration(duration); 
        memset(&duration,0, sizeof(duration));
    }
    | dur_prefix 'P' dur_time
    { 
        icalparser_yy_value = icalvalue_new_duration(duration); 
        memset(&duration,0, sizeof(duration));
    }
    | dur_prefix 'P' dur_week
    { 
        icalparser_yy_value = icalvalue_new_duration(duration); 
        memset(&duration,0, sizeof(duration));
    }


/* Period */

period_value:  DIGITS TIME_CHAR DIGITS utc_char '/'  DIGITS TIME_CHAR DIGITS utc_char_b
    {
            struct icalperiodtype p;
        
        p.start = fill_datetime($1,$3);
        p.start.is_utc = utc;
        p.start.is_date = 0;


        p.end = fill_datetime($6,$8);
        p.end.is_utc = utc_b;
        p.end.is_date = 0;
        
        p.duration.days = -1;
        p.duration.weeks = -1;
        p.duration.hours = -1;
        p.duration.minutes = -1;
        p.duration.seconds = -1;

        icalparser_yy_value = icalvalue_new_period(p);
    }
    | DIGITS TIME_CHAR DIGITS utc_char '/'  duration_value
    {
            struct icalperiodtype p;
        
        p.start = fill_datetime($1,$3);
        p.start.is_utc = utc;
        p.start.is_date = 0;

        p.end.year = -1;
        p.end.month = -1;
        p.end.day = -1;
        p.end.hour = -1;
        p.end.minute = -1;
        p.end.second = -1;
           
        /* The duration_value rule setes the global 'duration'
               variable, but it also creates a new value in
               icalparser_yy_value. So, free that, then copy
               'duration' into the icalperiodtype struct. */

        p.duration = icalvalue_get_duration(icalparser_yy_value);
        icalvalue_free(icalparser_yy_value);
        icalparser_yy_value = 0;

        icalparser_yy_value = icalvalue_new_period(p);

    }


trigger: 
    


/* UTC Offset */

plusminus: '+' { utcsign = 1; }
    | '-' { utcsign = -1; }

utcoffset_value: 
    plusminus INTNUMBER INTNUMBER
    {
        icalparser_yy_value = icalvalue_new_utcoffset( utcsign * ($2*3600) + ($3*60) );
    }

    | plusminus INTNUMBER INTNUMBER INTNUMBER
    {
        icalparser_yy_value = icalvalue_new_utcoffset(utcsign * ($2*3600) + ($3*60) +($4));
    }

%%

struct icaltimetype fill_datetime(char* datestr, char* timestr)
{
        struct icaltimetype stm;

        memset(&stm,0,sizeof(stm));

        if (datestr != 0){
        sscanf(datestr,"%4d%2d%2d",&(stm.year), &(stm.month), 
               &(stm.day));
        }

        if (timestr != 0){
        sscanf(timestr,"%2d%2d%2d", &(stm.hour), &(stm.minute), 
               &(stm.second));
        }

        return stm;

}

void ical_yyerror(char* s)
{
    /*fprintf(stderr,"Parse error \'%s\'\n", s);*/
}