Exemple #1
0
        internal bool IsAllItemsOverThisLevel(Pullenti.Ner.Decree.Internal.PartToken.ItemType typ)
        {
            int l0 = this._getLevel(Pullenti.Ner.Decree.Internal.PartToken._getAttrNameByTyp(typ));

            if (l0 <= 0)
            {
                return(false);
            }
            foreach (Pullenti.Ner.Slot s in Slots)
            {
                int l = this._getLevel(s.TypeName);
                if (l <= 0)
                {
                    continue;
                }
                if (l >= l0)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        static int _analizeListItems(List <FragToken> chi, int ind)
        {
            if (ind >= chi.Count)
            {
                return(-1);
            }
            FragToken res = chi[ind];

            Pullenti.Ner.Instrument.InstrumentKind ki = res.Kind;
            if (((ki == Pullenti.Ner.Instrument.InstrumentKind.Chapter || ki == Pullenti.Ner.Instrument.InstrumentKind.Clause || ki == Pullenti.Ner.Instrument.InstrumentKind.Content) || ki == Pullenti.Ner.Instrument.InstrumentKind.Item || ki == Pullenti.Ner.Instrument.InstrumentKind.Subitem) || ki == Pullenti.Ner.Instrument.InstrumentKind.ClausePart || ki == Pullenti.Ner.Instrument.InstrumentKind.Indention)
            {
            }
            else
            {
                return(-1);
            }
            if (res.HasChanges && res.MultilineChangesValue != null)
            {
                Pullenti.Ner.MetaToken ci = res.MultilineChangesValue;
                FragToken cit             = new FragToken(ci.BeginToken, ci.EndToken)
                {
                    Kind = Pullenti.Ner.Instrument.InstrumentKind.Citation
                };
                res.Children.Add(cit);
                if (Pullenti.Ner.Core.BracketHelper.IsBracket(cit.BeginToken.Previous, true))
                {
                    cit.BeginToken = cit.BeginToken.Previous;
                }
                if (Pullenti.Ner.Core.BracketHelper.IsBracket(cit.EndToken.Next, true))
                {
                    cit.EndToken = cit.EndToken.Next;
                    if (cit.EndToken.Next != null && cit.EndToken.Next.IsCharOf(";."))
                    {
                        cit.EndToken = cit.EndToken.Next;
                    }
                }
                res.FillByContentChildren();
                if (res.Children[0].HasChanges)
                {
                }
                Pullenti.Ner.Instrument.InstrumentKind citKind = Pullenti.Ner.Instrument.InstrumentKind.Undefined;
                if (ci.Tag is Pullenti.Ner.Decree.DecreeChangeReferent)
                {
                    Pullenti.Ner.Decree.DecreeChangeReferent dcr = ci.Tag as Pullenti.Ner.Decree.DecreeChangeReferent;
                    if (dcr.Value != null && dcr.Value.NewItems.Count > 0)
                    {
                        string mnem = dcr.Value.NewItems[0];
                        int    i;
                        if ((((i = mnem.IndexOf(' ')))) > 0)
                        {
                            mnem = mnem.Substring(0, i);
                        }
                        citKind = Pullenti.Ner.Decree.Internal.PartToken._getInstrKindByTyp(Pullenti.Ner.Decree.Internal.PartToken._getTypeByAttrName(mnem));
                    }
                    else if (dcr.Owners.Count > 0 && (dcr.Owners[0] is Pullenti.Ner.Decree.DecreePartReferent) && dcr.Kind == Pullenti.Ner.Decree.DecreeChangeKind.New)
                    {
                        Pullenti.Ner.Decree.DecreePartReferent pat = dcr.Owners[0] as Pullenti.Ner.Decree.DecreePartReferent;
                        int min = 0;
                        foreach (Pullenti.Ner.Slot s in pat.Slots)
                        {
                            Pullenti.Ner.Decree.Internal.PartToken.ItemType ty = Pullenti.Ner.Decree.Internal.PartToken._getTypeByAttrName(s.TypeName);
                            if (ty == Pullenti.Ner.Decree.Internal.PartToken.ItemType.Undefined)
                            {
                                continue;
                            }
                            int l = Pullenti.Ner.Decree.Internal.PartToken._getRank(ty);
                            if (l == 0)
                            {
                                continue;
                            }
                            if (l > min || min == 0)
                            {
                                min     = l;
                                citKind = Pullenti.Ner.Decree.Internal.PartToken._getInstrKindByTyp(ty);
                            }
                        }
                    }
                }
                FragToken sub = null;
                if (citKind != Pullenti.Ner.Instrument.InstrumentKind.Undefined && citKind != Pullenti.Ner.Instrument.InstrumentKind.Appendix)
                {
                    sub = new FragToken(ci.BeginToken, ci.EndToken);
                    ContentAnalyzeWhapper wr = new ContentAnalyzeWhapper();
                    wr.Analyze(sub, null, true, citKind);
                    sub.Kind = Pullenti.Ner.Instrument.InstrumentKind.Content;
                }
                else
                {
                    sub = FragToken.CreateDocument(ci.BeginToken, ci.EndChar, citKind);
                }
                if (sub == null || sub.Children.Count == 0)
                {
                }
                else if ((sub.Kind == Pullenti.Ner.Instrument.InstrumentKind.Content && sub.Children.Count > 0 && sub.Children[0].BeginToken == sub.BeginToken) && sub.Children[sub.Children.Count - 1].EndToken == sub.EndToken)
                {
                    cit.Children.AddRange(sub.Children);
                }
                else
                {
                    cit.Children.Add(sub);
                }
                return(1);
            }
            int endChar = res.EndChar;

            if (res.Itok == null)
            {
                res.Itok = InstrToken1.Parse(res.BeginToken, true, null, 0, null, false, res.EndChar, false, false);
            }
            List <LineToken> lines = LineToken.ParseList(res.BeginToken, endChar, null);

            if (lines == null || (lines.Count < 1))
            {
                return(-1);
            }
            int ret = 1;

            if (res.Kind == Pullenti.Ner.Instrument.InstrumentKind.Content)
            {
                for (int j = ind + 1; j < chi.Count; j++)
                {
                    if (chi[j].Kind == Pullenti.Ner.Instrument.InstrumentKind.Content)
                    {
                        List <LineToken> lines2 = LineToken.ParseList(chi[j].BeginToken, chi[j].EndChar, lines[lines.Count - 1]);
                        if (lines2 == null || (lines2.Count < 1))
                        {
                            break;
                        }
                        if (!lines2[0].IsListItem)
                        {
                            if ((lines2.Count > 1 && lines2[1].IsListItem && lines2[0].EndToken.IsCharOf(":")) && !lines2[0].BeginToken.Chars.IsCapitalUpper)
                            {
                                lines2[0].IsListItem = true;
                            }
                            else
                            {
                                break;
                            }
                        }
                        lines.AddRange(lines2);
                        ret = (j - ind) + 1;
                    }
                    else if (chi[j].Kind != Pullenti.Ner.Instrument.InstrumentKind.Editions && chi[j].Kind != Pullenti.Ner.Instrument.InstrumentKind.Comment)
                    {
                        break;
                    }
                }
            }
            if (lines.Count < 2)
            {
                return(-1);
            }
            if ((lines.Count > 1 && lines[0].IsListItem && lines[1].IsListItem) && lines[0].Number != 1)
            {
                if (lines.Count == 2 || !lines[2].IsListItem)
                {
                    lines[0].IsListItem = (lines[1].IsListItem = false);
                }
            }
            for (int i = 0; i < lines.Count; i++)
            {
                if (lines[i].IsListItem)
                {
                    if (i > 0 && lines[i - 1].IsListItem)
                    {
                        continue;
                    }
                    if (((i + 1) < lines.Count) && lines[i + 1].IsListItem)
                    {
                    }
                    else
                    {
                        lines[i].IsListItem = false;
                        continue;
                    }
                    int  j;
                    bool newLine = false;
                    for (j = i + 1; j < lines.Count; j++)
                    {
                        if (!lines[j].IsListItem)
                        {
                            break;
                        }
                        else if (lines[j].IsNewlineBefore)
                        {
                            newLine = true;
                        }
                    }
                    if (newLine)
                    {
                        continue;
                    }
                    if (i > 0 && lines[i - 1].EndToken.IsChar(':'))
                    {
                        continue;
                    }
                    for (j = i; j < lines.Count; j++)
                    {
                        if (!lines[j].IsListItem)
                        {
                            break;
                        }
                        else
                        {
                            lines[j].IsListItem = false;
                        }
                    }
                }
            }
            if (lines.Count > 2)
            {
                LineToken last  = lines[lines.Count - 1];
                LineToken last2 = lines[lines.Count - 2];
                if ((!last.IsListItem && last.EndToken.IsChar('.') && last2.IsListItem) && last2.EndToken.IsChar(';'))
                {
                    if ((last.LengthChar < (last2.LengthChar * 2)) || last.BeginToken.Chars.IsAllLower)
                    {
                        last.IsListItem = true;
                    }
                }
            }
            for (int i = 0; i < (lines.Count - 1); i++)
            {
                if (!lines[i].IsListItem && !lines[i + 1].IsListItem)
                {
                    if (((i + 2) < lines.Count) && lines[i + 2].IsListItem && lines[i + 1].EndToken.IsChar(':'))
                    {
                    }
                    else
                    {
                        lines[i].EndToken = lines[i + 1].EndToken;
                        lines.RemoveAt(i + 1);
                        i--;
                    }
                }
            }
            for (int i = 0; i < (lines.Count - 1); i++)
            {
                if (lines[i].IsListItem)
                {
                    if (lines[i].Number == 1)
                    {
                        bool ok    = true;
                        int  num   = 1;
                        int  nonum = 0;
                        for (int j = i + 1; j < lines.Count; j++)
                        {
                            if (!lines[j].IsListItem)
                            {
                                ok = false;
                                break;
                            }
                            else if (lines[j].Number > 0)
                            {
                                num++;
                                if (lines[j].Number != num)
                                {
                                    ok = false;
                                    break;
                                }
                            }
                            else
                            {
                                nonum++;
                            }
                        }
                        if (!ok || nonum == 0 || (num < 2))
                        {
                            break;
                        }
                        LineToken lt = lines[i];
                        for (int j = i + 1; j < lines.Count; j++)
                        {
                            if (lines[j].Number > 0)
                            {
                                lt = lines[j];
                            }
                            else
                            {
                                List <LineToken> chli = lt.Tag as List <LineToken>;
                                if (chli == null)
                                {
                                    lt.Tag = (chli = new List <LineToken>());
                                }
                                lt.EndToken = lines[j].EndToken;
                                chli.Add(lines[j]);
                                lines.RemoveAt(j);
                                j--;
                            }
                        }
                    }
                }
            }
            int cou = 0;

            foreach (LineToken li in lines)
            {
                if (li.IsListItem)
                {
                    cou++;
                }
            }
            if (cou < 2)
            {
                return(-1);
            }
            for (int i = 0; i < lines.Count; i++)
            {
                if (lines[i].IsListItem)
                {
                    int  i0 = i;
                    bool ok = true;
                    cou = 1;
                    for (; i < lines.Count; i++, cou++)
                    {
                        if (!lines[i].IsListItem)
                        {
                            break;
                        }
                        else if (lines[i].Number != cou)
                        {
                            ok = false;
                        }
                    }
                    if (!ok)
                    {
                        for (i = i0; i < lines.Count; i++)
                        {
                            if (!lines[i].IsListItem)
                            {
                                break;
                            }
                            else
                            {
                                lines[i].Number = 0;
                            }
                        }
                    }
                    if (cou > 3 && lines[i0].BeginToken.GetSourceText() != lines[i0 + 1].BeginToken.GetSourceText() && lines[i0 + 1].BeginToken.GetSourceText() == lines[i0 + 2].BeginToken.GetSourceText())
                    {
                        string pref = lines[i0 + 1].BeginToken.GetSourceText();
                        ok = true;
                        for (int j = i0 + 2; j < i; j++)
                        {
                            if (pref != lines[j].BeginToken.GetSourceText())
                            {
                                ok = false;
                                break;
                            }
                        }
                        if (!ok)
                        {
                            continue;
                        }
                        Pullenti.Ner.Token tt = null;
                        ok = false;
                        for (tt = lines[i0].EndToken.Previous; tt != null && tt != lines[i0].BeginToken; tt = tt.Previous)
                        {
                            if (tt.GetSourceText() == pref)
                            {
                                ok = true;
                                break;
                            }
                        }
                        if (ok)
                        {
                            LineToken li0 = new LineToken(lines[i0].BeginToken, tt.Previous);
                            lines[i0].BeginToken = tt;
                            lines.Insert(i0, li0);
                            i++;
                        }
                    }
                }
            }
            foreach (LineToken li in lines)
            {
                li.CorrectBeginToken();
                FragToken ch = new FragToken(li.BeginToken, li.EndToken)
                {
                    Kind = (li.IsListItem ? Pullenti.Ner.Instrument.InstrumentKind.ListItem : Pullenti.Ner.Instrument.InstrumentKind.Content), Number = li.Number
                };
                if (ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Content && ch.EndToken.IsChar(':'))
                {
                    ch.Kind = Pullenti.Ner.Instrument.InstrumentKind.ListHead;
                }
                res.Children.Add(ch);
                List <LineToken> chli = li.Tag as List <LineToken>;
                if (chli != null)
                {
                    foreach (LineToken lt in chli)
                    {
                        ch.Children.Add(new FragToken(lt.BeginToken, lt.EndToken)
                        {
                            Kind = Pullenti.Ner.Instrument.InstrumentKind.ListItem
                        });
                    }
                    if (ch.BeginChar < ch.Children[0].BeginChar)
                    {
                        ch.Children.Insert(0, new FragToken(ch.BeginToken, ch.Children[0].BeginToken.Previous)
                        {
                            Kind = Pullenti.Ner.Instrument.InstrumentKind.Content
                        });
                    }
                }
            }
            return(ret);
        }