Copied from old documentation. Removed all Gedcom_val details.
[gedcom-parse.git] / gedcom / gedcom.y
index 702d1256dcba2c8f921ce3074776e0bc1f2c91d0..5448c74b89e26a3d6207e0fa33b37f9b5cb86aae 100644 (file)
@@ -164,6 +164,10 @@ struct safe_buffer line_item_buffer = { NULL, 0, NULL, 0,
 
 void cleanup_concat_buffer(); 
 struct safe_buffer concat_buffer = { NULL, 0, NULL, 0, cleanup_concat_buffer };
+
+void cleanup_usertag_buffer();
+struct safe_buffer usertag_buffer = { NULL, 0, NULL, 0,
+                                     cleanup_usertag_buffer};
  
 /* These are defined at the bottom of the file */ 
 void push_countarray(int level);
@@ -174,13 +178,14 @@ Gedcom_ctxt get_parentctxt(int offset);
 void pop_countarray();
 int  count_tag(int tag);
 int  check_occurrence(int tag);
-void clean_up(); 
+void clean_up();
 
 #define HANDLE_ERROR                                                          \
      { if (error_mechanism == IMMED_FAIL) {                                   \
         clean_up(); YYABORT;                                                 \
        }                                                                      \
        else if (error_mechanism == DEFER_FAIL) {                              \
+         gedcom_debug_print("Fail on line %d", line_no);                      \
          yyerrok; fail = 1;                                                   \
        }                                                                      \
        else if (error_mechanism == IGNORE_ERRORS) {                           \
@@ -210,7 +215,9 @@ void clean_up();
                      #TAG, parenttag);                                       \
          HANDLE_ERROR;                                                        \
        }                                                                      \
-     } 
+     }
+#define CHK_COND(TAG)                                                         \
+     check_occurrence(TAG_##TAG)
 #define POP                                                                   \
      { pop_countarray();                                                      \
        --count_level;                                                         \
@@ -255,7 +262,7 @@ void clean_up();
 }
 
 %token_table
-%expect 308
+%expect 317
 
 %token <string> BADTOKEN
 %token <number> OPEN
@@ -415,9 +422,13 @@ void clean_up();
 %%
 
 file        : head_sect records trlr_sect
-               { if (fail == 1) YYABORT; }
+               { compat_close();
+                if (fail == 1) YYABORT;
+              }
             | error
-               { clean_up(); }
+               { compat_close();
+                clean_up();
+              }
             ;
 
 records     : /* empty */
@@ -444,22 +455,24 @@ head_sect    : OPEN DELIM TAG_HEAD
                                         NULL, GEDCOM_MAKE_NULL(val2));
                 START(HEAD, $1, $<ctxt>$) }
                head_subs
-               { if (compat_mode(C_FTREE)) {
-                  CHECK3(SOUR, GEDC, CHAR);
-                  compat_generate_submitter_link($<ctxt>4);
-                }
-                else if (compat_mode(C_LIFELINES)) {
-                  CHECK1(SOUR);
+               { if (compat_mode(C_NO_SUBMITTER) && ! CHK_COND(SUBM))
                   compat_generate_submitter_link($<ctxt>4);
+                else CHK(SUBM);
+
+                if (compat_mode(C_NO_GEDC) && ! CHK_COND(GEDC))
                   compat_generate_gedcom($<ctxt>4);
+                else CHK(GEDC);
+
+                if (compat_mode(C_NO_CHAR) && ! CHK_COND(CHAR)) {
                   if (compat_generate_char($<ctxt>4)) HANDLE_ERROR;
-                }
-                else
-                  CHECK4(SOUR, SUBM, GEDC, CHAR)
+                }
+                else CHK(CHAR);
+
+                CHECK1(SOUR);
               }
                CLOSE
                { end_record(REC_HEAD, $<ctxt>4, GEDCOM_MAKE_NULL(val1));
-                if (compat_mode(C_FTREE | C_LIFELINES))
+                if (compat_mode(C_NO_SUBMITTER))
                   compat_generate_submitter();
               }
              ;
@@ -471,7 +484,7 @@ head_subs    : /* empty */
 head_sub     : head_sour_sect  { OCCUR2(SOUR, 1, 1) }
              | head_dest_sect  { OCCUR2(DEST, 0, 1) }
              | head_date_sect  { OCCUR2(DATE, 0, 1) }
-             | head_time_sect  { if (!compat_mode(C_LIFELINES))
+             | head_time_sect  { if (!compat_mode(C_HEAD_TIME))
                                  INVALID_TAG("TIME");
                                 OCCUR2(TIME, 0, 1) }
              | head_subm_sect  { OCCUR2(SUBM, 1, 1) }
@@ -488,7 +501,7 @@ head_sub     : head_sour_sect  { OCCUR2(SOUR, 1, 1) }
 
 /* HEAD.SOUR */
 head_sour_sect : OPEN DELIM TAG_SOUR mand_line_item 
-                 { set_compatibility($4);
+                 { set_compatibility_program($4);
                   $<ctxt>$ = start_element(ELT_HEAD_SOUR, PARENT,
                                            $1, $3, $4,
                                            GEDCOM_MAKE_STRING(val1, $4));
@@ -497,7 +510,8 @@ head_sour_sect : OPEN DELIM TAG_SOUR mand_line_item
                  head_sour_subs
                  { CHECK0 }
                 CLOSE
-                 { end_element(ELT_HEAD_SOUR, PARENT, $<ctxt>5,
+                 { compute_compatibility();
+                  end_element(ELT_HEAD_SOUR, PARENT, $<ctxt>5,
                               GEDCOM_MAKE_NULL(val1)); }
                ;
 
@@ -513,7 +527,8 @@ head_sour_sub : head_sour_vers_sect  { OCCUR2(VERS, 0, 1) }
               ;
 
 head_sour_vers_sect : OPEN DELIM TAG_VERS mand_line_item
-                      { $<ctxt>$ = start_element(ELT_HEAD_SOUR_VERS, PARENT,
+                      { set_compatibility_version($4);
+                       $<ctxt>$ = start_element(ELT_HEAD_SOUR_VERS, PARENT,
                                                 $1, $3, $4,
                                                 GEDCOM_MAKE_STRING(val1, $4));
                        START(VERS, $1, $<ctxt>$)
@@ -636,6 +651,8 @@ head_date_sect : OPEN DELIM TAG_DATE mand_line_item
                   $<ctxt>$ = start_element(ELT_HEAD_DATE,
                                            PARENT, $1, $3, $4,
                                            GEDCOM_MAKE_DATE(val1, dv));
+                  if (compat_mode(C_HEAD_TIME))
+                    compat_save_head_date_context($<ctxt>$);
                   START(DATE, $1, $<ctxt>$)
                 }
                  head_date_subs
@@ -668,10 +685,16 @@ head_date_time_sect : OPEN DELIM TAG_TIME mand_line_item
                      }
                     ;
 
-/* HEAD.TIME (Only for 'Lifelines' compatibility) */
-/* Just ignore the time... */
-head_time_sect : OPEN DELIM TAG_TIME opt_line_item CLOSE
-                 { gedcom_warning(_("Header change time lost in the compatibility"));
+/* HEAD.TIME (Only for compatibility) */
+head_time_sect : OPEN DELIM TAG_TIME opt_line_item
+                 { if (compat_mode(C_HEAD_TIME)) {
+                    $<ctxt>$ = compat_generate_head_time_start($1, $3, $4);
+                   }
+                 }
+                 CLOSE
+                 { if (compat_mode (C_HEAD_TIME)) {
+                    compat_generate_head_time_end($<ctxt>5);
+                  }
                  }
               ;
 
@@ -745,7 +768,13 @@ head_gedc_sect : OPEN DELIM TAG_GEDC
                   START(GEDC, $1, $<ctxt>$)
                 }
                  head_gedc_subs
-                { CHECK2(VERS, FORM) }
+                { if (compat_mode(C_NO_GEDC_FORM) && ! CHK_COND(FORM))
+                    compat_generate_gedcom_form($<ctxt>4);
+                  else CHK(FORM);
+                
+                  CHECK1(VERS)  
+                }
+
                  CLOSE
                  { end_element(ELT_HEAD_GEDC, PARENT, $<ctxt>4,
                               GEDCOM_MAKE_NULL(val1));
@@ -1047,7 +1076,10 @@ indiv_rec   : OPEN DELIM POINTER DELIM TAG_INDI
               indi_subs
              { CHECK0 }
               CLOSE
-              { end_record(REC_INDI, $<ctxt>6, GEDCOM_MAKE_NULL(val1)); }
+              { end_record(REC_INDI, $<ctxt>6, GEDCOM_MAKE_NULL(val1));
+               if (compat_mode(C_NO_SLGC_FAMC))
+                 compat_generate_slgc_famc_fam();
+             }
             ;
 
 indi_subs   : /* empty */
@@ -1074,7 +1106,7 @@ indi_sub    : indi_resn_sect  { OCCUR2(RESN, 0, 1) }
             | indi_afn_sect  /* 0:M */
             | ident_struc_sub  /* 0:1 */
             | change_date_sub  /* 0:1 */
-           | ftree_addr_sect { if (!compat_mode(C_FTREE))
+           | indi_addr_sect { if (!compat_mode(C_INDI_ADDR))
                                  INVALID_TAG("ADDR");
                              }
            | no_std_sub
@@ -1212,26 +1244,29 @@ 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
-                  { if (compat_mode(C_FTREE)) {
+/* INDI.ADDR (Only for compatibility) */
+indi_addr_sect : OPEN DELIM TAG_ADDR opt_line_item
+                  { if (compat_mode(C_INDI_ADDR)) {
                      Gedcom_ctxt par = compat_generate_resi_start(PARENT);
                      START(RESI, $1, par);
                      $<ctxt>$
                        = start_element(ELT_SUB_ADDR,
                                        par, $1 + 1, $3, $4,
                                        GEDCOM_MAKE_NULL_OR_STRING(val2, $4));
-                     START(ADDR, $1, $<ctxt>$);
+                     reset_buffer(&concat_buffer);
+                     safe_buf_append(&concat_buffer, $4);
+                     START(ADDR, $1 + 1, $<ctxt>$);
                    }
                  else { START(ADDR, $1, NULL) }
                  }
                   ftree_addr_subs
                   { CHECK0 }
                   CLOSE
-                  { if (compat_mode(C_FTREE)) {
+                  { if (compat_mode(C_INDI_ADDR)) {
                      Gedcom_ctxt par = PARENT;
+                     char* complete = get_buf_string(&concat_buffer);
                      end_element(ELT_SUB_ADDR, par, $<ctxt>5,
-                                 GEDCOM_MAKE_NULL(val1));
+                                 GEDCOM_MAKE_STRING(val1, complete));
                      CHECK0;
                      compat_generate_resi_end(PARENT, par);
                    } 
@@ -1403,11 +1438,11 @@ note_rec    : OPEN DELIM POINTER DELIM TAG_NOTE note_line_item
             ;
 
 note_line_item : /* empty */
-                   { if (!compat_mode(C_FTREE)) {
+                   { if (!compat_mode(C_NOTE_NO_VALUE)) {
                       gedcom_error(_("Missing value")); YYERROR;
                     }
                     else {
-                      $$ = "";
+                      $$ = VALUE_IF_MISSING;
                     }
                   }
                | DELIM line_item
@@ -1423,9 +1458,32 @@ note_sub    : continuation_sub  /* 0:M */
             | source_cit_sub  /* 0:M */
             | ident_struc_sub  /* 0:1 */
             | change_date_sub  /* 0:1 */
+            | note_note_sect  { if (!compat_mode(C_NOTE_NOTE))
+                                 INVALID_TAG("NOTE");
+                              }
             | no_std_sub
             ;
 
+/* Same actions as cont_sect, for compatibility */
+note_note_sect : OPEN DELIM TAG_NOTE opt_line_item
+            { $3.string = "CONT";
+             $3.value  = TAG_CONT;
+             $<ctxt>$ = start_element(ELT_SUB_CONT,
+                                      PARENT, $1, $3, $4, 
+                                      GEDCOM_MAKE_NULL_OR_STRING(val1, $4));
+             SAFE_BUF_ADDCHAR(&concat_buffer, '\n');
+             if (GEDCOM_IS_STRING(&val1))
+               safe_buf_append(&concat_buffer, $4);
+             START(CONT, $1, $<ctxt>$)  
+            }  
+            no_std_subs  
+            { CHECK0 }  
+            CLOSE  
+            { end_element(ELT_SUB_CONT, PARENT, $<ctxt>5,
+                         GEDCOM_MAKE_NULL(val1));
+           }
+            ;
+
 /*********************************************************************/
 /**** Repository record                                           ****/
 /*********************************************************************/
@@ -1497,6 +1555,24 @@ sour_sub    : sour_data_sect  { OCCUR2(DATA, 0, 1) }
             | sour_abbr_sect  { OCCUR2(ABBR, 0, 1) }
             | sour_publ_sect  { OCCUR2(PUBL, 0, 1) }
             | sour_text_sect  { OCCUR2(TEXT, 0, 1) }
+            | sour_type_sect  { if (!compat_mode(C_NONSTD_SOUR_TAGS))
+                                 INVALID_TAG("TYPE");
+                               OCCUR2(TYPE, 0, 1) }
+            | sour_file_sect  { if (!compat_mode(C_NONSTD_SOUR_TAGS))
+                                 INVALID_TAG("FILE");
+                               OCCUR2(FILE, 0, 1) }
+            | sour_plac_sect  { if (!compat_mode(C_NONSTD_SOUR_TAGS))
+                                 INVALID_TAG("PLAC");
+                               OCCUR2(PLAC, 0, 1) }
+            | sour_date_sect  { if (!compat_mode(C_NONSTD_SOUR_TAGS))
+                                 INVALID_TAG("DATE");
+                               OCCUR2(DATE, 0, 1) }
+            | sour_medi_sect  { if (!compat_mode(C_NONSTD_SOUR_TAGS))
+                                 INVALID_TAG("MEDI");
+                               OCCUR2(MEDI, 0, 1) }
+            | sour_page_sect  { if (!compat_mode(C_NONSTD_SOUR_TAGS))
+                                 INVALID_TAG("PAGE");
+                               OCCUR2(PAGE, 0, 1) }
             | source_repos_cit_sub  /* 0:1 */
             | multim_link_sub  /* 0:M */
             | note_struc_sub  /* 0:M */
@@ -1717,6 +1793,90 @@ sour_text_sub  : continuation_sub  /* 0:M */
                | no_std_sub
                ;
 
+/* Only for compatibility */
+sour_type_sect : OPEN DELIM TAG_TYPE opt_line_item  
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS)) {
+                    $<ctxt>$ =
+                      compat_generate_nonstd_sour_start(PARENT, $1, $3, $4,
+                                                        &usertag_buffer);
+                  }
+                 }
+                 CLOSE            
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS))
+                    compat_generate_nonstd_sour_end(PARENT, $<ctxt>5);
+                }
+               ;
+
+/* Only for compatibility */
+sour_file_sect : OPEN DELIM TAG_FILE opt_line_item  
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS)) {
+                    $<ctxt>$ =
+                      compat_generate_nonstd_sour_start(PARENT, $1, $3, $4,
+                                                        &usertag_buffer);
+                  }
+                 }
+                 CLOSE            
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS))
+                    compat_generate_nonstd_sour_end(PARENT, $<ctxt>5);
+                }
+               ;
+
+/* Only for compatibility */
+sour_plac_sect : OPEN DELIM TAG_PLAC opt_line_item  
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS)) {
+                    $<ctxt>$ =
+                      compat_generate_nonstd_sour_start(PARENT, $1, $3, $4,
+                                                        &usertag_buffer);
+                  }
+                 }
+                 CLOSE            
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS))
+                    compat_generate_nonstd_sour_end(PARENT, $<ctxt>5);
+                }
+               ;
+
+/* Only for compatibility */
+sour_date_sect : OPEN DELIM TAG_DATE opt_line_item  
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS)) {
+                    $<ctxt>$ =
+                      compat_generate_nonstd_sour_start(PARENT, $1, $3, $4,
+                                                        &usertag_buffer);
+                  }
+                 }
+                 CLOSE            
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS))
+                    compat_generate_nonstd_sour_end(PARENT, $<ctxt>5);
+                }
+               ;
+
+/* Only for compatibility */
+sour_medi_sect : OPEN DELIM TAG_MEDI opt_line_item  
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS)) {
+                    $<ctxt>$ =
+                      compat_generate_nonstd_sour_start(PARENT, $1, $3, $4,
+                                                        &usertag_buffer);
+                  }
+                 }
+                 CLOSE            
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS))
+                    compat_generate_nonstd_sour_end(PARENT, $<ctxt>5);
+                }
+               ;
+
+/* Only for compatibility */
+sour_page_sect : OPEN DELIM TAG_PAGE opt_line_item  
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS)) {
+                    $<ctxt>$ =
+                      compat_generate_nonstd_sour_start(PARENT, $1, $3, $4,
+                                                        &usertag_buffer);
+                  }
+                 }
+                 CLOSE            
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS))
+                    compat_generate_nonstd_sour_end(PARENT, $<ctxt>5);
+                }
+               ;
+
 /*********************************************************************/
 /**** Submission record                                           ****/
 /*********************************************************************/
@@ -1866,11 +2026,14 @@ submit_rec : OPEN DELIM POINTER DELIM TAG_SUBM
               $<ctxt>$ = start_record(REC_SUBM,
                                       $1, GEDCOM_MAKE_XREF_PTR(val1, xr), $5,
                                       NULL, GEDCOM_MAKE_NULL(val2));
-               START(SUBM, $1, $<ctxt>$) }
+              START(SUBM, $1, $<ctxt>$) }
              subm_subs
             { CHECK1(NAME) }
              CLOSE
-             { end_record(REC_SUBM, $<ctxt>6, GEDCOM_MAKE_NULL(val1)); }
+             { end_record(REC_SUBM, $<ctxt>6, GEDCOM_MAKE_NULL(val1));
+              if (compat_mode(C_SUBM_CTRY))
+                compat_free_ctry_parent_context();
+            }
            ;
 
 subm_subs  : /* empty */
@@ -1884,6 +2047,9 @@ subm_sub   : subm_name_sect  { OCCUR2(NAME, 1, 1) }
            | subm_rfn_sect  { OCCUR2(RFN, 0, 1) }
            | subm_rin_sect  { OCCUR2(RIN, 0, 1) }
            | change_date_sub  /* 0:1 */
+          | subm_ctry_sect  { if (!compat_mode(C_SUBM_CTRY))
+                                 INVALID_TAG("CTRY");
+                              OCCUR2(CTRY, 0, 1) }
            | no_std_sub
            ;
 
@@ -1947,6 +2113,19 @@ subm_rin_sect  : OPEN DELIM TAG_RIN mand_line_item
                 }
                ;
 
+/* SUBM.CTRY (Only for compatibility) */
+subm_ctry_sect : OPEN DELIM TAG_CTRY opt_line_item
+                 { if (compat_mode(C_SUBM_CTRY)) {
+                    $<ctxt>$ = compat_generate_addr_ctry_start($1, $3, $4);
+                   }
+                 }
+                 CLOSE
+                 { if (compat_mode (C_SUBM_CTRY)) {
+                    compat_generate_addr_ctry_end($<ctxt>5);
+                  }
+                 }
+              ;
+
 /*********************************************************************/
 /**** Substructures                                               ****/
 /*********************************************************************/
@@ -1962,7 +2141,9 @@ addr_sect   : OPEN DELIM TAG_ADDR mand_line_item
                                         GEDCOM_MAKE_STRING(val1, $4));
                reset_buffer(&concat_buffer);
                safe_buf_append(&concat_buffer, $4);
-               START(ADDR, $1, $<ctxt>$)  
+               START(ADDR, $1, $<ctxt>$);
+               if (compat_mode(C_SUBM_CTRY))
+                 compat_save_ctry_parent_context($<ctxt>$);
               }
               addr_subs
              { CHECK0 }
@@ -2265,15 +2446,16 @@ continuation_sub : cont_sect  /* 0:M */
                  | conc_sect  /* 0:M */
                  ;
 
-cont_sect : OPEN DELIM TAG_CONT mand_line_item 
+cont_sect : OPEN DELIM TAG_CONT opt_line_item 
             { $<ctxt>$ = start_element(ELT_SUB_CONT,
                                       PARENT, $1, $3, $4, 
-                                      GEDCOM_MAKE_STRING(val1, $4));
+                                      GEDCOM_MAKE_NULL_OR_STRING(val1, $4));
              SAFE_BUF_ADDCHAR(&concat_buffer, '\n');
-             safe_buf_append(&concat_buffer, $4);
+             if (GEDCOM_IS_STRING(&val1))
+               safe_buf_append(&concat_buffer, $4);
              START(CONT, $1, $<ctxt>$)  
             }  
-            no_std_subs  
+            cont_conc_subs  
             { CHECK0 }  
             CLOSE  
             { end_element(ELT_SUB_CONT, PARENT, $<ctxt>5,
@@ -2285,10 +2467,13 @@ conc_sect : OPEN DELIM TAG_CONC mand_line_item
             { $<ctxt>$ = start_element(ELT_SUB_CONC,
                                       PARENT, $1, $3, $4, 
                                       GEDCOM_MAKE_STRING(val1, $4));
+             if (compat_mode(C_CONC_NEEDS_SPACE)) {
+               safe_buf_append(&concat_buffer, " ");
+             }
              safe_buf_append(&concat_buffer, $4);
              START(CONC, $1, $<ctxt>$)  
             }  
-            no_std_subs  
+            cont_conc_subs  
             { CHECK0 }  
             CLOSE  
             { end_element(ELT_SUB_CONC, PARENT, $<ctxt>5,
@@ -2296,6 +2481,33 @@ conc_sect : OPEN DELIM TAG_CONC mand_line_item
            }
           ; 
 
+cont_conc_subs : /* empty */
+               | cont_conc_subs cont_conc_sub
+               ;
+
+cont_conc_sub  : cont_conc_sour_sect { if (!compat_mode(C_NOTE_CONC_SOUR))
+                                        INVALID_TAG("SOUR");
+                                      OCCUR2(SOUR, 0, 1) } 
+               | no_std_sub
+              ;
+
+/* Only for compatibility */
+cont_conc_sour_sect : OPEN DELIM TAG_SOUR DELIM POINTER
+                      { if (compat_mode(C_NOTE_CONC_SOUR)) {
+                         $<ctxt>$
+                           = compat_generate_note_sour_start(GRANDPARENT(1),
+                                                             $1, $3, $5);
+                         if ($<ctxt>$ == (void*)-1) HANDLE_ERROR;
+                        }
+                      }
+                      no_std_subs
+                      CLOSE
+                      { if (compat_mode(C_NOTE_CONC_SOUR)) {
+                         compat_generate_note_sour_end($<ctxt>6);
+                       }
+                      }
+                     ;
+
 /* EVENT DETAIL */
 event_detail_sub : event_detail_type_sect  { OCCUR2(TYPE, 0, 1) }
                  | event_detail_date_sect  { OCCUR2(DATE, 0, 1) }
@@ -2883,7 +3095,11 @@ lio_slgc_sect : OPEN DELIM TAG_SLGC
                  START(SLGC, $1, $<ctxt>$) 
                 }
                 lio_slgc_subs
-               { CHECK1(FAMC) }
+                { if (compat_mode(C_NO_SLGC_FAMC) && ! CHK_COND(FAMC))
+                   compat_generate_slgc_famc_link($<ctxt>4);
+                 else CHK(FAMC);
+                 CHECK0;
+               }
                 CLOSE 
                 { end_element(ELT_SUB_LIO_SLGC, PARENT, $<ctxt>4, 
                              GEDCOM_MAKE_NULL(val1));
@@ -3128,14 +3344,19 @@ note_struc_link_sub : source_cit_sub
                     ;
 
 note_struc_emb_sect : OPEN DELIM TAG_NOTE opt_line_item
-                      { $<ctxt>$
+                      { char* str = $4;
+                       if (compat_mode(C_NOTE_TOO_LONG))
+                         str = compat_long_line_get_prefix($4);
+                       $<ctxt>$
                          = start_element(ELT_SUB_NOTE,
-                                         PARENT, $1, $3, $4,
-                                        GEDCOM_MAKE_NULL_OR_STRING(val1, $4));
+                                         PARENT, $1, $3, str,
+                                       GEDCOM_MAKE_NULL_OR_STRING(val1, str));
                        reset_buffer(&concat_buffer);
                        if ($4)
                          safe_buf_append(&concat_buffer, $4);
-                       START(NOTE, $1, $<ctxt>$) 
+                       START(NOTE, $1, $<ctxt>$);
+                       if (compat_mode(C_NOTE_TOO_LONG))
+                         compat_long_line_finish($<ctxt>$, $1);
                       }
                       note_struc_emb_subs
                      { CHECK0 }
@@ -3512,22 +3733,41 @@ source_cit_emb_sub : continuation_sub
 
 /* SOURCE REPOSITORY CITATION */
 source_repos_cit_sub : source_repos_repo_sect  { OCCUR2(REPO, 0, 1) }
+                     | source_repos_repo_txt_sect
+                       { if (!compat_mode(C_NONSTD_SOUR_TAGS))
+                          INVALID_TAG("REPO");
+                        OCCUR2(REPO, 0, 1)
+                      }
                      ;
 
-source_repos_repo_sect : OPEN DELIM TAG_REPO mand_pointer
+/* Only for compatibility */
+source_repos_repo_txt_sect : OPEN DELIM TAG_REPO opt_line_item
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS)) {
+                    $<ctxt>$ =
+                      compat_generate_nonstd_sour_start(PARENT, $1, $3, $4,
+                                                        &usertag_buffer);
+                  }
+                 }
+                 CLOSE            
+                 { if (compat_mode(C_NONSTD_SOUR_TAGS))
+                    compat_generate_nonstd_sour_end(PARENT, $<ctxt>5);
+                }
+               ;
+
+source_repos_repo_sect : OPEN DELIM TAG_REPO DELIM POINTER
                          { struct xref_value *xr
-                            = gedcom_parse_xref($4, XREF_USED, XREF_REPO);
-                          if (xr == NULL) HANDLE_ERROR;
+                            = gedcom_parse_xref($5, XREF_USED, XREF_REPO);
+                          if (xr == NULL) HANDLE_ERROR;
                           $<ctxt>$
                             = start_element(ELT_SUB_REPO,
-                                            PARENT, $1, $3, $4,
+                                            PARENT, $1, $3, $5,
                                             GEDCOM_MAKE_XREF_PTR(val1, xr));
-                          START(REPO, $1, $<ctxt>$) 
-                         }
+                          START(REPO, $1, $<ctxt>$);
+                        }
                          source_repos_repo_subs
                         { CHECK0 }
                          CLOSE 
-                         { end_element(ELT_SUB_REPO, PARENT, $<ctxt>5
+                         { end_element(ELT_SUB_REPO, PARENT, $<ctxt>6
                                       GEDCOM_MAKE_NULL(val1));
                         }
                        ;
@@ -3629,9 +3869,18 @@ no_std_rec  : user_rec /* 0:M */
 
 user_rec    : OPEN DELIM opt_xref USERTAG
               { if ($4.string[0] != '_') {
-                 gedcom_error(_("Undefined tag (and not a valid user tag): %s"),
-                              $4);
-                 YYERROR;
+                 if ((compat_mode(C_551_TAGS)
+                      && compat_check_551_tag($4.string, &usertag_buffer))
+                     ||
+                     (compat_mode(C_NONSTD_SOUR_TAGS)
+                      && compat_check_sour_tag($4.string, &usertag_buffer))) {
+                   $4.string = get_buf_string(&usertag_buffer);
+                 }
+                 else {                  
+                   gedcom_error(_("Undefined tag (and not a valid user tag): %s"),
+                                $4);
+                   YYERROR;
+                 }
                }
              }
               opt_value
@@ -3653,9 +3902,22 @@ user_rec    : OPEN DELIM opt_xref USERTAG
             ;
 user_sect   : OPEN DELIM opt_xref USERTAG
               { if ($4.string[0] != '_') {
-                 gedcom_error(_("Undefined tag (and not a valid user tag): %s"),
-                              $4);
-                 YYERROR;
+                 if ((compat_mode(C_551_TAGS)
+                      && compat_check_551_tag($4.string, &usertag_buffer))
+                     ||
+                     (compat_mode(C_SUBM_COMM)
+                      && compat_check_subm_comm($4.string, get_parenttag(0),
+                                                &usertag_buffer))
+                     ||
+                     (compat_mode(C_NONSTD_SOUR_TAGS)
+                      && compat_check_sour_tag($4.string, &usertag_buffer))) {
+                   $4.string = get_buf_string(&usertag_buffer);
+                 }
+                 else {
+                   gedcom_error(_("Undefined tag (and not a valid user tag): %s"),
+                                $4);
+                   YYERROR;
+                 }
                }
              }
               opt_value
@@ -3667,11 +3929,21 @@ user_sect   : OPEN DELIM opt_xref USERTAG
              CLOSE
               { end_element(ELT_USER, PARENT, $<ctxt>7, 
                            GEDCOM_MAKE_NULL(val1));
+               if (compat_mode(C_SUBM_COMM))
+                 compat_close_subm_comm();
              }
             ;
 
 user_sects   : /* empty */     { }
             | user_sects user_sect { }
+            | user_sects gen_sect
+              { if (compat_mode(C_SUBM_COMM)) {
+                }
+               else {
+                 gedcom_error(_("Standard tag not allowed in user section"));
+                 YYERROR;
+               }
+             }
             ;
 
 opt_xref    : /* empty */        { $$ = NULL; }
@@ -3695,10 +3967,9 @@ mand_pointer : /* empty */ { gedcom_error(_("Missing pointer")); YYERROR; }
              ;
 
 mand_line_item : /* empty */
-                 { if (compat_mode(C_LIFELINES)) {
-                     /* Lifelines tends to not care about mandatory values */
-                    gedcom_debug_print("==Val: ==");
-                    $$ = "";
+                 { if (compat_mode(C_NO_REQUIRED_VALUES)) {
+                     gedcom_debug_print("==Val: ==");
+                    $$ = VALUE_IF_MISSING;
                   }
                   else {
                     gedcom_error(_("Missing value")); YYERROR;
@@ -3761,9 +4032,23 @@ error_sect  : OPEN DELIM opt_xref anytag opt_value error_subs CLOSE { }
             ;
 
 gen_sect    : OPEN DELIM opt_xref anystdtag
-              { INVALID_TAG($4.string); }
-              opt_value opt_sects CLOSE
-              { }
+              { if (compat_mode(C_SUBM_COMM)
+                   && compat_check_subm_comm_cont($4.string)) {
+                 /* Will pass here */
+               }
+               else {
+                 INVALID_TAG($4.string);
+               }
+             }
+              opt_value
+              { if (compat_mode(C_SUBM_COMM)) {
+                 $<ctxt>$ = compat_subm_comm_cont_start(PARENT, $6);
+                }
+             }
+             opt_sects CLOSE
+              { if (compat_mode(C_SUBM_COMM))
+                 compat_subm_comm_cont_end(PARENT, $<ctxt>7);
+             }
             ;
 
 gen_rec : gen_rec_top
@@ -3940,7 +4225,7 @@ Gedcom_ctxt ctxt_stack[MAXGEDCLEVEL+1];
 void push_countarray(int level)
 {
   int *count = NULL;
-  gedcom_debug_print("Push Count level: %d, level: %d\n", count_level, level);
+  gedcom_debug_print("Push Count level: %d, level: %d", count_level, level);
   if (count_level != level + 1) {
     gedcom_error(_("Internal error: count level mismatch"));
     exit(1);
@@ -3950,7 +4235,7 @@ void push_countarray(int level)
     exit(1);
   }
   else {
-    gedcom_debug_print("calloc countarray %d\n", count_level);
+    gedcom_debug_print("calloc countarray %d", count_level);
     count = (int *)calloc(YYNTOKENS, sizeof(int));
     if (count == NULL) {
       gedcom_error(_("Internal error: count array calloc error"));
@@ -3997,14 +4282,14 @@ int check_occurrence(int tag)
 void pop_countarray()
 {
   int *count;
-  gedcom_debug_print("Pop Count level: %d\n", count_level);
+  gedcom_debug_print("Pop Count level: %d", count_level);
   if (count_level < 0) {
     gedcom_error(_("Internal error: count array underflow"));
     exit(1);
   }
   else {
     count = count_arrays[count_level];
-    gedcom_debug_print("free countarray %d\n", count_level);
+    gedcom_debug_print("free countarray %d", count_level);
     free(count);
     count_arrays[count_level] = NULL;
   }
@@ -4012,7 +4297,7 @@ void pop_countarray()
 
 void clean_up()
 {
-  gedcom_debug_print("Cleanup countarrays\n");
+  gedcom_debug_print("Cleanup countarrays");
   while (count_level > 0) {
     pop_countarray();
     --count_level;
@@ -4029,6 +4314,11 @@ void cleanup_line_item_buffer()
   cleanup_buffer(&line_item_buffer);
 }
 
+void cleanup_usertag_buffer()
+{
+  cleanup_buffer(&usertag_buffer);
+}
+
 /* Enabling debug mode */
 /* level 0: no debugging */
 /* level 1: only internal */
@@ -4063,9 +4353,3 @@ int gedcom_debug_print(const char* s, ...)
   }
   return(res);
 }
-
-/* Setting the error mechanism */
-void gedcom_set_error_handling(Gedcom_err_mech mechanism)
-{
-  error_mechanism = mechanism;
-}