Some enhancements in the ftree compatibility.
[gedcom-parse.git] / gedcom / gedcom.y
index 3302c1b808fa718eab3af3e93aeae6f7992ce75b..10486dadc7889c8b6cec9eee958de326bbe00cfe 100644 (file)
 #include "interface.h"
 #include "date.h"
 #include "xref.h"
+#include "compat.h"
 
 int  count_level    = 0;
 int  fail           = 0;
@@ -211,7 +212,7 @@ int  compat_mode(int flags);
                      #TAG, parenttag);                                       \
          HANDLE_ERROR;                                                        \
        }                                                                      \
-     }
+     } 
 #define POP                                                                   \
      { pop_countarray();                                                      \
        --count_level;                                                         \
@@ -256,7 +257,7 @@ int  compat_mode(int flags);
 }
 
 %token_table
-%expect 300
+%expect 303
 
 %token <string> BADTOKEN
 %token <number> OPEN
@@ -443,13 +444,18 @@ head_sect    : OPEN DELIM TAG_HEAD
                                         NULL, GEDCOM_MAKE_NULL(val2));
                 START(HEAD, $<ctxt>$) }
                head_subs
-               { if (compat_mode(C_FTREE))
-                  CHECK3(SOUR, GEDC, CHAR)
+               { if (compat_mode(C_FTREE)) {
+                  CHECK3(SOUR, GEDC, CHAR);
+                  compat_generate_submitter_link($<ctxt>4);
+                }
                 else
                   CHECK4(SOUR, SUBM, GEDC, CHAR)
               }
                CLOSE
-               { end_record(REC_HEAD, $<ctxt>4); }
+               { end_record(REC_HEAD, $<ctxt>4);
+                if (compat_mode(C_FTREE))
+                  compat_generate_submitter();
+              }
              ;
 
 head_subs    : /* empty */
@@ -761,7 +767,9 @@ head_gedc_form_sect : OPEN DELIM TAG_FORM mand_line_item
 
 /* HEAD.CHAR */
 head_char_sect : OPEN DELIM TAG_CHAR mand_line_item 
-                 { if (open_conv_to_internal($4) == 0) YYERROR;
+                 { /* Don't allow to continue if conversion context couldn't
+                     be opened */
+                  if (open_conv_to_internal($4) == 0) YYABORT;
                   $<ctxt>$ = start_element(ELT_HEAD_CHAR,
                                            PARENT, $1, $3, $4,
                                            GEDCOM_MAKE_STRING(val1, $4));
@@ -1164,7 +1172,36 @@ indi_afn_sect  : OPEN DELIM TAG_AFN mand_line_item
 
 /* INDI.ADDR (Only for 'ftree' compatibility) */
 ftree_addr_sect : OPEN DELIM TAG_ADDR opt_line_item
-                  { START(ADDR, NULL) } no_std_subs { CHECK0 } CLOSE { }
+                  { if (compat_mode(C_FTREE)) {
+                     Gedcom_ctxt par = compat_generate_resi_start(PARENT);
+                     START(RESI, par);
+                     $<ctxt>$
+                       = start_element(ELT_SUB_ADDR,
+                                       par, $1 + 1, $3, $4,
+                                       GEDCOM_MAKE_NULL_OR_STRING(val2, $4));
+                     START(ADDR, $<ctxt>$);
+                   }
+                 else { START(ADDR, NULL) }
+                 }
+                  ftree_addr_subs
+                  { CHECK0 }
+                  CLOSE
+                  { if (compat_mode(C_FTREE)) {
+                     Gedcom_ctxt par = PARENT;
+                     end_element(ELT_SUB_ADDR, par, $<ctxt>5, NULL);
+                     CHECK0;
+                     compat_generate_resi_end(PARENT, par);
+                   } 
+                 }
+
+ftree_addr_subs : /* empty */
+                | ftree_addr_subs ftree_addr_sub
+                ;
+
+ftree_addr_sub  : continuation_sub
+                | phon_sect
+                | no_std_sub
+                ;
 
 /*********************************************************************/
 /**** Multimedia record                                           ****/
@@ -1744,7 +1781,7 @@ subm_subs  : /* empty */
            | subm_subs subm_sub
            ;
 
-subm_sub   : subm_name_sect  { OCCUR2(NAME, 0, 1) }
+subm_sub   : subm_name_sect  { OCCUR2(NAME, 1, 1) }
            | addr_struc_sub  /* 0:1 */
            | multim_link_sub  /* 0:M */
            | subm_lang_sect  { OCCUR2(LANG, 0, 3) }
@@ -3494,7 +3531,7 @@ mand_line_item : /* empty */ { gedcom_error(_("Missing value")); YYERROR; }
                                    $$ = $2; }
                ;
 
-opt_line_item : /* empty */ { }
+opt_line_item : /* empty */     { $$ = NULL; }
               | DELIM line_item { gedcom_debug_print("==Val: %s==", $2);
                                  $$ = $2; }
               ;
@@ -3546,7 +3583,7 @@ error_subs  : /* empty */
 error_sect  : OPEN DELIM opt_xref anytag opt_value error_subs CLOSE { }
 
 gen_sect    : OPEN DELIM opt_xref anystdtag
-              { INVALID_TAG($4); }
+              { INVALID_TAG($4.string); }
               opt_value opt_sects CLOSE
               { }
             ;
@@ -3556,7 +3593,7 @@ gen_rec : gen_rec_top
         ;
 
 gen_rec_norm : OPEN DELIM opt_xref anystdtag
-               { INVALID_TOP_TAG($4) }
+               { INVALID_TOP_TAG($4.string) }
                opt_value opt_sects CLOSE
                { }
              ;