1 /* Parser for Gedcom dates.
2 Copyright (C) 2001 The Genes Development Team
3 This file is part of the Gedcom parser library.
4 Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
6 The Gedcom parser library is free software; you can redistribute it
7 and/or modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The Gedcom parser library is distributed in the hope that it will be
12 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the Gedcom parser library; if not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
31 struct date_value date_val;
35 %token <string> ESC_DATE_GREG
36 %token <string> ESC_DATE_JULN
37 %token <string> ESC_DATE_HEBR
38 %token <string> ESC_DATE_FREN
39 %token <string> MOD_FROM
40 %token <string> MOD_TO
41 %token <string> MOD_BEF
42 %token <string> MOD_AFT
43 %token <string> MOD_BET
44 %token <string> MOD_AND
45 %token <string> MOD_ABT
46 %token <string> MOD_CAL
47 %token <string> MOD_EST
48 %token <string> MOD_INT
49 %token <string> MON_JAN
50 %token <string> MON_FEB
51 %token <string> MON_MAR
52 %token <string> MON_APR
53 %token <string> MON_MAY
54 %token <string> MON_JUN
55 %token <string> MON_JUL
56 %token <string> MON_AUG
57 %token <string> MON_SEP
58 %token <string> MON_OCT
59 %token <string> MON_NOV
60 %token <string> MON_DEC
61 %token <string> MON_TSH
62 %token <string> MON_CSH
63 %token <string> MON_KSL
64 %token <string> MON_TVT
65 %token <string> MON_SHV
66 %token <string> MON_ADR
67 %token <string> MON_ADS
68 %token <string> MON_NSN
69 %token <string> MON_IYR
70 %token <string> MON_SVN
71 %token <string> MON_TMZ
72 %token <string> MON_AAV
73 %token <string> MON_ELL
74 %token <string> MON_VEND
75 %token <string> MON_BRUM
76 %token <string> MON_FRIM
77 %token <string> MON_NIVO
78 %token <string> MON_PLUV
79 %token <string> MON_VENT
80 %token <string> MON_GERM
81 %token <string> MON_FLOR
82 %token <string> MON_PRAI
83 %token <string> MON_MESS
84 %token <string> MON_THER
85 %token <string> MON_FRUC
86 %token <string> MON_COMP
90 %token <string> NUMBER
92 %token <string> BADTOKEN
94 %type <date_val> date_value
95 %type <date_val> date_period
96 %type <date_val> date_range
97 %type <date_val> date_approx
98 %type <date_val> date_interpr
99 %type <string> date_phrase
104 date_value : date { make_date_value(DV_NO_MODIFIER,
110 | date_phrase { make_date_value(DV_PHRASE,
111 def_date, def_date, $1); }
112 | error { /* On error: put entire string in 'phrase' member
114 make_date_value(DV_PHRASE,
115 def_date, def_date, curr_line_value); }
118 date : ESC_DATE_GREG date_greg { copy_date(&$$, date_s);
119 $$.cal = CAL_GREGORIAN; }
120 | ESC_DATE_JULN date_juln { copy_date(&$$, date_s);
121 $$.cal = CAL_JULIAN; }
122 | ESC_DATE_HEBR date_hebr { copy_date(&$$, date_s);
123 $$.cal = CAL_HEBREW; }
124 | ESC_DATE_FREN date_fren { copy_date(&$$, date_s);
125 $$.cal = CAL_FRENCH_REV; }
126 | date_greg { copy_date(&$$, date_s);
127 $$.cal = CAL_GREGORIAN; }
130 date_period : MOD_FROM date { make_date_value(DV_FROM,
132 | MOD_TO date { make_date_value(DV_TO,
134 | MOD_FROM date { copy_date(&$<date>$, $2); }
136 { make_date_value(DV_FROM_TO, $<date>3, $5, ""); }
139 date_range : MOD_BEF date { make_date_value(DV_BEFORE,
141 | MOD_AFT date { make_date_value(DV_AFTER,
143 | MOD_BET date { copy_date(&$<date>$, $2); }
145 { make_date_value(DV_BETWEEN, $<date>3, $5, ""); }
148 date_approx : MOD_ABT date { make_date_value(DV_ABOUT,
150 | MOD_CAL date { make_date_value(DV_CALCULATED,
152 | MOD_EST date { make_date_value(DV_ESTIMATED,
156 date_interpr : MOD_INT date date_phrase
157 { make_date_value(DV_INTERPRETED, $2, def_date, $3); }
160 date_phrase : OPEN TEXT CLOSE { $$ = $2; }
163 date_greg : day month_greg year_greg
164 | month_greg year_greg
168 date_juln : day month_greg year
173 date_hebr : day month_hebr year
178 date_fren : day month_fren year
185 if (strlen($1) <= MAX_DAY_LEN) {
186 strcpy(date_s.day_str, $1);
187 date_s.day = atoi($1);
190 gedcom_date_error(_("Too many characters in day '%s'"),
196 month_greg : MON_JAN { strcpy(date_s.month_str, $1);
198 | MON_FEB { strcpy(date_s.month_str, $1);
200 | MON_MAR { strcpy(date_s.month_str, $1);
202 | MON_APR { strcpy(date_s.month_str, $1);
204 | MON_MAY { strcpy(date_s.month_str, $1);
206 | MON_JUN { strcpy(date_s.month_str, $1);
208 | MON_JUL { strcpy(date_s.month_str, $1);
210 | MON_AUG { strcpy(date_s.month_str, $1);
212 | MON_SEP { strcpy(date_s.month_str, $1);
214 | MON_OCT { strcpy(date_s.month_str, $1);
216 | MON_NOV { strcpy(date_s.month_str, $1);
218 | MON_DEC { strcpy(date_s.month_str, $1);
222 month_hebr : MON_TSH { strcpy(date_s.month_str, $1);
224 | MON_CSH { strcpy(date_s.month_str, $1);
226 | MON_KSL { strcpy(date_s.month_str, $1);
228 | MON_TVT { strcpy(date_s.month_str, $1);
230 | MON_SHV { strcpy(date_s.month_str, $1);
232 | MON_ADR { strcpy(date_s.month_str, $1);
234 | MON_ADS { strcpy(date_s.month_str, $1);
236 | MON_NSN { strcpy(date_s.month_str, $1);
238 | MON_IYR { strcpy(date_s.month_str, $1);
240 | MON_SVN { strcpy(date_s.month_str, $1);
242 | MON_TMZ { strcpy(date_s.month_str, $1);
244 | MON_AAV { strcpy(date_s.month_str, $1);
246 | MON_ELL { strcpy(date_s.month_str, $1);
250 month_fren : MON_VEND { strcpy(date_s.month_str, $1);
252 | MON_BRUM { strcpy(date_s.month_str, $1);
254 | MON_FRIM { strcpy(date_s.month_str, $1);
256 | MON_NIVO { strcpy(date_s.month_str, $1);
258 | MON_PLUV { strcpy(date_s.month_str, $1);
260 | MON_VENT { strcpy(date_s.month_str, $1);
262 | MON_GERM { strcpy(date_s.month_str, $1);
264 | MON_FLOR { strcpy(date_s.month_str, $1);
266 | MON_PRAI { strcpy(date_s.month_str, $1);
268 | MON_MESS { strcpy(date_s.month_str, $1);
270 | MON_THER { strcpy(date_s.month_str, $1);
272 | MON_FRUC { strcpy(date_s.month_str, $1);
274 | MON_COMP { strcpy(date_s.month_str, $1);
279 { if (strlen($1) <= MAX_YEAR_LEN) {
280 strcpy(date_s.year_str, $1);
281 date_s.year = atoi($1);
282 date_s.year_type = YEAR_SINGLE;
285 gedcom_date_error(_("Too many characters in year '%s'"),
292 { if (strlen($1) <= MAX_YEAR_LEN) {
293 strcpy(date_s.year_str, $1);
294 date_s.year = atoi($1);
295 date_s.year_type = YEAR_SINGLE;
298 gedcom_date_error(_("Too many characters in year '%s'"),
302 | NUMBER SLASH NUMBER
303 { if (strlen($1) + strlen($3) + 1 <= MAX_YEAR_LEN) {
304 sprintf(date_s.year_str, "%s/%s", $1, $3);
305 date_s.year = atoi($1) + 1;
306 date_s.year_type = YEAR_DOUBLE;
309 gedcom_date_error(_("Too many characters in year '%s/%s'"),