예제 #1
0
        // CHIL processing pulled out for _FREL/_MREL
        private void childProc(ParseContext2 context)
        {
            var fam = (context.Parent as FamRecord);

            LookAhead(context); // Any sub-lines (e.g. _FREL/_MREL)?

            string xref;
            string extra;

            StructParser.parseXrefExtra(context.Remain, out xref, out extra);
            if (string.IsNullOrEmpty(xref))
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissIdent; // TODO "Missing/unterminated identifier: " + context.Tag;
                err.Beg   = context.Begline + context.Parent.BegLine;
                err.End   = context.Endline + context.Parent.BegLine;
                err.Tag   = context.Tag;
                fam.Errors.Add(err);
                return;
            }
#if XREFTRACK
            int key = XrefTrack.Instance.StoreXref(xref);
#endif
            foreach (var child in fam.Childs)
            {
#if XREFTRACK
                if (child.Key == key)
#else
                if (child.Xref == xref)
#endif
                {
                    UnkRec err = new UnkRec();
                    err.Error = UnkRec.ErrorCode.MultCHIL; // TODO "CHIL ident used more than once (one person cannot be two children)";
                    err.Beg   = context.Begline + context.Parent.BegLine;
                    err.End   = context.Endline + context.Parent.BegLine;
                    fam.Errors.Add(err);
                    return;
                }
            }

            string mrel = null;
            string frel = null;
            if (context.Endline > context.Begline)
            {
                LineUtil.LineData ld = new LineUtil.LineData();
                //var gs = new GEDSplitter();
                //ParseContext2 ctx = new ParseContext2();
                int i = context.Begline + 1;
                while (i <= context.Endline)
                {
                    //LineUtil.LevelTagAndRemain(ld, context.Lines.GetLine(i));
                    context.gs.LevelTagAndRemain(context.Lines.GetLine(i), ld);
                    switch (ld.Tag)
                    {
                    case "_MREL":
                        if (!string.IsNullOrWhiteSpace(ld.Remain))     // FTA expects 'Natural' and I canna see why not && ld.Remain != "Natural")
                        {
                            mrel = ld.Remain;
                        }
                        break;

                    case "_FREL":
                        if (!string.IsNullOrWhiteSpace(ld.Remain))     // FTA expects 'Natural' and I canna see why not && ld.Remain != "Natural")
                        {
                            frel = ld.Remain;
                        }
                        break;

                    case "_PREF":
                    case "_STAT":
                        // TODO temporarily ignore: see 2524482.ged
                        break;

                    default:
                        UnkRec unk = new UnkRec(ld.Tag, i + context.Parent.BegLine, i + context.Parent.BegLine);
                        fam.Unknowns.Add(unk);
                        break;
                    }
                    i++;
                }
                //gs = null;
            }
            fam.AddChild(xref, frel, mrel);
        }
예제 #2
0
        protected static void StructParse(StructParseContext ctx, Dictionary <string, TagProc> tagSet)
        {
            LineUtil.LineData ld = new LineUtil.LineData();
            //GEDSplitter gs = new GEDSplitter();

            int i   = ctx.Begline + 1;
            int max = ctx.Lines.Max;

            for (; i < max; i++)
            {
                try
                {
                    ctx.gs.LevelTagAndRemain(ctx.Lines.GetLine(i), ld);
                    //LineUtil.LevelTagAndRemain(ld, ctx.Lines.GetLine(i));
                }
                catch (Exception)
                {
                    UnkRec exc = new UnkRec();
                    exc.Beg   = exc.End = i;
                    exc.Error = UnkRec.ErrorCode.Exception;
                    // TODO exc.Error = "Exception during parse, skipping line";
                    ctx.Record.Errors.Add(exc); // TODO is Record only for errors?
                    continue;
                }

                if (ld.Level <= ctx.Level)
                {
                    break; // end of sub-record
                }
                ctx.Remain1 = ld.Remain1;

                if (ld.Tag == null)
                {
                    UnkRec exc = new UnkRec();
                    exc.Beg   = exc.End = i;
                    exc.Error = UnkRec.ErrorCode.MissTag;
                    // TODO exc.Error = "Exception during parse, skipping line";
                    // TODO not exception - missing tag / invalid linebreak
                    ctx.Record.Errors.Add(exc); // TODO is Record only for errors?
                    continue;
                }

                TagProc tagproc;
                if (tagSet.TryGetValue(ld.Tag, out tagproc))
                {
                    ctx.Begline = i;
                    ctx.Tag     = ld.Tag;
                    tagproc(ctx, i, ld.Level);
                }
                else
                {
                    LineSet extra    = new LineSet();
                    char    oldLevel = ctx.Level;
                    ctx.Begline = i;
                    ctx.Level   = ld.Level;
                    GedRecParse.LookAhead(ctx);
                    extra.Beg = ctx.Begline + ctx.Lines.Beg; // Make line #s relative to file
                    extra.End = ctx.Endline + ctx.Lines.Beg;
                    ctx.Parent.OtherLines.Add(extra);
                    ctx.Level = oldLevel;
                }
                i = Math.Max(ctx.Endline, i); // HACK: extendedText() may have advanced ctx.Endline further
            }
            ctx.Endline = i - 1;
            ld          = null;
            //gs = null;
        }