/*
 * SDK Pullenti Lingvo, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software.
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C#.NET project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

const Utils = require("./../../../unisharp/Utils");
const Hashtable = require("./../../../unisharp/Hashtable");
const RefOutArgWrapper = require("./../../../unisharp/RefOutArgWrapper");
const StringBuilder = require("./../../../unisharp/StringBuilder");

const NounPhraseParseAttr = require("./../../core/NounPhraseParseAttr");
const NumberSpellingType = require("./../../NumberSpellingType");
const MorphNumber = require("./../../../morph/MorphNumber");
const MorphClass = require("./../../../morph/MorphClass");
const MetaToken = require("./../../MetaToken");
const InstrumentParticipantReferent = require("./../InstrumentParticipantReferent");
const TextToken = require("./../../TextToken");
const OrganizationReferent = require("./../../org/OrganizationReferent");
const BlkTyps = require("./../../core/internal/BlkTyps");
const NounPhraseHelper = require("./../../core/NounPhraseHelper");
const GeoReferent = require("./../../geo/GeoReferent");
const OrgItemTypeToken = require("./../../org/internal/OrgItemTypeToken");
const MoneyReferent = require("./../../money/MoneyReferent");
const BankDataReferent = require("./../../bank/BankDataReferent");
const PartTokenItemType = require("./../../decree/internal/PartTokenItemType");
const NumberHelper = require("./../../core/NumberHelper");
const DecreeChangeValueKind = require("./../../decree/DecreeChangeValueKind");
const InstrToken1Types = require("./InstrToken1Types");
const DecreeChangeValueReferent = require("./../../decree/DecreeChangeValueReferent");
const DecreeChangeKind = require("./../../decree/DecreeChangeKind");
const MorphologyService = require("./../../../morph/MorphologyService");
const NumberToken = require("./../../NumberToken");
const TerminParseAttr = require("./../../core/TerminParseAttr");
const Token = require("./../../Token");
const InstrumentArtefactReferent = require("./../InstrumentArtefactReferent");
const InstrumentAnalyzer = require("./../InstrumentAnalyzer");
const BracketHelper = require("./../../core/BracketHelper");
const InstrToken1StdTitleType = require("./InstrToken1StdTitleType");
const MailLineTypes = require("./../../mail/internal/MailLineTypes");
const MailLine = require("./../../mail/internal/MailLine");
const BlockTitleToken = require("./../../core/internal/BlockTitleToken");
const LanguageHelper = require("./../../../morph/LanguageHelper");
const ParticipantTokenKinds = require("./ParticipantTokenKinds");
const ComplexNumToken = require("./../../core/ComplexNumToken");
const OrganizationKind = require("./../../org/OrganizationKind");
const ParticipantToken = require("./ParticipantToken");
const PersonIdentityReferent = require("./../../person/PersonIdentityReferent");
const ReferentToken = require("./../../ReferentToken");
const Referent = require("./../../Referent");
const DecreeTokenItemType = require("./../../decree/internal/DecreeTokenItemType");
const DecreeKind = require("./../../decree/DecreeKind");
const MiscHelper = require("./../../core/MiscHelper");
const DateReferent = require("./../../date/DateReferent");
const NumberTypes = require("./NumberTypes");
const InstrumentKind = require("./../InstrumentKind");
const GetTextAttr = require("./../../core/GetTextAttr");
const DecreePartReferent = require("./../../decree/DecreePartReferent");
const DecreeChangeReferent = require("./../../decree/DecreeChangeReferent");
const ILTypes = require("./ILTypes");
const InstrumentBlockReferent = require("./../InstrumentBlockReferent");
const TableHelper = require("./../../core/TableHelper");
const StreetReferent = require("./../../address/StreetReferent");
const BracketParseAttr = require("./../../core/BracketParseAttr");
const PhoneReferent = require("./../../phone/PhoneReferent");
const UriReferent = require("./../../uri/UriReferent");
const DateItemToken = require("./../../date/internal/DateItemToken");
const PartToken = require("./../../decree/internal/PartToken");
const PersonReferent = require("./../../person/PersonReferent");
const AddressReferent = require("./../../address/AddressReferent");
const MorphGender = require("./../../../morph/MorphGender");
const DecreeReferent = require("./../../decree/DecreeReferent");
const PersonPropertyReferent = require("./../../person/PersonPropertyReferent");
const NumberingHelper = require("./NumberingHelper");
const DecreeToken = require("./../../decree/internal/DecreeToken");
const DecreeHelper = require("./../../decree/internal/DecreeHelper");
const InstrumentReferent = require("./../InstrumentReferent");

class FragToken extends MetaToken {
    
    constructor(b, e) {
        super(b, e, null);
        this.kind = InstrumentKind.UNDEFINED;
        this.kind2 = InstrumentKind.UNDEFINED;
        this.value = null;
        this.name = null;
        this.number = 0;
        this.minNumber = 0;
        this.subNumber = 0;
        this.subNumber2 = 0;
        this.subNumber3 = 0;
        this.tableColumns = 0;
        this.referents = null;
        this.isExpired = false;
        this.isError = false;
        this.children = new Array();
        this.m_Doc = null;
        this.itok = null;
        for (let t = this.endToken.next; t !== null; t = t.next) {
            if (t.isChar(String.fromCharCode(7)) || t.isChar(String.fromCharCode(0x1F))) 
                this.endToken = t;
            else 
                break;
        }
    }
    
    get numberString() {
        if (this.subNumber === 0) 
            return this.number.toString();
        let tmp = new StringBuilder();
        tmp.append(this.number).append(".").append(this.subNumber);
        if (this.subNumber2 > 0) 
            tmp.append(".").append(this.subNumber2);
        if (this.subNumber3 > 0) 
            tmp.append(".").append(this.subNumber3);
        return tmp.toString();
    }
    
    sortChildren() {
        for (let k = 0; k < this.children.length; k++) {
            let ch = false;
            for (let i = 0; i < (this.children.length - 1); i++) {
                if (this.children[i].compareTo(this.children[i + 1]) > 0) {
                    ch = true;
                    let v = this.children[i];
                    this.children[i] = this.children[i + 1];
                    this.children[i + 1] = v;
                }
            }
            if (!ch) 
                break;
        }
    }
    
    findChild(_kind) {
        for (const ch of this.children) {
            if (ch.kind === _kind) 
                return ch;
        }
        return null;
    }
    
    compareTo(other) {
        if (this.beginChar < other.beginChar) 
            return -1;
        if (this.beginChar > other.beginChar) 
            return 1;
        if (this.endChar < other.endChar) 
            return -1;
        if (this.endChar > other.endChar) 
            return 1;
        return 0;
    }
    
    get minChildNumber() {
        for (const ch of this.children) {
            if (ch.number > 0) {
                if (ch.number !== 1) {
                    if (ch.itok !== null && ch.itok.numTyp === NumberTypes.LETTER) 
                        return 0;
                }
                return ch.number;
            }
        }
        return 0;
    }
    
    get maxChildNumber() {
        let max = 0;
        for (const ch of this.children) {
            if (ch.number > max) 
                max = ch.number;
        }
        return max;
    }
    
    get defVal() {
        return false;
    }
    set defVal(_value) {
        let str = this.getSourceText();
        while (str.length > 0) {
            let last = str[str.length - 1];
            let first = str[0];
            if (((last.charCodeAt(0)) === 0x1E || (last.charCodeAt(0)) === 0x1F || (last.charCodeAt(0)) === 7) || Utils.isWhitespace(last)) 
                str = str.substring(0, 0 + str.length - 1);
            else if (((first.charCodeAt(0)) === 0x1E || (first.charCodeAt(0)) === 0x1F || (first.charCodeAt(0)) === 7) || Utils.isWhitespace(first)) 
                str = str.substring(1);
            else 
                break;
        }
        this.value = str;
        return _value;
    }
    
    get defVal2() {
        return false;
    }
    set defVal2(_value) {
        this.value = FragToken.getRestoredNameMT(this, false);
        return _value;
    }
    
    checkExpired() {
        let tt = this.beginToken;
        if (this.itok !== null && this.itok.numEndToken !== null) 
            tt = this.itok.numEndToken.next;
        if (tt !== null && (tt.getReferent() instanceof DecreePartReferent)) 
            tt = tt.next;
        else {
            let pp = PartToken.tryAttach(tt, null, false, false);
            if (pp === null) 
                pp = PartToken.tryAttach(tt, null, false, true);
            if (pp !== null) 
                tt = pp.endToken.next;
        }
        if ((tt !== null && tt.isValue("УТРАТИТЬ", "ВТРАТИТИ") && tt.next !== null) && tt.next.isValue("СИЛА", "ЧИННІСТЬ")) 
            this.isExpired = true;
        else if (tt !== null && tt.isValue("ИСКЛЮЧИТЬ", null)) {
            if (tt.isNewlineAfter) 
                this.isExpired = true;
            else if (tt.next !== null && ((tt.next.isHiphen || tt.next.isCharOf(".;")))) 
                this.isExpired = true;
        }
    }
    
    static getRestoredNameMT(mt, indexItem = false) {
        return FragToken.getRestoredName(mt.beginToken, mt.endToken, indexItem);
    }
    
    static getRestoredName(b, e, indexItem = false) {
        let e0 = e;
        for (; e !== null && e.beginChar > b.endChar; e = e.previous) {
            if (e.isCharOf("*<") || e.isTableControlChar) {
            }
            else if ((e.isCharOf(">") && (e.previous instanceof NumberToken) && e.previous.previous !== null) && e.previous.previous.isChar('<')) 
                e = e.previous;
            else if (e.isCharOf(">") && e.previous.isChar('*')) {
            }
            else if ((e instanceof NumberToken) && ((e === e0 || e.next.isTableControlChar)) && indexItem) {
            }
            else if (((e.isChar('.') || e.isHiphen)) && indexItem) {
            }
            else 
                break;
        }
        let b0 = b;
        for (; b !== null && b.endChar <= e.endChar; b = b.next) {
            if (b.isTableControlChar) {
            }
            else {
                b0 = b;
                break;
            }
        }
        let str = MiscHelper.getTextValue(b0, e, GetTextAttr.of((GetTextAttr.RESTOREREGISTER.value()) | (GetTextAttr.KEEPREGISTER.value()) | (GetTextAttr.KEEPQUOTES.value())));
        if (!Utils.isNullOrEmpty(str)) {
            if (BracketHelper.isBracketChar(str[0], true) && BracketHelper.isBracketChar(str[str.length - 1], true)) 
                str = str.substring(1, 1 + str.length - 2);
            if (Utils.isLowerCase(str[0])) 
                str = (str[0].toUpperCase() + str.substring(1));
        }
        return str;
    }
    
    toString() {
        let tmp = new StringBuilder();
        if (this.kind !== InstrumentKind.UNDEFINED) {
            tmp.append(String(this.kind)).append(":");
            if (this.kind2 !== InstrumentKind.UNDEFINED) 
                tmp.append(" (").append(String(this.kind2)).append("):");
        }
        else if (this.itok !== null) 
            tmp.append(this.itok).append(" ");
        if (this.number > 0) {
            if (this.minNumber > 0) 
                tmp.append(" Num=[").append(this.minNumber).append("..").append(this.number).append("]");
            else 
                tmp.append(" Num=").append(this.number);
            if (this.subNumber > 0) 
                tmp.append(".").append(this.subNumber);
            if (this.subNumber2 > 0) 
                tmp.append(".").append(this.subNumber2);
            if (this.subNumber3 > 0) 
                tmp.append(".").append(this.subNumber3);
        }
        if (this.isExpired) 
            tmp.append(" Expired");
        if (this.isError) 
            tmp.append(" Error");
        if (this.children.length > 0) 
            tmp.append(" ChCount=").append(this.children.length);
        if (this.name !== null) 
            tmp.append(" Nam='").append(this.name).append("'");
        if (this.value !== null) 
            tmp.append(" Val='").append(this.value.toString()).append("'");
        if (tmp.length === 0) 
            tmp.append(this.getSourceText());
        return tmp.toString();
    }
    
    createReferent(ad) {
        return this._CreateReferent(ad, this);
    }
    
    _CreateReferent(ad, bas) {
        let res = null;
        if (this.m_Doc !== null) 
            res = this.m_Doc;
        else {
            res = new InstrumentBlockReferent();
            res.kind = this.kind;
            res.kind2 = this.kind2;
            if (this.number > 0) 
                res.number = this.number;
            if (this.minNumber > 0) 
                res.minNumber = this.minNumber;
            if (this.subNumber > 0) 
                res.subNumber = this.subNumber;
            if (this.subNumber2 > 0) 
                res.subNumber2 = this.subNumber2;
            if (this.subNumber3 > 0) 
                res.subNumber3 = this.subNumber3;
            let tnum = this._calcTailNumber();
            if (tnum !== null) 
                res.addSlot(InstrumentBlockReferent.ATTR_TAILNUMBER, tnum, false, 0);
            if (this.kind === InstrumentKind.TABLE) {
                if (this.tableColumns > 0) 
                    res.tableColumns = this.tableColumns;
            }
            if (this.isExpired) 
                res.isExpired = true;
            if (this.isError) 
                res.isError = true;
            if (this.name !== null && this.kind !== InstrumentKind.HEAD) {
                let s = res.addSlot(InstrumentBlockReferent.ATTR_NAME, this.name.toUpperCase(), false, 0);
                s.tag = this.name;
            }
            if (this.value !== null && this.kind !== InstrumentKind.CONTACT) {
                if ((typeof this.value === 'string' || this.value instanceof String)) 
                    res.addSlot(InstrumentBlockReferent.ATTR_VALUE, this.value, false, 0);
                else if (this.value instanceof Referent) 
                    res.addSlot(InstrumentBlockReferent.ATTR_REF, this.value, false, 0);
                else if (this.value instanceof ReferentToken) {
                    let r = this.value.referent;
                    this.value.saveToLocalOntology();
                    res.addSlot(InstrumentBlockReferent.ATTR_REF, this.value.referent, false, 0);
                    res.addExtReferent(Utils.as(this.value, ReferentToken));
                    let s = bas.m_Doc.findSlot(null, r, true);
                    if (s !== null) 
                        s.value = this.value.referent;
                }
                else if (this.value instanceof DecreeToken) {
                    let dt = Utils.as(this.value, DecreeToken);
                    if (dt.ref instanceof ReferentToken) {
                        let r = dt.ref.referent;
                        dt.ref.saveToLocalOntology();
                        res.addSlot(InstrumentBlockReferent.ATTR_REF, dt.ref.referent, false, 0);
                        res.addExtReferent(Utils.as(dt.ref, ReferentToken));
                        let s = bas.m_Doc.findSlot(null, r, true);
                        if (s !== null) 
                            s.value = dt.ref.referent;
                    }
                    else if (dt.value !== null) 
                        res.addSlot(InstrumentBlockReferent.ATTR_VALUE, dt.value, false, 0);
                }
            }
            if (this.referents !== null) {
                for (const r of this.referents) {
                    res.addSlot(InstrumentBlockReferent.ATTR_REF, r, false, 0);
                }
            }
            if (this.children.length === 0) {
                for (let t = this.beginToken; t !== null && (t.beginChar < this.endChar); t = t.next) {
                    if (t.getReferent() instanceof DecreeChangeReferent) 
                        res.addSlot(InstrumentBlockReferent.ATTR_REF, t.getReferent(), false, 0);
                    if (t.endChar > this.endChar) 
                        break;
                }
            }
        }
        if (ad !== null) {
            if (ad.referents.length > 200000) 
                return null;
            if (this.beginChar <= this.endChar) {
                ad.referents.push(res);
                res.addOccurenceOfRefTok(new ReferentToken(res, this.beginToken, this.endToken));
            }
        }
        for (const ch of this.children) {
            let ich = ch._CreateReferent(ad, bas);
            if (ich !== null) 
                res.addSlot(InstrumentBlockReferent.ATTR_CHILD, ich, false, 0);
        }
        return res;
    }
    
    fillByContentChildren() {
        this.sortChildren();
        if (this.children.length === 0) {
            this.children.push(FragToken._new2000(this.beginToken, this.endToken, InstrumentKind.CONTENT));
            return;
        }
        if (this.beginChar < this.children[0].beginChar) 
            this.children.splice(0, 0, FragToken._new2000(this.beginToken, this.children[0].beginToken.previous, InstrumentKind.CONTENT));
        for (let i = 0; i < (this.children.length - 1); i++) {
            if (this.children[i].endToken.next !== this.children[i + 1].beginToken && (this.children[i].endToken.next.endChar < this.children[i + 1].beginChar)) 
                this.children.splice(i + 1, 0, FragToken._new2000(this.children[i].endToken.next, this.children[i + 1].beginToken.previous, InstrumentKind.CONTENT));
        }
        if (this.children[this.children.length - 1].endChar < this.endChar) 
            this.children.push(FragToken._new2000(this.children[this.children.length - 1].endToken.next, this.endToken, InstrumentKind.CONTENT));
    }
    
    static createDocument(t, maxChar, rootKind = InstrumentKind.UNDEFINED) {
        const InstrToken = require("./InstrToken");
        const InstrToken1 = require("./InstrToken1");
        if (t === null) 
            return null;
        DecreeHelper.removePsevdoDecreeparts(t.kit);
        while ((t instanceof TextToken) && t.next !== null) {
            let tt = MiscHelper.checkImage(t);
            if (tt !== null) {
                t = tt.next;
                continue;
            }
            if (t.isTableControlChar || !t.chars.isLetter || t.isValue("КОНСУЛЬТАНТПЛЮС", null)) 
                t = t.next;
            else if (t.isValue2("ДОКУМЕНТ", "ПРЕДОСТАВЛЕН")) 
                t = t.next.next;
            else 
                break;
        }
        let cou1 = 10;
        let cons = true;
        for (let tt = t; tt !== null && cou1 > 0; tt = tt.next) {
            if (!tt.isNewlineBefore) 
                continue;
            cou1--;
            if (tt.isValue3("ДОКУМЕНТ", "ПРЕДОСТАВЛЕН", "КОНСУЛЬТАНТПЛЮС")) {
                tt = tt.next.next;
                t = tt;
                cons = true;
                continue;
            }
            if (tt.isValue2("ДАТА", "СОХРАНЕНИЯ")) {
                tt = tt.next.next;
                if (tt !== null && tt.isChar(':')) 
                    tt = tt.next;
                if (tt !== null && (tt.getReferent() instanceof DateReferent)) 
                    tt = tt.next;
                t = tt;
                continue;
            }
        }
        if (t === null) 
            return null;
        if (t.getReferent() instanceof DecreeReferent) {
            let dec0 = Utils.as(t.getReferent(), DecreeReferent);
            if (dec0.kind === DecreeKind.PUBLISHER) 
                t = t.next;
            else 
                t = t.kit.debedToken(t);
        }
        else if (t.getReferent() instanceof DecreePartReferent) {
            let dp = Utils.as(t.getReferent(), DecreePartReferent);
            if ((dp.clause !== null || dp.item !== null || dp.subItem !== null) || dp.indention !== null) {
            }
            else 
                t = t.kit.debedToken(t);
        }
        if (t === null) 
            return null;
        let res = FragToken.__createActionQuestion(t, maxChar);
        if (res !== null) 
            return res;
        res = FragToken._new2000(t, t, InstrumentKind.DOCUMENT);
        res.m_Doc = new InstrumentReferent();
        let isApp = false;
        let cou = 0;
        for (let ttt = t; ttt !== null && (cou < 5); ttt = ttt.next,cou++) {
            if (ttt.isNewlineBefore || ttt.previous.isTableControlChar) {
                if (ttt.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК")) {
                    isApp = true;
                    break;
                }
                if (ttt.getReferent() instanceof DecreeReferent) 
                    break;
                let dtt = DecreeToken.tryAttach(ttt, null, false);
                if (dtt !== null && ((dtt.typ === DecreeTokenItemType.TYP || dtt.typ === DecreeTokenItemType.NUMBER || dtt.typ === DecreeTokenItemType.TERR))) 
                    break;
                if (ttt instanceof NumberToken) 
                    break;
            }
        }
        let head = (isApp || maxChar > 0 ? null : FragToken.createDocTitle(t, res.m_Doc));
        let headKind = DecreeKind.UNDEFINED;
        if (head !== null && (head.tag instanceof DecreeKind)) 
            headKind = DecreeKind.of(head.tag);
        let head1 = null;
        let appDoc = new InstrumentReferent();
        if (maxChar > 0 && !isApp) {
        }
        else 
            head1 = FragToken.createAppendixTitle(t, res, appDoc, true, true);
        if (head1 !== null) {
            if (head1.tag instanceof FragToken) {
                res.m_Doc = appDoc;
                res.children.push(head1);
                res.children.push(Utils.as(head1.tag, FragToken));
                res.endToken = head1.tag.endToken;
                return res;
            }
            let ee = false;
            if (head === null) 
                ee = true;
            else if (head1.endChar > head.endChar && ((res.m_Doc.typ === "ПРИЛОЖЕНИЕ" || res.m_Doc.typ === "ДОДАТОК"))) 
                ee = true;
            else if (head1.children.length > head.children.length && head1.endChar > head.endChar) 
                ee = true;
            if (ee) {
                head = head1;
                res.m_Doc = appDoc;
            }
        }
        if (head !== null) {
            if (maxChar === 0) 
                FragToken._createJusticeParticipants(head, res.m_Doc);
            head.sortChildren();
            res.children.push(head);
            res.endToken = head.endToken;
            if (head.beginChar < res.beginChar) 
                res.beginToken = head.beginToken;
            if (head.children.length > 1 && head.children[head.children.length - 1].kind === InstrumentKind.IGNORED) {
                let last = head.children[head.children.length - 1];
                res.children.push(last);
                Utils.removeItem(head.children, last);
                head.endToken = last.beginToken.previous;
            }
            t = res.endToken.next;
        }
        if (t === null) {
            if (head !== null && head.children.length > 2) 
                return res;
            return null;
        }
        let isContract = false;
        if (res.m_Doc.typ !== null) {
            if (res.m_Doc.typ.includes("ДОГОВОР") || res.m_Doc.typ.includes("ДОГОВІР") || res.m_Doc.typ.includes("КОНТРАКТ")) 
                isContract = true;
        }
        let t0 = t;
        let li = InstrToken.parseList(t, maxChar);
        if (li === null || li.length === 0) 
            return null;
        let i = 0;
        if (isApp) {
            for (i = 0; i < li.length; i++) {
                if (li[i].typ === ILTypes.APPROVED) 
                    li[i].typ = ILTypes.UNDEFINED;
                else if (li[i].typ === ILTypes.APPENDIX && li[i].value !== "ПРИЛОЖЕНИЕ" && li[i].value !== "ДОДАТОК") 
                    li[i].typ = ILTypes.UNDEFINED;
            }
        }
        let tmpApps = new Array();
        for (i = 0; i < li.length; i++) {
            if (li[i].typ === ILTypes.APPENDIX || li[i].typ === ILTypes.APPROVED) 
                tmpApps.push(li[i]);
        }
        for (i = 0; i < (li.length - 1); i++) {
            if (li[i].typ === ILTypes.APPENDIX) {
                if (i > 0 && li[i - 1].typ === ILTypes.PERSON) 
                    break;
                let num1 = InstrToken1.parse(li[i].beginToken, true, null, 0, null, false, 0, false, false);
                let maxNum = i + 7;
                let i0 = i;
                for (let j = i + 1; (j < li.length) && (j < maxNum); j++) {
                    if (li[j].typ === ILTypes.APPENDIX) {
                        if (li[j].whitespacesBeforeCount > 1) 
                            break;
                        if (li[j].value !== li[i].value) {
                            if (li[i].value === "ПРИЛОЖЕНИЕ" || li[i].value === "ДОДАТОК") 
                                li[j].typ = ILTypes.UNDEFINED;
                            else if (li[j].value === "ПРИЛОЖЕНИЕ" || li[j].value === "ДОДАТОК") {
                                li[i].typ = ILTypes.UNDEFINED;
                                break;
                            }
                        }
                        else {
                            let le = li[j].beginChar - li[i0].beginChar;
                            if (le > 400) 
                                break;
                            if ((j - i0) > 3) 
                                break;
                            i = j;
                            let num2 = InstrToken1.parse(li[j].beginToken, true, null, 0, null, false, 0, false, false);
                            let d = NumberingHelper.calcDelta(num1, num2, true);
                            if (d === 1) {
                                li[i0].typ = ILTypes.UNDEFINED;
                                li[j].typ = ILTypes.UNDEFINED;
                                i0 = j;
                            }
                            num1 = num2;
                            maxNum = j + 7;
                        }
                    }
                    else if (li[j].typ === ILTypes.APPROVED) 
                        li[j].typ = ILTypes.UNDEFINED;
                }
            }
        }
        let hasApp = false;
        for (i = 0; i < li.length; i++) {
            if (li[i].typ === ILTypes.APPENDIX || li[i].typ === ILTypes.APPROVED) {
                if (li[i].typ === ILTypes.APPROVED) {
                    hasApp = true;
                    if (i === 0) 
                        continue;
                    if (!li[i].isNewlineAfter) {
                        if (((i + 1) < li.length) && li[i + 1].isNewlineAfter && li[i + 1].typ === ILTypes.UNDEFINED) {
                        }
                        else 
                            continue;
                    }
                }
                if (li[i].ref instanceof DecreeReferent) {
                    let ok = false;
                    let cou2 = 20;
                    for (let tt = li[i].beginToken; tt !== null && cou2 > 0; tt = tt.next,cou2--) {
                        let dr = Utils.as(tt.getReferent(), DecreeReferent);
                        if (dr === null) 
                            continue;
                        if (dr.typ !== res.m_Doc.typ) 
                            continue;
                        if (dr.number !== null && res.m_Doc.regNumber !== null) {
                            if (dr.number !== res.m_Doc.regNumber) 
                                continue;
                        }
                        ok = true;
                        break;
                    }
                    if (!ok) 
                        continue;
                }
                break;
            }
        }
        let i1 = i;
        if (maxChar === 0 && i1 === li.length) {
            for (i = 0; i < li.length; i++) {
                if (li[i].typ === ILTypes.PERSON && li[i].isNewlineBefore && ((!li[i].hasTableChars || li[i].isPurePerson))) {
                    let j = 0;
                    let dat = false;
                    let num = false;
                    let _geo = false;
                    let pers = 0;
                    for (j = i + 1; j < li.length; j++) {
                        if (li[j].typ === ILTypes.GEO) 
                            _geo = true;
                        else if (li[j].typ === ILTypes.REGNUMBER) 
                            num = true;
                        else if (li[j].typ === ILTypes.DATE) 
                            dat = true;
                        else if (li[j].typ === ILTypes.PERSON && li[j].isPurePerson) {
                            if (((li[j].isNewlineBefore || ((li[j - 1].typ === ILTypes.PERSON || li[j - 1].typ === ILTypes.DATE)))) && ((li[j].isNewlineAfter || ((((j + 1) < li.length) && ((li[j + 1].typ === ILTypes.PERSON || li[j + 1].typ === ILTypes.DATE))))))) 
                                pers++;
                            else 
                                break;
                        }
                        else if (li[j].noWords) {
                        }
                        else 
                            break;
                    }
                    let k = pers;
                    if (dat) 
                        k++;
                    if (num) 
                        k++;
                    if (_geo) 
                        k++;
                    if ((j < li.length) && ((li[j].typ === ILTypes.APPENDIX || li[j].typ === ILTypes.APPROVED))) 
                        k += 2;
                    else if ((li[i].isPurePerson && li[i].beginToken.previous !== null && li[i].beginToken.previous.isChar('.')) && li[i].isNewlineAfter) {
                        let itt = InstrToken1.parse(li[i].endToken.next, true, null, 0, null, false, 0, false, false);
                        if (itt !== null && itt.numbers.length > 0 && li[i + 1].typ === ILTypes.UNDEFINED) {
                        }
                        else 
                            k += 2;
                    }
                    if (k >= 2) {
                        i = j;
                        if ((i < li.length) && ((li[i].typ === ILTypes.UNDEFINED || li[i].typ === ILTypes.TYP))) 
                            li[i].typ = ILTypes.APPROVED;
                        if ((i > (i1 + 10) && (i1 < li.length) && li[i1].typ === ILTypes.APPENDIX) && li[i1].whitespacesBeforeCount > 15) {
                        }
                        else 
                            i1 = i;
                        break;
                    }
                }
            }
        }
        if ((maxChar === 0 && (i1 < li.length) && (i1 + 10) > li.length) && !hasApp && ((li[li.length - 1].endChar - li[i1].endChar) < 200)) {
            for (let ii = li.length - 1; ii > i; ii--) {
                if (li[ii].typ === ILTypes.PERSON || li[ii].typ === ILTypes.DATE || ((li[ii].typ === ILTypes.REGNUMBER && li[ii].isNewlineBefore))) {
                    i1 = ii + 1;
                    break;
                }
            }
        }
        let cMax = i1 - 1;
        let tail = null;
        let persList = new Array();
        for (i = i1 - 1; i > 0; i--) {
            if (maxChar > 0) 
                break;
            let lii = li[i];
            if (lii.hasTableChars) {
                if ((i < (i1 - 1)) && lii.typ !== ILTypes.PERSON && !lii.noWords) 
                    break;
                if (isContract) 
                    break;
            }
            if ((lii.typ === ILTypes.PERSON || lii.typ === ILTypes.REGNUMBER || lii.typ === ILTypes.DATE) || lii.typ === ILTypes.GEO) {
                if (!lii.isNewlineBefore && li[i - 1].typ === ILTypes.UNDEFINED && li[i - 1].hasVerb) 
                    break;
                if (persList.length > 0) {
                    if (lii.typ !== ILTypes.PERSON && lii.typ !== ILTypes.DATE) 
                        break;
                    if (!lii.isNewlineBefore && !lii.isNewlineAfter && !lii.hasTableChars) {
                        if (!lii.isNewlineBefore && i > 0 && li[i - 1].typ === ILTypes.PERSON) {
                        }
                        else 
                            break;
                    }
                }
                if (lii.typ === ILTypes.PERSON && (lii.ref instanceof ReferentToken)) {
                    if (persList.includes(lii.ref.referent)) {
                        if (!lii.isNewlineBefore) 
                            break;
                    }
                }
                if (!lii.isNewlineBefore && !lii.beginToken.isTableControlChar && ((lii.typ === ILTypes.GEO || li[i].typ === ILTypes.PERSON))) {
                    if (i > 0 && ((li[i - 1].typ === ILTypes.UNDEFINED && !li[i - 1].endToken.isTableControlChar))) {
                        if (li[i - 1].beginToken.isValue("ИСП", null) || li[i - 1].beginToken.isValue("ИСПОЛНИТЕЛЬ", null)) {
                        }
                        else 
                            break;
                    }
                    if (lii.endToken.isCharOf(";.")) 
                        break;
                    if (!lii.isNewlineAfter) {
                        if (lii.endToken.next !== null && !lii.endToken.next.isTableControlChar) 
                            break;
                    }
                }
                if (tail === null) {
                    tail = FragToken._new2000(li[i].beginToken, li[i1 - 1].endToken, InstrumentKind.TAIL);
                    if ((i1 - 1) > i) {
                    }
                }
                tail.beginToken = lii.beginToken;
                cMax = i - 1;
                let fr = new FragToken(li[i].beginToken, li[i].endToken);
                tail.children.splice(0, 0, fr);
                if (li[i].typ === ILTypes.PERSON) {
                    fr.kind = InstrumentKind.SIGNER;
                    if (li[i].ref instanceof ReferentToken) {
                        res.m_Doc.addSlot(InstrumentReferent.ATTR_SIGNER, li[i].ref.referent, false, 0);
                        res.m_Doc.addExtReferent(Utils.as(li[i].ref, ReferentToken));
                        fr.value = li[i].ref;
                        persList.push(li[i].ref.referent);
                    }
                }
                else if (li[i].typ === ILTypes.REGNUMBER) {
                    if (li[i].isNewlineBefore) {
                        if (res.m_Doc.regNumber === null || res.m_Doc.regNumber === li[i].value) {
                            fr.kind = InstrumentKind.NUMBER;
                            fr.value = li[i].value;
                            res.m_Doc.addSlot(InstrumentBlockReferent.ATTR_NUMBER, li[i].value, false, 0);
                        }
                    }
                }
                else if (li[i].typ === ILTypes.DATE) {
                    fr.kind = InstrumentKind.DATE;
                    fr.value = li[i].value;
                    if (li[i].ref !== null) {
                        res.m_Doc.addDate(li[i].ref);
                        fr.value = li[i].ref;
                    }
                    else if (li[i].value !== null) 
                        res.m_Doc.addDate(li[i].value);
                }
                else if (li[i].typ === ILTypes.GEO) {
                    fr.kind = InstrumentKind.PLACE;
                    fr.value = li[i].ref;
                }
                if (fr.value === null) 
                    fr.value = MiscHelper.getTextValueOfMetaToken(fr, GetTextAttr.NO);
            }
            else {
                let ss = MiscHelper.getTextValue(li[i].beginToken, li[i].endToken, GetTextAttr.KEEPQUOTES);
                if (ss === null || ss.length === 0) 
                    continue;
                if (ss[ss.length - 1] === ':') 
                    ss = ss.substring(0, 0 + ss.length - 1);
                if (li[i].isPodpisStoron && tail !== null) {
                    tail.beginToken = li[i].beginToken;
                    tail.children.splice(0, 0, FragToken._new2064(li[i].beginToken, li[i].endToken, InstrumentKind.NAME, ss));
                    cMax = i - 1;
                    break;
                }
                let jj = 0;
                for (jj = 0; jj < ss.length; jj++) {
                    if (Utils.isLetterOrDigit(ss[jj])) 
                        break;
                }
                if (jj >= ss.length) 
                    continue;
                if ((ss.length < 100) && (((i1 - i) < 5))) 
                    continue;
                if ((ss.length < 15) && (((i1 - i) < 10))) 
                    continue;
                break;
            }
        }
        if (cMax < 0) {
            if (i1 > 0) 
                return null;
        }
        else {
            let content = FragToken._new2000(li[0].beginToken, li[cMax].endToken, InstrumentKind.CONTENT);
            res.children.push(content);
            content._analizeContent(res, maxChar > 0, rootKind);
            if (maxChar > 0 && cMax === (li.length - 1) && head === null) 
                res = content;
        }
        if (tail !== null) {
            res.children.push(tail);
            for (; i1 < li.length; i1++) {
                if (li[i1].beginToken === li[i1].endToken && (li[i1].beginToken.getReferent() instanceof DecreeReferent) && li[i1].beginToken.getReferent().kind === DecreeKind.PUBLISHER) {
                    let ap = FragToken._new2000(li[i1].beginToken, li[i1].endToken, InstrumentKind.APPROVED);
                    ap.referents = new Array();
                    ap.referents.push(Utils.as(li[i1].beginToken.getReferent(), DecreeReferent));
                    tail.children.push(ap);
                    tail.endToken = li[i1].endToken;
                }
                else 
                    break;
            }
            if (tail.children.length > 0 && (tail.children[tail.children.length - 1].endChar < tail.endChar)) {
                let unkw = FragToken._new2000(tail.children[tail.children.length - 1].endToken.next, tail.endToken, InstrumentKind.UNDEFINED);
                tail.endToken = unkw.beginToken.previous;
                res.children.push(unkw);
            }
        }
        let isAllApps = isApp;
        let app0 = null;
        for (i = i1; i < li.length; i++) {
            let j = 0;
            let app = new FragToken(li[i].beginToken, li[i].endToken);
            let title = FragToken.createAppendixTitle(app.beginToken, app, res.m_Doc, isAllApps, false);
            for (j = i + 1; j < li.length; j++) {
                if (title !== null && li[j].endChar <= title.endChar) 
                    continue;
                if (li[j].typ === ILTypes.APPENDIX) {
                    if (li[j].value === li[i1].value) 
                        break;
                    if (li[j].typ === li[i1].typ) 
                        break;
                    if (li[j].value !== null && li[i1].value === null) 
                        break;
                    continue;
                }
                else if (li[j].typ === ILTypes.APPROVED) {
                    if ((li[j].beginChar - li[i].endChar) > 200) 
                        break;
                }
            }
            app.endToken = li[j - 1].endToken;
            tail = null;
            if (li[j - 1].typ === ILTypes.PERSON && li[j - 1].isNewlineBefore && li[j - 1].isNewlineAfter) {
                tail = FragToken._new2000(li[j - 1].beginToken, li[j - 1].endToken, InstrumentKind.TAIL);
                for (let jj = j - 1; jj > i; jj--) {
                    if (li[jj].typ !== ILTypes.PERSON || !li[jj].isNewlineBefore || !li[jj].isNewlineAfter) 
                        break;
                    else {
                        let fr = FragToken._new2000(li[jj].beginToken, li[jj].endToken, InstrumentKind.SIGNER);
                        if (li[jj].ref instanceof ReferentToken) 
                            fr.value = li[jj].ref;
                        tail.children.splice(0, 0, fr);
                        tail.beginToken = fr.beginToken;
                        app.endToken = tail.beginToken.previous;
                    }
                }
            }
            if (li[i].typ === ILTypes.APPENDIX || ((((i + 1) < li.length) && li[i + 1].typ === ILTypes.APPENDIX))) 
                app.kind = InstrumentKind.APPENDIX;
            else if (app.kind !== InstrumentKind.APPENDIX) 
                app.kind = InstrumentKind.INTERNALDOCUMENT;
            if (title === null) {
                let ok = true;
                if (app.lengthChar < 500) 
                    ok = false;
                else {
                    app._analizeContent(app, false, InstrumentKind.UNDEFINED);
                    if (app.children.length < 2) 
                        ok = false;
                }
                if (ok) 
                    res.children.push(app);
                else if (res.children.length > 0) {
                    app.kind = InstrumentKind.UNDEFINED;
                    res.children[res.children.length - 1].children.push(app);
                    res.children[res.children.length - 1].endToken = app.endToken;
                }
            }
            else {
                if (isApp && app.kind === InstrumentKind.APPENDIX) {
                    if (res.children.length > 0) 
                        res.endToken = res.children[res.children.length - 1].endToken;
                    let res0 = FragToken._new2070(res.beginToken, res.endToken, res.m_Doc, InstrumentKind.DOCUMENT);
                    res.m_Doc = null;
                    res.kind = InstrumentKind.APPENDIX;
                    res0.children.splice(0, 0, res);
                    res = res0;
                    isApp = false;
                }
                if ((app0 !== null && !isApp && app0.kind === InstrumentKind.INTERNALDOCUMENT) && app.kind === InstrumentKind.APPENDIX) 
                    app0.children.push(app);
                else 
                    res.children.push(app);
                if (!isApp && app.kind === InstrumentKind.INTERNALDOCUMENT) 
                    app0 = app;
                if (title.name !== null) {
                    app.name = title.name;
                    title.name = null;
                }
                if (title.isExpired) {
                    app.isExpired = true;
                    title.isExpired = false;
                }
                app.children.push(title);
                if (app.endChar < title.endChar) 
                    app.endToken = title.endToken;
                if (title.endToken.next !== null) {
                    if (title.endToken.endChar < app.endToken.beginChar) {
                        let acontent = FragToken._new2000(title.endToken.next, app.endToken, InstrumentKind.CONTENT);
                        app.children.push(acontent);
                        acontent._analizeContent(app, false, InstrumentKind.UNDEFINED);
                    }
                    else {
                    }
                }
                if (app.children.length === 1 && app.kind !== InstrumentKind.APPENDIX) {
                    app.children.splice(0, app.children.length);
                    app.kind = InstrumentKind.UNDEFINED;
                    app.name = null;
                }
            }
            if (tail !== null) {
                app.children.push(tail);
                app.endToken = tail.endToken;
            }
            i = j - 1;
        }
        if (res.children.length > 0) 
            res.endToken = res.children[res.children.length - 1].endToken;
        let appendixes = new Array();
        for (const ch of res.children) {
            if (ch.kind === InstrumentKind.APPENDIX) 
                appendixes.push(ch);
        }
        for (i = 1; i < appendixes.length; i++) {
            let maxCoef = 0;
            let ii = -1;
            for (let j = i - 1; j >= 0; j--) {
                let coef = appendixes[i].calcOwnerCoef(appendixes[j]);
                if (coef > maxCoef) {
                    maxCoef = coef;
                    ii = j;
                }
            }
            if (ii < 0) 
                continue;
            appendixes[ii].children.push(appendixes[i]);
            Utils.removeItem(res.children, appendixes[i]);
        }
        if (maxChar > 0) 
            return res;
        if (!isContract && headKind !== DecreeKind.STANDARD) {
            for (const ch of res.children) {
                if (ch.kind === InstrumentKind.APPENDIX || ch.kind === InstrumentKind.INTERNALDOCUMENT || ch.kind === InstrumentKind.HEAD) {
                    if (ch.kind === InstrumentKind.APPENDIX && res.m_Doc.name !== null) 
                        continue;
                    let hi = (ch.kind === InstrumentKind.HEAD ? ch : ch.findChild(InstrumentKind.HEAD));
                    if (hi !== null) {
                        hi = hi.findChild(InstrumentKind.NAME);
                        if (hi !== null && hi.value !== null && hi.value.toString().length > 20) 
                            res.m_Doc.addSlot(InstrumentBlockReferent.ATTR_NAME, hi.value, false, 0);
                    }
                }
            }
        }
        if (res.m_Doc.typ === null) {
            for (const ch of res.children) {
                if (ch.kind === InstrumentKind.APPENDIX) {
                    let hi = ch.findChild(InstrumentKind.HEAD);
                    if (hi !== null) 
                        hi = hi.findChild(InstrumentKind.DOCREFERENCE);
                    if (hi !== null) {
                        let t1 = hi.beginToken;
                        if (t1.isValue("К", "ДО") && t1.next !== null) 
                            t1 = t1.next;
                        let dr = Utils.as(t1.getReferent(), DecreeReferent);
                        if (dr !== null && dr.number === res.m_Doc.regNumber) 
                            res.m_Doc.typ = dr.typ;
                        else {
                            let dt = DecreeToken.tryAttach(t1, null, false);
                            if (dt !== null && dt.typ === DecreeTokenItemType.TYP) 
                                res.m_Doc.typ = dt.value;
                        }
                    }
                    break;
                }
            }
        }
        res._createJusticeResolution();
        if (res.m_Doc.typ === null && ((res.m_Doc.regNumber !== null || res.m_Doc.caseNumber !== null))) {
            if ((res.children.length > 1 && res.children[1].kind === InstrumentKind.CONTENT && res.children[1].children.length > 0) && res.children[1].children[res.children[1].children.length - 1].kind === InstrumentKind.DOCPART) {
                let part = res.children[1].children[res.children[1].children.length - 1];
                for (const ch of part.children) {
                    if (ch.kind === InstrumentKind.DIRECTIVE && ch.value !== null) {
                        res.m_Doc.typ = Utils.asString(ch.value);
                        break;
                    }
                }
            }
        }
        return res;
    }
    
    static _createCaseInfo(t) {
        if (t === null) 
            return null;
        if (!t.isNewlineBefore) 
            return null;
        let rez = false;
        let t1 = null;
        if ((t instanceof ReferentToken) && (t.getReferent() instanceof DecreePartReferent)) {
            let dpr = Utils.as(t.getReferent(), DecreePartReferent);
            if (dpr.part === "резолютивная") 
                t1 = t;
        }
        else if (t.isValue("РЕЗОЛЮТИВНЫЙ", "РЕЗОЛЮТИВНЫЙ") && t.next !== null && t.next.isValue("ЧАСТЬ", "ЧАСТИНА")) 
            t1 = t.next;
        else if (t.isValue("ПОЛНЫЙ", "ПОВНИЙ") && t.next !== null && t.next.isValue("ТЕКСТ", null)) 
            t1 = t.next;
        if (t1 !== null) {
            rez = true;
            let dt = DecreeToken.tryAttach(t1.next, null, false);
            if (dt !== null && dt.typ === DecreeTokenItemType.TYP) 
                t1 = dt.endToken;
        }
        if (!rez) {
            if ((t.isValue("ПОСТАНОВЛЕНИЕ", "ПОСТАНОВА") || t.isValue("РЕШЕНИЕ", "РІШЕННЯ") || t.isValue("ОПРЕДЕЛЕНИЕ", "ВИЗНАЧЕННЯ")) || t.isValue("ПРИГОВОР", "ВИРОК")) {
                if (t.isNewlineAfter && t.chars.isAllUpper) 
                    return null;
                t1 = t;
            }
        }
        if (t1 === null) 
            return null;
        if (t1.next !== null && t1.next.morph._class.isPreposition) {
            let npt = NounPhraseHelper.tryParse(t1.next.next, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null) 
                t1 = npt.endToken;
        }
        if (t1.next !== null && t1.next.morph._class.isVerb) {
        }
        else 
            return null;
        let hasDate = false;
        for (let tt = t1.next; tt !== null; tt = tt.next) {
            if (MiscHelper.canBeStartOfSentence(tt)) 
                break;
            else {
                t1 = tt;
                if (t1.getReferent() instanceof DateReferent) 
                    hasDate = true;
            }
        }
        if ((!hasDate && t1.next !== null && (t1.next.getReferent() instanceof DateReferent)) && t1.next.isNewlineAfter) 
            t1 = t1.next;
        return FragToken._new2000(t, t1, InstrumentKind.CASEINFO);
    }
    
    static _createApproved(t) {
        const InstrToken = require("./InstrToken");
        if (t === null) 
            return null;
        let res = null;
        if (((t instanceof ReferentToken) && t.beginToken.isChar('(') && t.endToken.isChar(')')) && t.beginToken.next.isValue("ПРОТОКОЛ", null)) {
            res = FragToken._new2000(t, t, InstrumentKind.APPROVED);
            res.referents = new Array();
            res.referents.push(t.getReferent());
            return res;
        }
        let tt = InstrToken._checkApproved(t);
        if (tt !== null) 
            res = FragToken._new2000(t, tt, InstrumentKind.APPROVED);
        else if ((t.isValue("ОДОБРИТЬ", "СХВАЛИТИ") || t.isValue("ПРИНЯТЬ", "ПРИЙНЯТИ") || t.isValue("УТВЕРДИТЬ", "ЗАТВЕРДИТИ")) || t.isValue("СОГЛАСОВАТЬ", null)) {
            if (t.morph.containsAttr("инф.", null) && t.morph.containsAttr("сов.в.", null)) {
            }
            else 
                res = FragToken._new2000(t, t, InstrumentKind.APPROVED);
        }
        else if ((t instanceof TextToken) && ((t.term === "ИМЕНЕМ" || t.term === "ІМЕНЕМ"))) 
            res = FragToken._new2000(t, t, InstrumentKind.APPROVED);
        if (res === null) 
            return null;
        t = res.endToken;
        if (t.next === null) 
            return res;
        if (!t.isNewlineAfter && t.next.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false) === res.beginToken.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false)) {
            for (t = t.next; t !== null; t = t.next) {
                if (t.isNewlineBefore || t.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false) !== res.beginToken.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false)) 
                    break;
                else 
                    res.endToken = t;
            }
            if (t.next === null) 
                return res;
            let tt0 = t.next;
            for (t = t.next; t !== null; t = t.next) {
                let dtt = DecreeToken.tryAttach(t, null, false);
                if (dtt !== null) {
                    if (dtt.typ === DecreeTokenItemType.TYP && t !== tt0 && t.isNewlineBefore) 
                        break;
                    res.endToken = (t = dtt.endToken);
                    continue;
                }
                if (t.newlinesBeforeCount > 1) 
                    break;
                res.endToken = t;
            }
            return res;
        }
        for (t = t.next; t !== null; t = t.next) {
            if (t.isAnd || t.morph._class.isPreposition) 
                continue;
            if (t.isValue("ВВЕСТИ", null) || t.isValue("ДЕЙСТВИЕ", "ДІЯ")) {
                res.endToken = t;
                continue;
            }
            break;
        }
        while (t !== null) {
            if (t.isCharOf(":.,") || BracketHelper.isBracket(t, true)) 
                t = t.next;
            else 
                break;
        }
        if (t === null) 
            return res;
        let dts = DecreeToken.tryAttachList(t, null, 10, false);
        if (dts !== null && dts.length > 0) {
            for (let i = 0; i < dts.length; i++) {
                let dt = dts[i];
                if (dt.typ === DecreeTokenItemType.ORG) 
                    res.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.ORGANIZATION, dt));
                else if (dt.typ === DecreeTokenItemType.OWNER) 
                    res.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.INITIATOR, dt));
                else if (dt.typ === DecreeTokenItemType.DATE) 
                    res.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.DATE, dt));
                else if (dt.typ === DecreeTokenItemType.NUMBER && i > 0 && dts[i - 1].typ === DecreeTokenItemType.DATE) 
                    res.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.NUMBER, dt));
                else if (dt.typ === DecreeTokenItemType.TYP && i === 0) {
                    if (((i + 1) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.TERR) {
                        i++;
                        dt = dts[i];
                    }
                }
                else if (dt.typ === DecreeTokenItemType.TERR && res.beginToken.isValue("ИМЕНЕМ", "ІМЕНЕМ")) 
                    res.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.PLACE, dt));
                else 
                    break;
                res.endToken = dt.endToken;
            }
        }
        else if (t.getReferent() instanceof DecreeReferent) {
            res.referents = new Array();
            for (; t !== null; t = t.next) {
                if (t.isCommaAnd) 
                    continue;
                if (t.isChar('.')) {
                    res.endToken = t;
                    continue;
                }
                let dr = Utils.as(t.getReferent(), DecreeReferent);
                if (dr === null) 
                    break;
                if (res.referents.length > 0) {
                    if (t.newlinesBeforeCount > 3) 
                        break;
                    if (t.isNewlineBefore) {
                        let dt = DecreeToken.tryAttach(t.beginToken, null, false);
                        if (dt !== null && dt.typ === DecreeTokenItemType.TYP && dt.isNewlineAfter) 
                            break;
                    }
                }
                res.referents.push(dr);
                res.endToken = t;
            }
        }
        else if ((t.getReferent() instanceof PersonReferent) || (t.getReferent() instanceof PersonPropertyReferent)) {
            res.referents = new Array();
            for (; t !== null; t = t.next) {
                if (t.isCommaAnd) 
                    continue;
                if ((t.getReferent() instanceof PersonReferent) || (t.getReferent() instanceof PersonPropertyReferent)) {
                    res.referents.push(t.getReferent());
                    res.endToken = t;
                }
                else 
                    break;
            }
        }
        if (res.children.length === 0) {
            if (((!res.beginToken.isNewlineBefore && !res.beginToken.previous.isTableControlChar)) || ((!res.endToken.isNewlineAfter && !res.endToken.next.isTableControlChar))) 
                return null;
        }
        if (res.endToken.next !== null && (res.endToken.next.getReferent() instanceof DateReferent)) {
            let dt = DecreeToken.tryAttach(res.endToken.next, null, false);
            if (dt !== null) {
                res.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.DATE, dt));
                res.endToken = dt.endToken;
                dt = DecreeToken.tryAttach(res.endToken.next, null, false);
                if (dt !== null && dt.typ === DecreeTokenItemType.NUMBER) {
                    res.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.NUMBER, dt));
                    res.endToken = dt.endToken;
                }
            }
        }
        t = res.endToken.next;
        if (t !== null && t.isComma) 
            t = t.next;
        if (t !== null && t.isValue("ПРОТОКОЛ", null)) {
            dts = DecreeToken.tryAttachList(t, null, 10, false);
            if (dts !== null && dts.length > 0) 
                res.endToken = dts[dts.length - 1].endToken;
            else if (t.getReferent() instanceof DecreeReferent) 
                res.endToken = t;
        }
        if (!res.isNewlineBefore && res.beginToken.previous !== null && BracketHelper.canBeStartOfSequence(res.beginToken.previous, true, false)) 
            res.beginToken = res.beginToken.previous;
        return res;
    }
    
    static _createMisc(t) {
        const InstrToken1 = require("./InstrToken1");
        if (t === null || t.next === null) 
            return null;
        if (t.isValue("ФОРМА", null) && t.next.isValue("ДОКУМЕНТА", null)) {
            let num = DecreeToken.tryAttach(t.next.next, null, false);
            if (num !== null && num.typ === DecreeTokenItemType.NUMBER) 
                return FragToken._new2000(t, num.endToken, InstrumentKind.UNDEFINED);
            if ((t.next.next instanceof NumberToken) && t.next.next.isNewlineAfter) 
                return FragToken._new2000(t, t.next.next, InstrumentKind.UNDEFINED);
        }
        let npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
        if (npt !== null) {
            if (npt.endToken.isValue("ОБРАЗЕЦ", null) && ((t.chars.isAllLower || npt.isNewlineAfter))) 
                return new FragToken(t, npt.endToken);
        }
        if (t.isChar('(')) {
            npt = NounPhraseHelper.tryParse(t.next, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null && npt.endToken.next !== null && npt.endToken.next.isChar(')')) 
                return FragToken._new2000(t, npt.endToken.next, InstrumentKind.UNDEFINED);
        }
        if ((t instanceof NumberToken) && t.next !== null && t.next.isValue("СЕССИЯ", null)) 
            return FragToken._new2000(t, t.next, InstrumentKind.UNDEFINED);
        if (t.isValue("С", null) && t.next.isValue("ИЗМЕНЕНИЕ", null) && t.next.next !== null) {
            let tt = t.next.next;
            if (tt.morph._class.isPreposition && tt.next !== null) 
                tt = tt.next;
            if (tt.getReferent() instanceof DateReferent) {
                if (tt.next !== null && tt.next.isChar('.')) 
                    tt = tt.next;
                return FragToken._new2000(t, tt, InstrumentKind.UNDEFINED);
            }
        }
        let t0 = t;
        while ((t instanceof TextToken) && t.lengthChar === 1 && t.next !== null) {
            let tt = MiscHelper.checkNumberPrefix(t);
            if (tt !== null) 
                return null;
            t = t.next;
        }
        for (; t !== null; t = t.next) {
            if (t.isChar('|')) {
            }
            else 
                break;
        }
        if (t === null) 
            return null;
        if (t.isValue3("МЕСТО", "ДЛЯ", "QR")) {
            for (let tt = t.next.next; tt !== null; tt = tt.next) {
                if (tt.isNewlineAfter) 
                    return new FragToken(t0, tt);
            }
        }
        if (t.isValue("ЗАКАЗ", null)) {
            let itt = InstrToken1.parse(t, false, null, 0, null, false, 0, false, false);
            if (itt !== null) 
                return FragToken._new2000(t, itt.endToken, InstrumentKind.UNDEFINED);
        }
        let nums = 0;
        let spec = 0;
        let _chars = 0;
        let words = 0;
        for (let t1 = t0; t1 !== null; t1 = t1.next) {
            let ddd = DecreeToken.tryAttach(t1, null, false);
            if (ddd !== null) 
                break;
            if (t1.isTableControlChar) {
            }
            else if (t1 instanceof NumberToken) 
                nums++;
            else if (!(t1 instanceof TextToken) || t1.lengthChar > 7) 
                break;
            else if (!t1.chars.isLetter) 
                spec++;
            else if (t1.lengthChar < 3) 
                _chars++;
            else if (t1.getMorphClassInDictionary().isUndefined) 
                _chars++;
            else 
                words++;
            if (!t1.isNewlineAfter) 
                continue;
            if ((nums + spec + _chars) <= 1) 
                break;
            if ((nums + spec + _chars) > (words * 3)) {
            }
            else if ((words < 2) && (nums + spec + _chars) > 3) {
            }
            else 
                break;
            return FragToken._new2000(t0, t1, InstrumentKind.UNDEFINED);
        }
        if (t.getReferent() instanceof StreetReferent) {
            let lin = InstrToken1.parse(t0, true, null, 0, null, false, 0, false, false);
            if (lin !== null && (lin.lengthChar < 70)) 
                return FragToken._new2000(t0, lin.endToken, InstrumentKind.CONTACT);
        }
        if (t0.isChar('(')) {
            let br = BracketHelper.tryParse(t0, BracketParseAttr.NO, 100);
            if (br !== null && br.isNewlineAfter) 
                return FragToken._new2000(t0, br.endToken, InstrumentKind.UNDEFINED);
        }
        if (t0.previous !== null && t0.previous.isTableControlChar) {
            let rows = TableHelper.tryParseRows(t0.previous, 0, false, false);
            if (rows !== null && (rows.length < 30) && rows.length > 3) {
                let tt = rows[rows.length - 1].endToken.next;
                if (tt !== null && tt.isNewlineBefore) {
                    let dt = DecreeToken.tryAttach(tt, null, false);
                    if (dt !== null && dt.typ === DecreeTokenItemType.TYP) 
                        return FragToken._new2000(t0.previous, tt.previous, InstrumentKind.UNDEFINED);
                }
            }
        }
        if (t.isNewlineBefore && (t.getReferent() instanceof DecreePartReferent) && t.next !== null) {
            if (t.next.isValue2("ВВЕСТИ", "В")) {
                let npt1 = NounPhraseHelper.tryParse(t.next.next, NounPhraseParseAttr.PARSEPREPOSITION, 0, null);
                if (npt1 !== null && npt1.endToken.next !== null) {
                    if (npt1.endToken.next.isValue2("ОТДЕЛЬНЫЙ", "ДОКУМЕНТ")) 
                        return FragToken._new2000(t, npt1.endToken.next.next, InstrumentKind.UNDEFINED);
                }
            }
        }
        return null;
    }
    
    static _createEditions(t) {
        if (t === null || t.next === null) 
            return null;
        let t0 = t;
        let isInBracks = false;
        let isInFig = false;
        let ok = false;
        if ((t.isNewlineBefore && t.isValue("С", null) && t.next !== null) && t.next.isValue("ИЗМЕНЕНИЕ", null)) {
            let eee = FragToken._new2000(t, t, InstrumentKind.EDITIONS);
            for (t = t.next.next; t !== null; t = t.next) {
                if (t.isCommaAnd || (t.getReferent() instanceof DateReferent)) 
                    eee.endToken = t;
                else if (t.isValue("ДОПОЛНЕНИЕ", null) || t.isCharOf(":;.") || t.isValue("ОТ", null)) 
                    eee.endToken = t;
                else {
                    let dd = DateItemToken.tryParse(t, null, false);
                    if (dd !== null) 
                        eee.endToken = (t = dd.endToken);
                    else 
                        break;
                }
            }
            return eee;
        }
        if (t.isValue("СПИСОК", null)) {
            let npt = NounPhraseHelper.tryParse(t.next, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null && npt.noun.isValue("ДОКУМЕНТ", null)) {
                t = npt.endToken.next;
                if (t !== null && t.isCharOf(":.")) 
                    t = t.next;
                if (t === null) 
                    return null;
            }
        }
        if (!t.isChar('(') && !t.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК")) {
            if (t.isValue("В", "У") && t.next !== null && ((t.next.isValue("РЕДАКЦИЯ", "РЕДАКЦІЯ") || t.next.isValue("РЕД", null)))) {
            }
            else if (t.isValue("РЕДАКЦИЯ", "РЕДАКЦІЯ")) {
                let dtt0 = DecreeToken.tryAttach(t.next, null, false);
                if (dtt0 !== null) 
                    return FragToken._new2000(t, dtt0.endToken, InstrumentKind.EDITIONS);
            }
            else if (t.isChar('{') && t.isNewlineBefore) 
                isInFig = true;
            else 
                return null;
        }
        else {
            isInBracks = t.isChar('(');
            t = t.next;
        }
        let dt = DecreeToken.tryAttach(t, null, false);
        if (dt !== null && ((dt.typ === DecreeTokenItemType.NUMBER || dt.typ === DecreeTokenItemType.DATE))) 
            t = dt.endToken.next;
        else if (t instanceof NumberToken) 
            t = t.next;
        let pt = PartToken.tryAttach(t, null, false, true);
        if (pt !== null) 
            t = pt.endToken.next;
        else if (isInBracks && t !== null && (t.getReferent() instanceof DecreePartReferent)) 
            t = t.next;
        if (t === null) 
            return null;
        let isDoubt = false;
        while (((t.morph._class.isPreposition || t.morph._class.isAdverb)) && t.next !== null) {
            t = t.next;
        }
        if (t.isValue("РЕДАКЦИЯ", "РЕДАКЦІЯ")) 
            ok = true;
        else if (t.isValue("ОТФОРМАТИРОВАН", null) || t.isValue("ДОПОЛНЕН", null) || t.isValue("ДОПОЛНЕНИЕ", null)) 
            ok = true;
        else if (t.isValue("РЕД", null)) {
            ok = true;
            if (t.next !== null && t.next.isChar('.')) 
                t = t.next;
        }
        else if (((t.isValue("ИЗМ", null) || t.isValue("ИЗМЕНЕНИЕ", "ЗМІНА") || t.isValue("УЧЕТ", "ОБЛІК")) || t.isValue("ВКЛЮЧИТЬ", "ВКЛЮЧИТИ") || t.isValue("ДОПОЛНИТЬ", "ДОПОВНИТИ")) || t.isValue("ВВЕСТИ", null)) {
            if (t.isValue("УЧЕТ", "ОБЛІК")) 
                isDoubt = true;
            ok = true;
            for (t = t.next; t !== null; t = t.next) {
                if (t.next === null) 
                    break;
                if (t.isCharOf(",.")) 
                    continue;
                if (t.isValue("ВНЕСЕННЫЙ", "ВНЕСЕНИЙ") || t.isValue("ПОПРАВКА", null)) 
                    continue;
                t = t.previous;
                break;
            }
        }
        else if (t.getReferent() instanceof DecreeReferent) {
            let tt = t.beginToken;
            if (tt.isValue("В", "У") && tt.next !== null) 
                tt = tt.next;
            if (tt.isValue("РЕДАКЦИЯ", "РЕДАКЦІЯ")) 
                ok = true;
            else if (tt.isValue("РЕД", null)) 
                ok = true;
            t = t.previous;
        }
        if (t === null) 
            return null;
        if (!ok && !isInFig) 
            return null;
        let decrs = new Array();
        for (t = t.next; t !== null; t = t.next) {
            if (isInBracks) {
                if (t.isChar('(')) {
                    let br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                    if (br !== null && (br.lengthChar < 200)) {
                        t = br.endToken;
                        continue;
                    }
                }
                if (t.isChar(')')) 
                    break;
            }
            if (isInFig && t.isChar('}') && t.isNewlineAfter) 
                break;
            let dr = Utils.as(t.getReferent(), DecreeReferent);
            if (dr !== null) {
                decrs.push(dr);
                continue;
            }
            if (t.isCommaAnd) 
                continue;
            if (t.isNewlineBefore && ((!isInBracks || isDoubt))) {
                t = t.previous;
                break;
            }
        }
        if (t === null) 
            return null;
        ok = false;
        if (isInBracks) {
            ok = t.isChar(')');
            if (!t.isNewlineAfter) {
                if ((t.next instanceof TextToken) && t.next.isNewlineAfter && !t.next.chars.isLetter) {
                }
                else 
                    isDoubt = true;
            }
        }
        else if (isInFig && t.isChar('}')) 
            ok = true;
        else if (t.isChar('.') || t.isNewlineAfter) 
            ok = true;
        if (decrs.length > 0) 
            isDoubt = false;
        if (ok && !isDoubt) {
            let eds = FragToken._new2000(t0, t, InstrumentKind.EDITIONS);
            eds.referents = new Array();
            for (const d of decrs) {
                eds.referents.push(d);
            }
            return eds;
        }
        return null;
    }
    
    static _createOwner(t) {
        if (t === null || !t.isNewlineBefore) 
            return null;
        if (!t.chars.isCyrillicLetter || t.chars.isAllLower) 
            return null;
        let t1 = null;
        let t11 = null;
        let ignoreCurLine = false;
        let keyword = false;
        for (let tt = t; tt !== null; tt = tt.next) {
            if (tt.isNewlineBefore) 
                t11 = t1;
            let r = tt.getReferent();
            if ((r instanceof DecreeReferent) && keyword) {
                tt = tt.kit.debedToken(tt);
                r = tt.getReferent();
            }
            let dt = DecreeToken.tryAttach(tt, null, false);
            if (dt !== null) {
                if ((dt.typ !== DecreeTokenItemType.OWNER && dt.typ !== DecreeTokenItemType.ORG && dt.typ !== DecreeTokenItemType.UNKNOWN) && dt.typ !== DecreeTokenItemType.TERR && dt.typ !== DecreeTokenItemType.MISC) 
                    break;
                t1 = (tt = dt.endToken);
                continue;
            }
            if (tt !== t && tt.whitespacesBeforeCount > 15) {
                if (tt.previous !== null && tt.previous.isHiphen) {
                }
                else 
                    break;
            }
            if (((((r instanceof DateReferent) || (r instanceof AddressReferent) || (r instanceof StreetReferent)) || (r instanceof PhoneReferent) || (r instanceof UriReferent)) || (r instanceof PersonIdentityReferent) || (r instanceof BankDataReferent)) || (r instanceof DecreePartReferent) || (r instanceof DecreeReferent)) {
                ignoreCurLine = true;
                t1 = t11;
                break;
            }
            if (tt.morph._class.equals(MorphClass.VERB)) {
                ignoreCurLine = true;
                t1 = t11;
                break;
            }
            if ((r instanceof GeoReferent) && tt.isNewlineBefore) 
                break;
            t1 = tt;
            let oo = tt.kit.processReferent("ORGANIZATION", tt, null);
            if (oo !== null) {
                t1 = (tt = oo.endToken);
                continue;
            }
            let npt = NounPhraseHelper.tryParse(tt, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null) {
                if (tt === t) {
                    let typ = OrgItemTypeToken.tryAttach(tt, false);
                    if (typ !== null) {
                        keyword = true;
                        t1 = (tt = typ.endToken);
                        continue;
                    }
                }
                t1 = (tt = npt.endToken);
            }
        }
        if (t1 === null) 
            return null;
        let fr = FragToken._new2026(t, t1, InstrumentKind.ORGANIZATION, true);
        return fr;
    }
    
    calcOwnerCoef(owner) {
        let ownTyps = new Array();
        let ownName = null;
        for (const ch of owner.children) {
            if (ch.kind === InstrumentKind.HEAD) {
                for (const chh of ch.children) {
                    if (chh.kind === InstrumentKind.TYP || chh.kind === InstrumentKind.NAME || chh.kind === InstrumentKind.KEYWORD) {
                        let t = DecreeToken.isKeyword(chh.beginToken, false);
                        if (t instanceof TextToken) 
                            ownTyps.push(t.lemma);
                        if (chh.kind === InstrumentKind.NAME && ownName === null) 
                            ownName = chh;
                    }
                }
            }
        }
        for (const ch of this.children) {
            if (ch.kind === InstrumentKind.HEAD) {
                for (const chh of ch.children) {
                    if (chh.kind === InstrumentKind.DOCREFERENCE) {
                        let t = chh.beginToken;
                        if (t.morph._class.isPreposition) 
                            t = t.next;
                        let tt = DecreeToken.isKeyword(t, false);
                        if (tt instanceof TextToken) {
                            let ty = tt.lemma;
                            if (ownTyps.includes(ty)) 
                                return 1;
                            continue;
                        }
                        let pt = PartToken.tryAttach(t, null, false, false);
                        if (pt !== null) {
                            if (pt.typ === PartTokenItemType.APPENDIX) {
                                if (owner.number > 0) {
                                    for (const nn of pt.values) {
                                        if (nn.value === owner.number.toString()) 
                                            return 3;
                                    }
                                }
                            }
                        }
                        if (ownName !== null && ((typeof ownName.value === 'string' || ownName.value instanceof String))) {
                            let val0 = Utils.asString(ownName.value);
                            let val1 = MiscHelper.getTextValue(t, chh.endToken, GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
                            if (val1 === val0) 
                                return 3;
                            if (MiscHelper.canBeEquals(val0, val1, true, true, false)) 
                                return 3;
                            if (val1 !== null && ((val1.startsWith(val0) || val0.startsWith(val1)))) 
                                return 1;
                        }
                    }
                }
            }
        }
        return 0;
    }
    
    get hasChanges() {
        if (this.beginToken.getReferent() instanceof DecreeChangeReferent) 
            return true;
        for (let t = this.beginToken; t !== null && t.endChar <= this.endChar; t = t.next) {
            if (t.getReferent() instanceof DecreeChangeReferent) 
                return true;
        }
        return false;
    }
    
    get multilineChangesValue() {
        for (let t = this.beginToken; t !== null && (t.beginChar < this.endChar); t = t.next) {
            if (t.getReferent() instanceof DecreeChangeReferent) {
                let dcr = Utils.as(t.getReferent(), DecreeChangeReferent);
                for (let tt = t.beginToken; tt !== null && tt.endChar <= t.endChar; tt = tt.next) {
                    let dval = Utils.as(tt.getReferent(), DecreeChangeValueReferent);
                    if (dval === null || dval.kind !== DecreeChangeValueKind.TEXT) 
                        continue;
                    let val = dval.value;
                    if (val === null || (val.length < 100)) 
                        continue;
                    if ((val.indexOf('\r') < 0) && (val.indexOf('\n') < 0) && !tt.isNewlineBefore) 
                        continue;
                    let t0 = null;
                    for (t = tt.beginToken; t !== null && t.endChar <= tt.endChar; t = t.next) {
                        if (BracketHelper.isBracket(t, true) && ((t.isWhitespaceBefore || t.previous.isChar(':')))) {
                            t0 = t.next;
                            break;
                        }
                        else if (t.previous !== null && t.previous.isChar(':') && t.isNewlineBefore) {
                            t0 = t;
                            break;
                        }
                    }
                    let t1 = tt.endToken;
                    if (BracketHelper.isBracket(t1, true)) 
                        t1 = t1.previous;
                    if (t0 !== null && ((t0.endChar + 50) < t1.endChar)) 
                        return MetaToken._new663(t0, t1, dcr);
                    return null;
                }
            }
            if (t.endChar > this.endChar) 
                break;
        }
        return null;
    }
    
    _calcTailNumber() {
        if (this.kind === InstrumentKind.NUMBER || this.kind === InstrumentKind.NAME) 
            return null;
        let t = this.endToken;
        if (t.isComma) 
            t = t.previous;
        if (t === null || !t.isCharOf(")]")) 
            return null;
        let hasNum = false;
        for (let tt = t.previous; tt !== null && tt.beginChar >= this.beginChar; tt = tt.previous) {
            if (tt.isCharOf("([")) 
                return (hasNum ? MiscHelper.getTextValue(tt.next, t.previous, GetTextAttr.NO) : null);
            if (tt instanceof NumberToken) {
                hasNum = true;
                continue;
            }
            if (tt.lengthChar > 1) 
                break;
        }
        return null;
    }
    
    addChild(ch, addFillContent) {
        if (this.children.length === 0) {
            if (addFillContent && (this.beginChar < ch.beginChar)) 
                this.children.push(FragToken._new2000(this.beginToken, ch.beginToken.previous, InstrumentKind.CONTENT));
            this.children.push(ch);
            return;
        }
        for (let i = 0; i < this.children.length; i++) {
            if (ch.endChar <= this.children[i].beginChar) {
                this.children.splice(i, 0, ch);
                if (addFillContent) {
                    if (i > 0 && (this.children[i - 1].endToken.next.beginChar < ch.beginToken.previous.endChar)) 
                        this.children.splice(i, 0, FragToken._new2000(this.children[i - 1].endToken.next, ch.beginToken.previous, InstrumentKind.CONTENT));
                    else if (i === 0 && (this.beginChar < ch.beginChar)) 
                        this.children.splice(0, 0, FragToken._new2000(this.beginToken, ch.beginToken.previous, InstrumentKind.CONTENT));
                }
                return;
            }
        }
        this.children.push(ch);
    }
    
    _analizeTables() {
        const InstrToken1 = require("./InstrToken1");
        const ContentAnalyzeWhapper = require("./ContentAnalyzeWhapper");
        if (this.children.length > 0) {
            let abzCount = 0;
            let cou = 0;
            for (const ch of this.children) {
                if (ch.kind === InstrumentKind.INDENTION) 
                    abzCount++;
                if ((ch.kind !== InstrumentKind.KEYWORD && ch.kind !== InstrumentKind.NUMBER && ch.kind !== InstrumentKind.NUMBER) && ch.kind !== InstrumentKind.EDITIONS && ch.kind !== InstrumentKind.COMMENT) 
                    cou++;
            }
            if (abzCount === cou && cou > 0) {
                let chs = this.children;
                this.children = new Array();
                let bb = this._analizeTables();
                this.children = chs;
                if (bb) {
                    for (let i = 0; i < this.children.length; i++) {
                        if (this.children[i].kind === InstrumentKind.INDENTION) {
                            let ch0 = (i > 0 ? this.children[i - 1] : null);
                            if (ch0 !== null && ch0.kind === InstrumentKind.CONTENT) {
                                ch0.endToken = this.children[i].endToken;
                                this.children.splice(i, 1);
                                i--;
                            }
                            else 
                                this.children[i].kind = InstrumentKind.CONTENT;
                        }
                    }
                }
            }
            let changed = new Array();
            for (const ch of this.children) {
                if (ch._analizeTables()) 
                    changed.push(ch);
            }
            for (let i = changed.length - 1; i >= 0; i--) {
                if (changed[i].kind === InstrumentKind.CONTENT) {
                    let j = this.children.indexOf(changed[i]);
                    if (j < 0) 
                        continue;
                    this.children.splice(j, 1);
                    this.children.splice(j, 0, ...changed[i].children);
                }
            }
            let empty = true;
            for (const ch of this.children) {
                if ((ch.kind === InstrumentKind.NOTICE || ch.kind === InstrumentKind.FOOTNOTE || ch.kind === InstrumentKind.EDITIONS) || ch.kind === InstrumentKind.COMMENT) {
                }
                else 
                    empty = false;
            }
            if (!empty) 
                return false;
        }
        if (((this.kind === InstrumentKind.CHAPTER || this.kind === InstrumentKind.CLAUSE || this.kind === InstrumentKind.CONTENT) || this.kind === InstrumentKind.ITEM || this.kind === InstrumentKind.SUBITEM) || this.kind === InstrumentKind.INDENTION) {
        }
        else 
            return false;
        if (this.itok !== null && this.itok.hasChanges && !this.itok.beginToken.isTableControlChar) 
            return false;
        let _endChar = this.endChar;
        if (this.endToken.next === null) 
            _endChar = this.kit.sofa.text.length - 1;
        let t0 = this.beginToken;
        let tabs = false;
        let head = new Array();
        for (let tt = this.beginToken; tt !== null && tt.endChar <= _endChar; tt = tt.next) {
            if (!tt.isNewlineBefore) {
                if (tt.previous !== null && tt.previous.isChar(String.fromCharCode(0x1F))) {
                }
                else 
                    continue;
            }
            if (tt.isChar(String.fromCharCode(0x1E))) {
            }
            let rows = TableHelper.tryParseRows(tt, _endChar, false, false);
            if (rows === null || (rows.length < 2)) {
                let _itok = InstrToken1.parse(tt, true, null, 0, null, false, 0, false, false);
                if (_itok !== null) {
                    if (_itok.typ === InstrToken1Types.TABLE) {
                        head.splice(0, head.length);
                        head.push(_itok);
                    }
                    else if (head.length > 0) {
                        if (_itok.numbers.length > 0 || _itok.typ !== InstrToken1Types.LINE) 
                            head.splice(0, head.length);
                        else 
                            head.push(_itok);
                    }
                    tt = _itok.endToken;
                    continue;
                }
            }
            let ok = true;
            for (const r of rows) {
                if (r.cells.length > 35) 
                    ok = false;
            }
            if (!ok) {
                tt = rows[rows.length - 1].endToken;
                continue;
            }
            let tab = FragToken._new2000(rows[0].beginToken, rows[rows.length - 1].endToken, InstrumentKind.TABLE);
            if (head.length > 0) {
                tab.beginToken = head[0].beginToken;
                NumberingHelper.createNumber(tab, head[0]);
                let t00 = head[0].beginToken.next.next;
                if (head[0].numEndToken !== head[0].endToken && head[0].numEndToken !== null) 
                    t00 = head[0].numEndToken.next;
                if (t00 !== null && t00.endChar <= head[0].endChar) {
                    let frName = FragToken._new2005(t00, head[0].endToken, InstrumentKind.NAME, true, head[0]);
                    tab.children.push(frName);
                    tab.name = FragToken.getRestoredNameMT(frName, false);
                    let ii = ContentAnalyzeWhapper.correctName(tab, frName, head, 0);
                }
            }
            this.addChild(tab, true);
            for (let i = 0; i < rows.length; i++) {
                let rr = FragToken._new2024(rows[i].beginToken, rows[i].endToken, InstrumentKind.TABLEROW, i + 1);
                tab.children.push(rr);
                tabs = true;
                let no = 0;
                let cols = 0;
                for (const ce of rows[i].cells) {
                    let cell = FragToken._new2024(ce.beginToken, ce.endToken, InstrumentKind.TABLECELL, ++no);
                    if (ce.colSpan > 1) 
                        cols += (((cell.subNumber = ce.colSpan)));
                    else 
                        cols++;
                    if (ce.rowSpan > 1) 
                        cell.subNumber2 = ce.rowSpan;
                    rr.children.push(cell);
                }
                if (tab.tableColumns < cols) 
                    tab.tableColumns = cols;
                tt = rows[i].endToken;
            }
            if (tab.tableColumns > 1) {
                let rnums = new Int32Array(tab.tableColumns);
                let rnumsCols = new Int32Array(tab.tableColumns);
                for (const r of tab.children) {
                    let no = 0;
                    for (let ii = 0; ii < r.children.length; ii++) {
                        if ((no < rnums.length) && rnums[no] > 0) {
                            rnums[no]--;
                            no += rnumsCols[no];
                            ii--;
                            continue;
                        }
                        r.children[ii].number = no + 1;
                        if (r.children[ii].subNumber2 > 1 && (no < rnums.length)) {
                            rnums[no] = r.children[ii].subNumber2 - 1;
                            rnumsCols[no] = (r.children[ii].subNumber === 0 ? 1 : r.children[ii].subNumber);
                        }
                        no += (r.children[ii].subNumber === 0 ? 1 : r.children[ii].subNumber);
                    }
                }
            }
            t0 = tt.next;
        }
        if ((t0 !== null && (t0.endChar < this.endChar) && tabs) && t0 !== this.endToken) {
            if (this.children.length > 0 && (t0.endChar < this.children[this.children.length - 1].endChar)) {
            }
            else 
                this.addChild(FragToken._new2000(t0, this.endToken, InstrumentKind.CONTENT), false);
        }
        return tabs;
    }
    
    static createDocTitle(t0, doc) {
        const InstrToken1 = require("./InstrToken1");
        if (t0 === null) 
            return null;
        if (t0.isValue3("ДАННЫЕ", "ЭЛЕКТРОННОЙ", "ПОДПИСИ")) {
            let cou = 0;
            for (let tt = t0; tt !== null; tt = tt.next) {
                t0 = tt;
                let line = InstrToken1.parse(tt, true, null, 0, null, false, 0, false, false);
                if (line === null) 
                    continue;
                if (tt.getReferent() instanceof DecreeReferent) {
                    t0 = tt.kit.debedToken(tt);
                    break;
                }
                let dt = DecreeToken.tryAttach(tt, null, false);
                if (dt !== null && dt.typ === DecreeTokenItemType.TYP) 
                    break;
                if ((((tt.isValue("ДАННЫЕ", null) || tt.isValue("ДОКУМЕНТ", null) || tt.isValue("ВЛАДЕЛЕЦ", null)) || tt.isValue("ОРГАНИЗАЦИЯ", null) || tt.isValue("ПОДПИСАНО", null)) || tt.isValue2("СЕРИЙНЫЙ", "НОМЕР") || tt.isValue2("СРОК", "ДЕЙСТВИЯ")) || tt.isChar('(')) 
                    cou = 0;
                else {
                    cou++;
                    if (cou > 3) 
                        break;
                }
                tt = line.endToken;
            }
        }
        let title = FragToken.createContractTitle(t0, doc);
        if (title !== null) 
            return title;
        title = FragToken.createGostTitle(t0, doc);
        if (title !== null) 
            return title;
        title = FragToken.createZapiskaTitle(t0, doc);
        if (title !== null) 
            return title;
        title = FragToken.createTZTitle(t0, doc);
        if (title !== null) 
            return title;
        doc.slots.splice(0, doc.slots.length);
        title = FragToken.createProjectTitle(t0, doc);
        if (title !== null) 
            return title;
        doc.slots.splice(0, doc.slots.length);
        title = FragToken._createDocTitle_(t0, doc);
        if (title !== null && title.children.length === 1 && title.children[0].kind === InstrumentKind.NAME) {
            let title2 = FragToken._createDocTitle_(title.endToken.next, doc);
            if (title2 !== null && doc.typ !== null) {
                title.children.splice(title.children.length, 0, ...title2.children);
                title.endToken = title2.endToken;
            }
        }
        if ((title !== null && title.children.length >= 1 && title.children[0].kind === InstrumentKind.NAME) && doc.typ === null) {
            for (let t = title.endToken.next; t !== null; t = t.next) {
                if (t.isValue("ПРИКАЗЫВАТЬ", null) && t.next !== null && t.next.isChar(':')) {
                    doc.typ = "ПРИКАЗ";
                    break;
                }
            }
        }
        return title;
    }
    
    static _createDocTitle_(t0, doc) {
        const InstrToken = require("./InstrToken");
        const InstrToken1 = require("./InstrToken1");
        for (; t0 !== null; t0 = t0.next) {
            if (!t0.isTableControlChar) 
                break;
        }
        if (t0 === null) 
            return null;
        if (FragToken._isStartOfBody(t0, false)) 
            return null;
        let title = FragToken._new2000(t0, t0, InstrumentKind.HEAD);
        let dt0 = null;
        let t = null;
        let t1 = null;
        let _name = null;
        let nT0 = null;
        let emptyLines = 0;
        let endEmptyLines = null;
        let ignoreEmptyLines = false;
        let attrs = 0;
        let canBeOrgs = true;
        let unknownOrgs = new Array();
        let isContract = false;
        let startOfName = false;
        t = t0;
        if (t0.getReferent() !== null) {
            if (t0.getReferent().typeName === "PERSON") 
                return null;
        }
        let appr0 = null;
        if (t0.isValue("УТВЕРДИТЬ", "ЗАТВЕРДИТИ") || t0.isValue("ПРИНЯТЬ", "ПРИЙНЯТИ") || t0.isValue("УТВЕРЖДАТЬ", null)) 
            appr0 = FragToken._createApproved(t);
        if (appr0 !== null) {
            t1 = title.endToken = appr0.endToken;
            title.children.push(appr0);
            t = t1.next;
        }
        let edi0 = null;
        if (t0.isValue("РЕДАКЦИЯ", null)) 
            edi0 = FragToken._createEditions(t0);
        if (edi0 !== null) {
            t1 = title.endToken = edi0.endToken;
            title.children.push(edi0);
            t = t1.next;
        }
        if (t !== null && t.isValue("ДЕЛО", "СПРАВА")) {
            let dt = DecreeToken.tryAttach(t.next, null, false);
            if (dt !== null && dt.typ === DecreeTokenItemType.NUMBER) {
                dt.beginToken = t;
                title.children.push(FragToken._new2064(t, t, InstrumentKind.KEYWORD, "ДЕЛО"));
                FragToken._addTitleAttr(doc, title, dt);
                t = dt.endToken.next;
                if (t !== null && t.isValue("КОПИЯ", "КОПІЯ")) 
                    t = t.next;
                else if ((t.isChar('(') && t.next !== null && t.next.isValue("КОПИЯ", "КОПІЯ")) && t.next.next !== null && t.next.next.isChar(')')) 
                    t = t.next.next;
            }
        }
        for (; t !== null; t = t.next) {
            if (t.isTableControlChar) 
                continue;
            let tt2 = MiscHelper.checkImage(t);
            if (tt2 !== null) {
                t = tt2;
                continue;
            }
            if (t.isNewlineBefore || ((t.previous !== null && t.previous.isTableControlChar))) {
                if ((t.getReferent() instanceof DecreeReferent) && t.getReferent().kind !== DecreeKind.PUBLISHER) 
                    t = t.kit.debedToken(t);
                if (t.isValue("О", "ПРО") || t.isValue("ОБ", null) || t.isValue("ПО", null)) 
                    break;
                if (FragToken._isStartOfBody(t, false)) 
                    break;
                if (t.isCharOf("[") && _name === null) 
                    break;
                let iii = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
                if (iii !== null && iii.typ === InstrToken1Types.COMMENT) {
                    let cmt = FragToken._new2000(iii.beginToken, iii.endToken, InstrumentKind.COMMENT);
                    title.children.push(cmt);
                    t = (t1 = title.endToken = iii.endToken);
                    continue;
                }
                if (iii !== null && iii.endToken.isChar('?')) {
                    let cmt = FragToken._new2000(iii.beginToken, iii.endToken, InstrumentKind.NAME);
                    cmt.value = FragToken.getRestoredNameMT(iii, false);
                    title.children.push(cmt);
                    t = (t1 = title.endToken = iii.endToken);
                    break;
                }
                if ((((t.isValue("ЗАЯВИТЕЛЬ", "ЗАЯВНИК") || t.isValue("ИСТЕЦ", "ПОЗИВАЧ") || t.isValue("ОТВЕТЧИК", "ВІДПОВІДАЧ")) || t.isValue("ДОЛЖНИК", "БОРЖНИК") || t.isValue("КОПИЯ", "КОПІЯ"))) && t.next !== null && ((t.next.isChar(':') || t.next.isTableControlChar))) {
                    let ptt = FragToken._createJustParticipant(t.next.next, null);
                    if (ptt !== null) {
                        if (t.isValue("КОПИЯ", null)) {
                        }
                        t1 = ptt.endToken;
                        while (t1.next !== null && t1.next.isTableControlChar) {
                            t1 = t1.next;
                        }
                        if (t1.next !== null && t1.next.isChar('(')) {
                            let br = BracketHelper.tryParse(t1.next, BracketParseAttr.NO, 100);
                            if (br !== null) 
                                t1 = br.endToken;
                        }
                        let ft = FragToken._new2000(t, t1, InstrumentKind.INITIATOR);
                        title.children.push(ft);
                        t = title.endToken = t1;
                        continue;
                    }
                }
                if (t.isValue("ЦЕНА", "ЦІНА") && t.next !== null && t.next.isValue("ИСК", "ПОЗОВ")) {
                    let hasMoney = false;
                    let tt = null;
                    for (tt = t.next; tt !== null; tt = tt.next) {
                        if (tt.getReferent() instanceof MoneyReferent) 
                            hasMoney = true;
                        if (tt.isNewlineAfter) 
                            break;
                    }
                    if (tt !== null && hasMoney) {
                        while (tt.next !== null && tt.next.isTableControlChar) {
                            tt = tt.next;
                        }
                        if (tt.next !== null && tt.next.isChar('(')) {
                            let br = BracketHelper.tryParse(tt.next, BracketParseAttr.NO, 100);
                            if (br !== null) 
                                tt = br.endToken;
                        }
                        title.children.push(FragToken._new2000(t, tt, InstrumentKind.CASEINFO));
                        t = title.endToken = (t1 = tt);
                        continue;
                    }
                }
                if (t.isValue("В", "У")) {
                    let tt = t.next;
                    if (tt !== null && tt.isTableControlChar) 
                        tt = tt.next;
                    if (tt !== null && (tt.getReferent() instanceof OrganizationReferent)) {
                        let r = tt.getReferent();
                        while (tt.next !== null && tt.next.isTableControlChar) {
                            tt = tt.next;
                        }
                        t1 = tt;
                        if (t1.next !== null && t1.next.isChar('(')) {
                            let br = BracketHelper.tryParse(t1.next, BracketParseAttr.NO, 100);
                            if (br !== null) 
                                t1 = br.endToken;
                        }
                        let ooo = FragToken._new2000(t, t1, InstrumentKind.ORGANIZATION);
                        ooo.referents = new Array();
                        ooo.referents.push(r);
                        title.children.push(ooo);
                        t = title.endToken = t1;
                        continue;
                    }
                }
                if (t.lengthChar === 1 && t.chars.isLetter && t.isWhitespaceAfter) {
                    let ii = 0;
                    for (ii = 0; ii < InstrToken.m_DirectivesNorm.length; ii++) {
                        let ee = MiscHelper.tryAttachWordByLetters(InstrToken.m_DirectivesNorm[ii], t, false);
                        if (ee !== null && ee.isNewlineAfter) {
                            let ooo = FragToken._new2064(t, ee, InstrumentKind.KEYWORD, InstrToken.m_DirectivesNorm[ii]);
                            title.children.push(ooo);
                            doc.typ = InstrToken.m_DirectivesNorm[ii];
                            t = title.endToken = ee;
                            break;
                        }
                    }
                    if (ii < InstrToken.m_DirectivesNorm.length) 
                        continue;
                }
            }
            if (t.isHiphen || t.isChar('_')) {
                let ch = t.getSourceText()[0];
                for (; t !== null; t = t.next) {
                    if (!t.isChar(ch)) 
                        break;
                }
            }
            if (t === null) 
                break;
            let casinf = FragToken._createCaseInfo(t);
            if (casinf !== null) 
                break;
            let dr0 = Utils.as(t.getReferent(), DecreeReferent);
            if (dr0 !== null) {
                if (dr0.kind === DecreeKind.PUBLISHER) 
                    continue;
            }
            else if (t.getReferent() instanceof DecreePartReferent) {
                let dpr = Utils.as(t.getReferent(), DecreePartReferent);
                if (dpr !== null) {
                    if (((dpr.part === null && dpr.docPart === null)) || dpr.slots.length !== 2) 
                        break;
                    if ((t.next instanceof TextToken) && t.next.isPureVerb) 
                        break;
                    dr0 = dpr.owner;
                }
            }
            if (dr0 !== null) {
                if (doc.typ === null || doc.typ === dr0.typ) {
                    let tt1 = t.beginToken;
                    let li = DecreeToken.tryAttachList(tt1, null, 10, false);
                    if (li !== null && li.length > 0 && li[li.length - 1].isNewlineAfter) {
                        for (const dd of li) {
                            FragToken._addTitleAttr(doc, title, dd);
                        }
                        let ttt = li[li.length - 1].endToken;
                        if (ttt.endChar < t.endChar) {
                            nT0 = ttt.next;
                            _name = FragToken.getRestoredName(ttt.next, t.endToken, false);
                        }
                        t1 = t;
                        if (_name !== null && t1.isNewlineAfter) {
                            t = t.next;
                            break;
                        }
                        if (doc.typ === "КОДЕКС") {
                            let pt = PartToken.tryAttach(t.next, null, false, false);
                            if (pt !== null) {
                                if (((pt.typ !== PartTokenItemType.PART && pt.typ !== PartTokenItemType.DOCPART)) || pt.values.length !== 1) 
                                    pt = null;
                            }
                            if (pt !== null && pt.values.length > 0) {
                                doc.addSlot(InstrumentReferent.ATTR_PART, pt.values[0].value, false, 0);
                                title.children.push(FragToken._new2064(pt.beginToken, pt.endToken, InstrumentKind.DOCPART, pt.values[0].value));
                                t = pt.endToken;
                                continue;
                            }
                        }
                        if (doc.name !== null) {
                            t = t.next;
                            break;
                        }
                    }
                }
                else if (dr0.typ === "КОДЕКС") {
                    let pt = PartToken.tryAttach(t.next, null, false, false);
                    let nam = dr0.name;
                    if (pt !== null) {
                        if (((pt.typ !== PartTokenItemType.PART && pt.typ !== PartTokenItemType.DOCPART)) || pt.values.length !== 1) 
                            pt = null;
                    }
                    if (pt !== null && pt.values.length > 0) 
                        doc.addSlot(InstrumentReferent.ATTR_PART, pt.values[0].value, false, 0);
                    doc.addSlot(InstrumentBlockReferent.ATTR_NAME, nam, false, 0);
                    doc.typ = dr0.typ;
                    let _geo = dr0.getSlotValue(DecreeReferent.ATTR_GEO);
                    if (_geo !== null) 
                        doc.addSlot(InstrumentReferent.ATTR_GEO, _geo, false, 0);
                    t1 = t;
                    title.children.push(FragToken._new2064(t, t, InstrumentKind.NAME, nam));
                    if (pt !== null && pt.values.length > 0) {
                        title.children.push(FragToken._new2064(pt.beginToken, pt.endToken, InstrumentKind.DOCPART, pt.values[0].value));
                        t1 = pt.endToken;
                    }
                    t = t1;
                    continue;
                }
                t1 = t;
                ignoreEmptyLines = true;
                canBeOrgs = false;
                continue;
            }
            if (FragToken._isStartOfBody(t, false)) 
                break;
            if (t.isValue("ПРОЕКТ", null) && t.isNewlineAfter) 
                continue;
            if (doc.typ === null) {
                let ttt1 = DecreeToken.isKeyword(t, false);
                if (ttt1 !== null && ttt1.isNewlineAfter) {
                    let typ = MiscHelper.getTextValue(t, ttt1, GetTextAttr.KEEPQUOTES);
                    if (doc.typ === null) 
                        doc.typ = typ;
                    title.children.push(FragToken._new2064(t, ttt1, InstrumentKind.TYP, typ));
                    dt0 = DecreeToken._new1121(t, ttt1, DecreeTokenItemType.TYP, typ);
                    canBeOrgs = false;
                    t1 = (t = ttt1);
                    if ((t.next !== null && t.next.isNewlineAfter && typ === "УСТАВ") && (((t.next.getReferent() instanceof GeoReferent) || (t.next.getReferent() instanceof OrganizationReferent)))) {
                        t1 = (t = ttt1.next);
                        let nam = MiscHelper.getTextValueOfMetaToken(Utils.as(t, MetaToken), GetTextAttr.RESTOREREGISTER);
                        doc.addSlot(DecreeReferent.ATTR_NAME, "Устав " + nam, false, 0);
                        title.children.push(FragToken._new2064(t, t, InstrumentKind.NAME, nam));
                    }
                    continue;
                }
                if (t.isNewlineBefore && ttt1 !== null && DecreeToken.tryAttach(t, null, false) === null) {
                    startOfName = true;
                    break;
                }
            }
            let appr = FragToken._createApproved(t);
            if (appr !== null) {
                t = (t1 = appr.endToken);
                title.children.push(appr);
                if (appr.beginChar < title.beginChar) 
                    title.beginToken = appr.beginToken;
                continue;
            }
            let edss = FragToken._createEditions(t);
            if (edss !== null) 
                break;
            let misc = FragToken._createMisc(t);
            if (misc !== null) {
                t = (t1 = misc.endToken);
                title.children.push(misc);
                continue;
            }
            let dt = DecreeToken.tryAttach(t, dt0, false);
            if (dt !== null) {
                if (dt.typ === DecreeTokenItemType.TYP || dt.typ === DecreeTokenItemType.OWNER) {
                    if (dt.lengthChar < 4) 
                        dt = null;
                }
            }
            if (dt === null && dt0 !== null && ((dt0.typ === DecreeTokenItemType.OWNER || dt0.typ === DecreeTokenItemType.ORG))) {
                if ((t instanceof NumberToken) && t.isNewlineAfter && t.isNewlineBefore) 
                    dt = DecreeToken._new1121(t, t, DecreeTokenItemType.NUMBER, t.value.toString());
            }
            if (dt !== null && dt.typ === DecreeTokenItemType.UNKNOWN) 
                dt = null;
            if ((dt === null && (t instanceof NumberToken) && t.isNewlineBefore) && t.isNewlineAfter) {
                if (dt0 !== null && dt0.typ === DecreeTokenItemType.ORG && (t.typ === NumberSpellingType.DIGIT)) 
                    dt = DecreeToken._new1121(t, t, DecreeTokenItemType.NUMBER, t.value.toString());
            }
            if ((dt !== null && dt0 !== null && dt0.endToken.next !== dt.beginToken) && ((dt.typ === DecreeTokenItemType.TYP || dt.typ === DecreeTokenItemType.OWNER || dt.typ === DecreeTokenItemType.ORG))) {
                if (!t.isNewlineBefore && !t.previous.isTableControlChar) 
                    dt = null;
                else 
                    for (let ttt = dt.endToken.next; ttt !== null; ttt = ttt.next) {
                        if (ttt.isNewlineBefore || ttt.isTableControlChar) 
                            break;
                        else if ((ttt instanceof TextToken) && ttt.isPureVerb) {
                            dt = null;
                            break;
                        }
                    }
            }
            if (dt !== null && dt.typ === DecreeTokenItemType.DATE && dt0 !== null) {
                if (dt.isNewlineBefore || dt.isNewlineAfter) {
                }
                else if (dt0.typ === DecreeTokenItemType.NUMBER || dt0.typ === DecreeTokenItemType.TYP) {
                }
                else if (dt0.endToken.next === dt.beginToken) {
                }
                else 
                    dt = null;
            }
            if (dt === null) {
                if (t.getReferent() instanceof DateReferent) 
                    continue;
                if (t.isValue("ДАТА", null)) {
                    let ok = false;
                    for (let tt = t.next; tt !== null; tt = tt.next) {
                        if ((tt.isValue("ПОДПИСАНИЕ", "ПІДПИСАННЯ") || tt.isValue("ВВЕДЕНИЕ", "ВВЕДЕННЯ") || tt.isValue("ПРИНЯТИЕ", "ПРИЙНЯТТЯ")) || tt.isValue("ДЕЙСТВИЕ", "ДІЮ") || tt.morph._class.isPreposition) 
                            continue;
                        if ((tt instanceof TextToken) && !tt.chars.isLetter) 
                            continue;
                        let da = Utils.as(tt.getReferent(), DateReferent);
                        if (da !== null) {
                            let frdt = FragToken._new2000(t, tt, InstrumentKind.DATE);
                            title.children.push(frdt);
                            t = tt;
                            ok = true;
                            if (doc.date === null) 
                                doc.addDate(da);
                        }
                        break;
                    }
                    if (ok) 
                        continue;
                }
                let r = t.getReferent();
                if ((r === null && t.lengthChar === 1 && !t.chars.isLetter) && (t.next instanceof ReferentToken) && !t.isNewlineAfter) {
                    t = t.next;
                    r = t.getReferent();
                }
                if (((r instanceof AddressReferent) || (r instanceof UriReferent) || (r instanceof PhoneReferent)) || (r instanceof PersonIdentityReferent) || (r instanceof BankDataReferent)) {
                    let cnt = FragToken._new2000(t, t, InstrumentKind.CONTACT);
                    cnt.referents = new Array();
                    cnt.referents.push(r);
                    title.children.push(cnt);
                    for (; t !== null; t = t.next) {
                        if (t.next !== null && t.next.isCharOf(",;.")) 
                            t = t.next;
                        if (t.next === null) 
                            break;
                        r = t.next.getReferent();
                        if (((r instanceof AddressReferent) || (r instanceof UriReferent) || (r instanceof PhoneReferent)) || (r instanceof PersonIdentityReferent) || (r instanceof BankDataReferent)) {
                            cnt.referents.push(r);
                            cnt.endToken = t.next;
                        }
                        else if (t.isNewlineAfter) 
                            break;
                    }
                    continue;
                }
                let pt = (t.isNewlineBefore ? PartToken.tryAttach(t, null, false, false) : null);
                if ((pt !== null && ((pt.typ === PartTokenItemType.PART || pt.typ === PartTokenItemType.DOCPART)) && pt.values.length === 1) && pt.isNewlineAfter) {
                    let ok = false;
                    if (dt0 !== null && dt0.typ === DecreeTokenItemType.TYP) 
                        ok = true;
                    else {
                        let ddd = DecreeToken.tryAttach(pt.endToken.next, null, false);
                        if (ddd !== null && ddd.typ === DecreeTokenItemType.TYP) 
                            ok = true;
                        else if (FragToken._createApproved(pt.endToken.next) !== null) 
                            ok = true;
                    }
                    if (ok) {
                        title.children.push(FragToken._new2064(pt.beginToken, pt.endToken, InstrumentKind.DOCPART, pt.values[0].value));
                        doc.addSlot(InstrumentReferent.ATTR_PART, pt.values[0].value, false, 0);
                        t = pt.endToken;
                        continue;
                    }
                }
                if (appr0 !== null) 
                    break;
                if (canBeOrgs) {
                    if (t.getReferent() instanceof PersonReferent) {
                    }
                    else {
                        let org = FragToken._createOwner(t);
                        if (org !== null) {
                            unknownOrgs.push(org);
                            t1 = (t = org.endToken);
                            continue;
                        }
                    }
                }
                let stok = InstrToken.parse(t, 0, null);
                if (stok !== null && ((stok.noWords || (stok.lengthChar < 5)))) {
                    if (t0 === t) 
                        t0 = stok.endToken.next;
                    t = stok.endToken;
                    continue;
                }
                if ((t.isNewlineBefore && doc.typ !== null && (t instanceof TextToken)) && NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null) !== null) 
                    break;
                if (t.isNewlineBefore && t.isValue("К", "ДО")) 
                    break;
                if (((!ignoreEmptyLines && stok !== null && stok.typ === ILTypes.UNDEFINED) && !stok.hasVerb && ((dt0 === null || dt0.typ === DecreeTokenItemType.NUMBER))) && (emptyLines < 3)) {
                    if (stok.isNewlineAfter) 
                        emptyLines++;
                    else if (dt0 !== null) 
                        break;
                    t = (endEmptyLines = stok.endToken);
                    continue;
                }
                break;
            }
            if ((!ignoreEmptyLines && dt.typ === DecreeTokenItemType.TERR && endEmptyLines !== null) && dt0 === null) {
                if (dt.isNewlineAfter) 
                    emptyLines++;
                t = (endEmptyLines = dt.endToken);
                continue;
            }
            if (dt.typ === DecreeTokenItemType.ORG || dt.typ === DecreeTokenItemType.OWNER) {
                if (isContract) 
                    break;
                for (let ttt = dt.endToken.next; ttt !== null; ttt = ttt.next) {
                    if (ttt.whitespacesBeforeCount > 15) 
                        break;
                    if (ttt.getMorphClassInDictionary().equals(MorphClass.VERB)) {
                        dt = null;
                        break;
                    }
                    let dt1 = DecreeToken.tryAttach(ttt, dt0, false);
                    if (dt1 !== null) {
                        if ((dt1.typ === DecreeTokenItemType.NUMBER || dt1.typ === DecreeTokenItemType.TYP || dt1.typ === DecreeTokenItemType.NAME) || dt1.typ === DecreeTokenItemType.DATE || dt1.typ === DecreeTokenItemType.ORG) 
                            break;
                        dt.endToken = dt1.endToken;
                    }
                    else if (!ttt.chars.equals(dt.beginToken.chars) && ttt.isNewlineBefore) 
                        break;
                    else 
                        dt.endToken = ttt;
                }
                if (dt === null) 
                    break;
            }
            if (dt.typ === DecreeTokenItemType.TYP) {
                let typ = DecreeToken.getKind(dt.value, null);
                if (typ === DecreeKind.PUBLISHER) {
                    for (; t !== null; t = t.next) {
                        if (t.isNewlineAfter) 
                            break;
                    }
                    if (t === null) 
                        break;
                    continue;
                }
                if (typ === DecreeKind.CONTRACT || dt.value === "ДОВЕРЕННОСТЬ" || dt.value === "ДОВІРЕНІСТЬ") 
                    isContract = true;
                else if (dt.value === "ПРОТОКОЛ" && !dt.isNewlineAfter) {
                    let npt1 = NounPhraseHelper.tryParse(dt.endToken.next, NounPhraseParseAttr.NO, 0, null);
                    if (npt1 !== null) {
                        for (t = dt.endToken.next; t !== null; t = t.next) {
                            dt.endToken = t;
                            if (t.isNewlineAfter) 
                                break;
                        }
                    }
                }
                canBeOrgs = false;
            }
            dt0 = dt;
            if (dt.typ === DecreeTokenItemType.NUMBER && unknownOrgs.length > 0) {
                for (const org of unknownOrgs) {
                    title.children.push(org);
                    doc.addSlot(InstrumentReferent.ATTR_SOURCE, org.value, false, 0);
                }
                unknownOrgs.splice(0, unknownOrgs.length);
            }
            if (!FragToken._addTitleAttr(doc, title, dt)) 
                break;
            else 
                attrs++;
            t1 = (t = dt.endToken);
        }
        title.sortChildren();
        if (t === null || (((doc.typ === null && doc.regNumber === null && appr0 === null) && !startOfName))) {
            if (t === t0) {
                let nam = DecreeToken.tryAttachName(t0, null, true, false, false);
                if (nam !== null) {
                    _name = FragToken.getRestoredName(t0, nam.endToken, false);
                    if (!Utils.isNullOrEmpty(_name)) {
                        t1 = nam.endToken;
                        doc.addSlot(InstrumentBlockReferent.ATTR_NAME, _name.trim(), true, 0);
                        title.children.push(FragToken._new2064(t0, t1, InstrumentKind.NAME, _name.trim()));
                        for (; t1.next !== null; t1 = t1.next) {
                            if (t1.isTableControlChar && !t1.isChar(String.fromCharCode(0x1F))) {
                            }
                            else 
                                break;
                        }
                        title.endToken = t1;
                        for (t = t1.next; t !== null; t = t.next) {
                            if (FragToken._isStartOfBody(t, false)) 
                                break;
                            if (t.isTableControlChar) 
                                continue;
                            let appr1 = FragToken._createApproved(t);
                            if (appr1 !== null) {
                                title.children.push(appr1);
                                t = title.endToken = appr1.endToken;
                                continue;
                            }
                            let eds = FragToken._createEditions(t);
                            if (eds !== null) {
                                title.children.push(eds);
                                t = title.endToken = eds.endToken;
                                break;
                            }
                            appr1 = FragToken._createMisc(t);
                            if (appr1 !== null) {
                                title.children.push(appr1);
                                t = title.endToken = appr1.endToken;
                                continue;
                            }
                            let dt00 = DecreeToken.tryAttach(t, null, false);
                            if (dt00 !== null) {
                                if (dt00.typ === DecreeTokenItemType.DATE || dt00.typ === DecreeTokenItemType.TERR) {
                                    FragToken._addTitleAttr(doc, title, dt00);
                                    t = title.endToken = dt00.endToken;
                                    continue;
                                }
                            }
                            break;
                        }
                        return title;
                    }
                }
            }
            if (t !== null && t.isValue("О", null)) {
                let nam = DecreeToken.tryAttachName(t, null, true, false, false);
                if (nam !== null) {
                    _name = FragToken.getRestoredName(t, nam.endToken, false);
                    if (!Utils.isNullOrEmpty(_name)) {
                        t1 = nam.endToken;
                        doc.addSlot(InstrumentBlockReferent.ATTR_NAME, _name.trim(), true, 0);
                        title.children.push(FragToken._new2064(t, t1, InstrumentKind.NAME, _name.trim()));
                    }
                }
            }
            if (attrs > 0) {
                title.endToken = t1;
                return title;
            }
            return null;
        }
        for (let j = 0; j < unknownOrgs.length; j++) {
            title.children.splice(j, 0, unknownOrgs[j]);
            doc.addSlot(InstrumentReferent.ATTR_SOURCE, unknownOrgs[j].value, false, 0);
        }
        if (endEmptyLines !== null && doc.findSlot(InstrumentReferent.ATTR_SOURCE, null, true) === null) {
            let val = MiscHelper.getTextValue(t0, endEmptyLines, GetTextAttr.NO);
            doc.addSlot(InstrumentReferent.ATTR_SOURCE, val, false, 0);
            title.children.splice(0, 0, FragToken._new2064(t0, endEmptyLines, InstrumentKind.ORGANIZATION, val));
        }
        let isCase = false;
        for (const ch of title.children) {
            if (ch.value === null && ch.kind !== InstrumentKind.APPROVED && ch.kind !== InstrumentKind.EDITIONS) 
                ch.value = MiscHelper.getTextValue(ch.beginToken, ch.endToken, GetTextAttr.NO);
            if (ch.kind === InstrumentKind.CASENUMBER) 
                isCase = true;
        }
        if ((((_name !== null || t.isNewlineBefore || ((t.previous !== null && t.previous.isTableControlChar))) || ((!t.isNewlineBefore && title.children.length > 0 && title.children[title.children.length - 1].kind === InstrumentKind.TYP)))) && !isCase) {
            let tt0 = t;
            let firstLine = null;
            let poDelu = false;
            if (t.isValue("ПО", null) && t.next !== null && t.next.isValue("ДЕЛО", "СПРАВА")) 
                poDelu = true;
            for (; t !== null; t = t.next) {
                if (FragToken._isStartOfBody(t, false)) 
                    break;
                if ((_name !== null && t === tt0 && t.isNewlineBefore) && t.whitespacesBeforeCount > 15) 
                    break;
                if (t.isTableControlChar) 
                    break;
                if (t.isNewlineBefore) {
                    let pt = PartToken.tryAttach(t, null, false, false);
                    if (pt !== null && pt.typ !== PartTokenItemType.PREFIX) 
                        break;
                    let ltt = InstrToken1.parse(t, false, null, 0, null, false, 0, true, false);
                    if (ltt === null) 
                        break;
                    if (t !== tt0 && t.whitespacesBeforeCount > 15) {
                        if (t.newlinesBeforeCount > 2) 
                            break;
                        if (t.newlinesBeforeCount > 1 && !t.chars.isAllUpper) 
                            break;
                        if (t.isValue("О", "ПРО") || t.isValue("ОБ", null)) {
                        }
                        else if (ltt.allUpper && !ltt.hasChanges) {
                        }
                        else 
                            break;
                    }
                    if (ltt.numbers.length > 0) 
                        break;
                    let appr = FragToken._createApproved(t);
                    if (appr !== null) {
                        if (t.previous !== null && t.previous.isChar(',')) {
                        }
                        else 
                            break;
                    }
                    if (FragToken._createEditions(t) !== null || FragToken._createCaseInfo(t) !== null) 
                        break;
                    if (t.getReferent() instanceof GeoReferent) {
                        if (t.isNewlineAfter) 
                            break;
                        if (t.next !== null && (t.next.getReferent() instanceof DateReferent)) 
                            break;
                    }
                    if (t.getReferent() instanceof DateReferent) {
                        if (t.isNewlineAfter) 
                            break;
                        if (t.next !== null && (t.next.getReferent() instanceof GeoReferent)) 
                            break;
                    }
                    if (t.getReferent() instanceof DecreePartReferent) 
                        break;
                    if (t.getReferent() instanceof DecreeReferent) {
                        let dr = Utils.as(t.getReferent(), DecreeReferent);
                        if (dr.kind === DecreeKind.PUBLISHER) 
                            break;
                    }
                    if (t.isChar('(')) {
                        if (FragToken._createEditions(t) !== null) 
                            break;
                        let br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                        if (br !== null && !br.isNewlineAfter) {
                        }
                        else 
                            break;
                    }
                    if (ltt.hasVerb && !ltt.allUpper) {
                        if (t.isValue("О", "ПРО") && tt0 === t) {
                        }
                        else if (!poDelu) 
                            break;
                    }
                    if (ltt.typ === InstrToken1Types.DIRECTIVE) 
                        break;
                    let str = ltt.toString();
                    if (t.previous !== null && t.previous.isValue("ИЗМЕНЕНИЕ", null)) {
                    }
                    else if (str.includes("В СОСТАВЕ") || str.includes("В СКЛАДІ") || str.includes("У СКЛАДІ")) {
                        if (!ltt.allUpper) 
                            break;
                    }
                    if (t.isValue("В", null) && t.next !== null && t.next.isValue("ЦЕЛЬ", "МЕТА")) 
                        break;
                    if (firstLine === null) 
                        firstLine = ltt;
                    else if (firstLine.allUpper && !ltt.allUpper && !BracketHelper.canBeStartOfSequence(t, false, false)) 
                        break;
                    t1 = (t = ltt.endToken);
                    if (t1.isTableControlChar) {
                        t1 = (t = t1.previous);
                        break;
                    }
                }
                else 
                    t1 = t;
            }
            let tt1 = DecreeToken._tryAttachStdChangeName(tt0);
            if (tt1 !== null) {
                if (t1 === null || (t1.endChar < tt1.endChar)) 
                    t1 = tt1;
            }
            let val = (t1 !== null && t1 !== tt0 ? FragToken.getRestoredName(tt0, t1, false) : null);
            if (!Utils.isNullOrEmpty(val) && Utils.isLetter(val[0]) && Utils.isLowerCase(val[0])) 
                val = (val[0].toUpperCase()) + val.substring(1);
            if (_name === null && title.children.length > 0 && title.children[title.children.length - 1].kind === InstrumentKind.TYP) {
                let npt = NounPhraseHelper.tryParse(tt0, NounPhraseParseAttr.NO, 0, null);
                if (npt !== null) {
                    if (npt.morph._case.isGenitive) {
                        _name = Utils.asString(title.children[title.children.length - 1].value);
                        if (DecreeToken.tryAttach(title.children[title.children.length - 1].beginToken, null, false) === null) {
                            tt0 = title.children[title.children.length - 1].beginToken;
                            title.children.splice(title.children.length - 1, 1);
                        }
                    }
                }
            }
            if (val === null) 
                val = _name;
            else if (_name !== null) 
                val = (_name + " " + val);
            if (val !== null && tt0.beginChar <= t1.beginChar) {
                if (nT0 !== null) 
                    tt0 = nT0;
                val = val.trim();
                if (val.startsWith("[") && val.endsWith("]")) 
                    val = val.substring(1, 1 + val.length - 2).trim();
                doc.addSlot(InstrumentBlockReferent.ATTR_NAME, val.trim(), true, 0);
                title.children.push(FragToken._new2064(tt0, t1, InstrumentKind.NAME, val.trim()));
                if (val.includes("КОДЕКС")) {
                    let npt = NounPhraseHelper.tryParse(tt0, NounPhraseParseAttr.NO, 0, null);
                    if (npt !== null && npt.noun.isValue("КОДЕКС", null)) 
                        doc.typ = "КОДЕКС";
                }
            }
        }
        if (t1 === null) 
            return null;
        title.endToken = t1;
        for (t1 = t1.next; t1 !== null; t1 = t1.next) {
            if (t1.isNewlineBefore && (t1.getReferent() instanceof DecreeReferent) && t1.isNewlineAfter) {
                let dr = Utils.as(t1.getReferent(), DecreeReferent);
                title.children.push(FragToken._new2000(t1, t1, InstrumentKind.IGNORED));
                continue;
            }
            if (t1.isNewlineBefore && t1.isValue("ЧАСТЬ", "ЧАСТИНА")) {
                let pt = PartToken.tryAttach(t1, null, false, false);
                if (pt !== null && pt.isNewlineAfter) {
                    let pt2 = PartToken.tryAttach(pt.endToken.next, null, false, false);
                    if (pt2 !== null && (((pt2.typ === PartTokenItemType.SECTION || pt2.typ === PartTokenItemType.SUBSECTION || pt2.typ === PartTokenItemType.CHAPTER) || pt2.typ === PartTokenItemType.CLAUSE))) {
                    }
                    else {
                        doc.addSlot(InstrumentReferent.ATTR_PART, pt.values[0].value, false, 0);
                        title.children.push(FragToken._new2064(t1, pt.endToken, InstrumentKind.DOCPART, pt.values[0].value));
                        t1 = title.endToken = pt.endToken;
                        continue;
                    }
                }
            }
            if (t1.isNewlineBefore) {
                let iii = InstrToken1.parse(t1, true, null, 0, null, false, 0, false, false);
                if (iii !== null && iii.typ === InstrToken1Types.COMMENT) {
                    title.children.push(FragToken._new2000(t1, iii.endToken, InstrumentKind.COMMENT));
                    t1 = iii.endToken;
                    continue;
                }
            }
            let appr1 = FragToken._createApproved(t1);
            if (appr1 !== null) {
                t1 = appr1.endToken;
                title.children.push(appr1);
                title.endToken = appr1.endToken;
                continue;
            }
            let cinf = FragToken._createCaseInfo(t1);
            if (cinf !== null) {
                t1 = cinf.endToken;
                title.children.push(cinf);
                title.endToken = cinf.endToken;
                continue;
            }
            let eds = FragToken._createEditions(t1);
            if (eds !== null) {
                title.children.push(eds);
                title.endToken = (t1 = eds.endToken);
                continue;
            }
            appr1 = FragToken._createMisc(t1);
            if (appr1 !== null) {
                t1 = appr1.endToken;
                title.children.push(appr1);
                title.endToken = appr1.endToken;
                continue;
            }
            if ((t1.getReferent() instanceof DecreeReferent) && t1.getReferent().kind === DecreeKind.PUBLISHER && t1.isNewlineAfter) {
                let pub = FragToken._new2000(t1, t1, InstrumentKind.APPROVED);
                pub.referents = new Array();
                pub.referents.push(t1.getReferent());
                title.children.push(pub);
                title.endToken = t1;
                continue;
            }
            let tt = t1;
            if (tt.next !== null && tt.isChar(',')) 
                tt = tt.next;
            let dt = DecreeToken.tryAttach(tt, null, false);
            if (dt !== null && ((dt.typ === DecreeTokenItemType.DATE || dt.typ === DecreeTokenItemType.TERR || ((dt.typ === DecreeTokenItemType.NUMBER && ((dt.isDelo || MiscHelper.checkNumberPrefix(tt) !== null))))))) {
                if (dt.typ === DecreeTokenItemType.DATE) {
                    if (doc.date !== null) 
                        break;
                    if (!dt.isNewlineAfter && !MiscHelper.canBeStartOfSentence(dt.endToken.next)) {
                        let ttt = dt.endToken.next;
                        if (ttt !== null && (((ttt.getReferent() instanceof GeoReferent) || ttt.isComma))) {
                        }
                        else 
                            break;
                    }
                }
                if (!dt.isNewlineAfter) {
                    let lll = InstrToken1.parse(tt, true, null, 0, null, false, 0, false, false);
                    if (lll !== null && lll.hasVerb) 
                        break;
                }
                FragToken._addTitleAttr(doc, title, dt);
                t1 = title.endToken = dt.endToken;
                continue;
            }
            if (tt.isCharOf("([") && tt.isNewlineBefore) {
                let br = BracketHelper.tryParse(tt, BracketParseAttr.of((BracketParseAttr.CANBEMANYLINES.value()) | (BracketParseAttr.CANCONTAINSVERBS.value())), 100);
                if (br !== null) {
                    t1 = title.endToken = br.endToken;
                    title.children.push(FragToken._new2000(br.beginToken, br.endToken, (tt.isChar('[') ? InstrumentKind.NAME : InstrumentKind.COMMENT)));
                    continue;
                }
            }
            if (tt.isTableControlChar) {
                title.endToken = tt;
                continue;
            }
            break;
        }
        t1 = title.endToken.next;
        if (t1 !== null && t1.isNewlineBefore && doc.typ === "КОДЕКС") {
            let pt = PartToken.tryAttach(t1, null, false, false);
            if (pt !== null && ((pt.typ === PartTokenItemType.PART || pt.typ === PartTokenItemType.DOCPART)) && pt.values.length > 0) {
                let cou = 0;
                for (t = pt.endToken; t !== null; t = t.next) {
                    if (t.isNewlineBefore) {
                        if ((++cou) > 4) 
                            break;
                        let eds = FragToken._createEditions(t);
                        if (eds !== null) {
                            title.children.push(eds);
                            title.endToken = (t1 = eds.endToken);
                            title.children.push(FragToken._new2064(pt.beginToken, pt.endToken, InstrumentKind.DOCPART, pt.values[0].value));
                            if (doc.name !== null && doc.name.includes("КОДЕКС")) 
                                doc.addSlot(InstrumentReferent.ATTR_PART, pt.values[0].value, false, 0);
                            break;
                        }
                    }
                }
            }
            else if (t1.getReferent() instanceof DecreePartReferent) {
                let dr0 = Utils.as(t1.getReferent(), DecreePartReferent);
                if (dr0.part !== null || dr0.docPart !== null) {
                    let cou = 0;
                    for (t = t1.next; t !== null; t = t.next) {
                        if (t.isNewlineBefore) {
                            if ((++cou) > 4) 
                                break;
                            let eds = FragToken._createEditions(t);
                            if (eds !== null) {
                                title.children.push(eds);
                                title.endToken = (t1 = eds.endToken);
                                break;
                            }
                        }
                    }
                }
            }
        }
        return title;
    }
    
    static createAppendixTitle(t0, app, doc, isApp, start) {
        const InstrToken = require("./InstrToken");
        const InstrToken1 = require("./InstrToken1");
        if (t0 === null) 
            return null;
        if (t0 !== t0.kit.firstToken) {
            if (t0.getReferent() instanceof DecreePartReferent) {
                if (t0.getReferent().appendix !== null) {
                    if ((t0.next !== null && t0.next.isHiphen && (t0.next.next instanceof ReferentToken)) && (t0.next.next.getReferent() instanceof DecreePartReferent)) 
                        t0.kit.debedToken(t0.next.next);
                    t0 = t0.kit.debedToken(t0);
                }
            }
        }
        let t = t0;
        let t1 = null;
        let rr = t.getReferent();
        if (rr !== null) {
            if (rr.typeName === "PERSON") 
                return null;
        }
        let title = FragToken._new2000(t0, t, InstrumentKind.HEAD);
        let hasAppKeyword = false;
        let appr0 = FragToken._createApproved(t0);
        if (appr0 !== null) {
            title.endToken = appr0.endToken;
            title.children.push(appr0);
            t = appr0.endToken.next;
        }
        for (; t !== null; t = t.next) {
            let tt = MiscHelper.checkImage(t);
            if (tt !== null) {
                t = tt;
                continue;
            }
            let fr = InstrToken1.parse(t, true, null, 0, null, false, 0, true, false);
            if (fr === null) 
                break;
            if (fr.typ === InstrToken1Types.COMMENT) {
                title.endToken = (t = fr.endToken);
                title.children.push(FragToken._new2000(fr.beginToken, fr.endToken, InstrumentKind.COMMENT));
                continue;
            }
            if (fr.typ !== InstrToken1Types.APPENDIX && fr.typ !== InstrToken1Types.APPROVED) {
                if (fr.hasManySpecChars) {
                    t = fr.endToken;
                    continue;
                }
                if (t.getReferent() instanceof OrganizationReferent) {
                    t = fr.endToken;
                    continue;
                }
                if ((t.getReferent() instanceof DecreePartReferent) && t.getReferent().appendix !== null) {
                    t = t.kit.debedToken(t);
                    fr = InstrToken1.parse(t, true, null, 0, null, false, 0, true, false);
                    if (fr.typ !== InstrToken1Types.APPENDIX) 
                        break;
                }
                else 
                    break;
            }
            if (fr.typ === InstrToken1Types.APPENDIX) {
                hasAppKeyword = true;
                app.kind = InstrumentKind.APPENDIX;
            }
            let t2 = t;
            if (t.isValue("ОСОБЫЙ", "ОСОБЛИВИЙ") && t.next !== null) 
                t2 = t.next;
            if (t instanceof TextToken) 
                title.children.push(FragToken._new2026(t, t2, InstrumentKind.KEYWORD, true));
            title.endToken = (t = fr.endToken);
            if (fr.typ === InstrToken1Types.APPENDIX && fr.numBeginToken === null) {
                let fr1 = InstrToken1.parse(t.next, true, null, 0, null, false, 0, false, false);
                if (fr1 !== null && fr1.typ === InstrToken1Types.APPROVED) {
                    t = fr1.beginToken;
                    title.children.push(FragToken._new2064(t, t, InstrumentKind.KEYWORD, t.getSourceText().toUpperCase()));
                    title.endToken = (t = fr1.endToken);
                    fr = fr1;
                }
            }
            appr0 = FragToken._createApproved(t);
            if (appr0 !== null) {
                t = title.endToken = appr0.endToken;
                title.children.push(appr0);
                continue;
            }
            if (fr.numBeginToken !== null && fr.numEndToken !== null) {
                let num = FragToken._new2064(fr.numBeginToken, fr.numEndToken, InstrumentKind.NUMBER, MiscHelper.getTextValue(fr.numBeginToken, fr.numEndToken, GetTextAttr.KEEPREGISTER));
                title.children.push(num);
                if (fr.numbers.length > 0) 
                    app.number = PartToken.getNumber(fr.numbers[0]);
                if (fr.numbers.length > 1) {
                    app.subNumber = PartToken.getNumber(fr.numbers[1]);
                    if (fr.numbers.length > 2) 
                        app.subNumber2 = PartToken.getNumber(fr.numbers[2]);
                }
                if (fr.minNumber !== null) {
                    let nn = 0;
                    let wrapnn2142 = new RefOutArgWrapper();
                    let inoutres2143 = Utils.tryParseInt(fr.minNumber, wrapnn2142);
                    nn = wrapnn2142.value;
                    if (inoutres2143) 
                        app.minNumber = nn;
                }
                if (isApp) 
                    doc.addSlot(InstrumentReferent.ATTR_APPENDIX, (num.value != null ? num.value : "1"), false, 0);
            }
            else if (t.getReferent() instanceof DecreeReferent) {
                if (t.getReferent().kind === DecreeKind.PUBLISHER) {
                    let ff = FragToken._new2000(t, t, InstrumentKind.APPROVED);
                    ff.referents = new Array();
                    ff.referents.push(t.getReferent());
                    title.children.push(ff);
                }
                else if (fr.typ === InstrToken1Types.APPROVED && title.children.length > 0 && title.children[title.children.length - 1].kind === InstrumentKind.KEYWORD) {
                    let kw = title.children[title.children.length - 1];
                    let appr = FragToken._new2000(kw.beginToken, t, InstrumentKind.APPROVED);
                    title.children.splice(title.children.length - 1, 1);
                    appr.children.push(kw);
                    appr.children.push(FragToken._new2000(t, t, InstrumentKind.DOCREFERENCE));
                    title.children.push(appr);
                }
                else 
                    title.children.push(FragToken._new2000(t, t, InstrumentKind.DOCREFERENCE));
            }
            else if (fr.typ === InstrToken1Types.APPROVED && fr.lengthChar > 15 && fr.beginToken !== fr.endToken) 
                title.children.push(FragToken._new2000(fr.beginToken.next, t, InstrumentKind.DOCREFERENCE));
            else {
                let dts = DecreeToken.tryAttachList(t.next, null, 10, false);
                if (dts !== null && dts.length > 0 && dts[0].typ === DecreeTokenItemType.TYP) {
                    let dref = FragToken._new2000(dts[0].beginToken, dts[0].endToken, InstrumentKind.DOCREFERENCE);
                    for (let i = 1; i < dts.length; i++) {
                        if (dts[i].typ === DecreeTokenItemType.TYP) 
                            break;
                        else if (dts[i].typ !== DecreeTokenItemType.UNKNOWN) 
                            dref.endToken = dts[i].endToken;
                    }
                    title.children.push(dref);
                    title.endToken = (t = dref.endToken);
                }
            }
            if (fr.typ === InstrToken1Types.APPENDIX) {
                t = t.next;
                if (t !== null) {
                    let dpr = Utils.as(t.getReferent(), DecreePartReferent);
                    if (dpr !== null && dpr.appendix !== null) {
                        t = t.kit.debedToken(t);
                        t = t.previous;
                        continue;
                    }
                    if (t.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК")) {
                        t = t.previous;
                        continue;
                    }
                }
                break;
            }
        }
        if (t === null) 
            return null;
        let hasForNpa = false;
        if (t.isValue("К", "ДО")) {
            hasForNpa = true;
            let toDecr = null;
            let toks = new Array();
            for (let tt = t.next; tt !== null; tt = tt.next) {
                if (tt !== t.next && tt.isTableControlChar) 
                    break;
                if (tt.isNewlineBefore) {
                    if (tt.newlinesBeforeCount > 1) 
                        break;
                    let it1 = InstrToken1.parse(tt, false, null, 0, null, false, 0, false, false);
                    if (it1 !== null && it1.numbers.length > 0) 
                        break;
                    if (tt.chars.isAllLower) {
                    }
                    else if (tt.lengthChar > 2) {
                        let npt = NounPhraseHelper.tryParse(tt, NounPhraseParseAttr.of((NounPhraseParseAttr.PARSEPREPOSITION.value()) | (NounPhraseParseAttr.REFERENTCANBENOUN.value())), 0, null);
                        if (npt === null) 
                            break;
                        if (npt.morph._case.isNominative) 
                            break;
                    }
                }
                if (tt.getReferent() instanceof DecreeReferent) 
                    toDecr = Utils.as(tt.getReferent(), DecreeReferent);
                let tok = InstrToken.parse(tt, 0, null);
                if (tok === null) 
                    break;
                toks.push(tok);
                if (toks.length > 20) 
                    break;
                if (tt === t.next && tok.typ === ILTypes.UNDEFINED) {
                    let ttt = DecreeToken.isKeyword(tt, false);
                    if (ttt !== null) {
                        tok.endToken = ttt;
                        tok.typ = ILTypes.TYP;
                    }
                }
                tt = tok.endToken;
                let dtt = DecreeToken.tryAttach(tt.next, null, false);
                if (dtt !== null && dtt.typ === DecreeTokenItemType.DATE) 
                    tt = tok.endToken = dtt.endToken;
                if (tok.typ === ILTypes.TYP && !tt.isNewlineAfter) {
                    let nn = DecreeToken.tryAttachName(tt.next, null, false, true, false);
                    if (nn !== null) {
                        tt = tok.endToken = nn.endToken;
                        break;
                    }
                }
            }
            let maxInd = -1;
            for (let ii = 0; ii < toks.length; ii++) {
                let tok = toks[ii];
                if (tok.typ === ILTypes.TYP && ((tok.value === doc.typ || ii === 0)) && !tok.beginToken.previous.isValue("К", null)) 
                    maxInd = ii;
                else if (tok.typ === ILTypes.REGNUMBER && (((tok.value === doc.regNumber || tok.value === "?" || tok.isNewlineBefore) || tok.isNewlineAfter || tok.hasTableChars))) 
                    maxInd = ii;
                else if (tok.typ === ILTypes.DATE && doc.date !== null) {
                    if ((tok.ref instanceof DateReferent) && tok.ref.dt === doc.date) 
                        maxInd = ii;
                    else if (tok.ref instanceof ReferentToken) {
                        let dre = Utils.as(tok.ref.referent, DateReferent);
                        if (dre !== null && dre.dt !== null && doc.date !== null) {
                            if (dre.dt === doc.date) 
                                maxInd = ii;
                        }
                    }
                }
                else if (tok.typ === ILTypes.DATE && tok.beginToken.previous !== null && tok.beginToken.previous.isValue("ОТ", null)) 
                    maxInd = ii;
                else if (tok.typ === ILTypes.UNDEFINED && (tok.beginToken.getReferent() instanceof DecreeReferent)) {
                    maxInd = ii;
                    break;
                }
                else if (ii === 0 && tok.typ === ILTypes.UNDEFINED && (tok.beginToken.getReferent() instanceof DecreePartReferent)) {
                    let part = Utils.as(tok.beginToken.getReferent(), DecreePartReferent);
                    if (part.appendix !== null) {
                        maxInd = ii;
                        break;
                    }
                }
                else if (tok.typ === ILTypes.ORGANIZATION && ii === 1) 
                    maxInd = ii;
                else if (tok.typ === ILTypes.UNDEFINED) {
                    if (tok.beginToken.isValue("ОТ", null)) 
                        maxInd = ii;
                    else if (MiscHelper.checkNumberPrefix(tok.beginToken) !== null) 
                        maxInd = ii;
                }
                else if (tok.typ === ILTypes.GEO || tok.typ === ILTypes.ORGANIZATION) 
                    maxInd = ii;
            }
            if (toks.length > 0 && DecreeToken.isKeyword(toks[toks.length - 1].endToken.next, false) !== null) 
                maxInd = toks.length - 1;
            else if (toks.length > 0 && (maxInd < 0) && toks[0].beginToken.previous.isValue("К", null)) 
                maxInd = toks.length - 1;
            let te = null;
            if (maxInd >= 0) {
                te = toks[maxInd].endToken;
                if (!te.isNewlineAfter) {
                    let nn = DecreeToken.tryAttachName(te.next, null, false, true, false);
                    if (nn !== null) 
                        te = nn.endToken;
                }
            }
            else if (t.next !== null && (t.next.getReferent() instanceof DecreeReferent)) 
                te = t.next;
            if (te !== null) {
                let dr = FragToken._new2000(t, te, InstrumentKind.DOCREFERENCE);
                if (toDecr !== null) {
                    dr.referents = new Array();
                    dr.referents.push(toDecr);
                }
                title.children.push(dr);
                title.endToken = te;
                if ((((t = te.next))) === null) 
                    return title;
            }
        }
        if (title.children.length === 0) {
            if (t !== null && t.isValue("АКТ", null)) {
            }
            else 
                return null;
        }
        for (let kk = 0; kk < 10; kk++) {
            let ta = FragToken._createApproved(t);
            if (ta !== null) {
                title.children.push(ta);
                title.endToken = (t = ta.endToken);
                t = t.next;
                if (t === null) 
                    return title;
                continue;
            }
            let ee = FragToken._createEditions(t);
            if (ee !== null) {
                title.children.push(ee);
                title.endToken = ee.endToken;
                t = ee.endToken.next;
                if (t === null) 
                    return title;
                continue;
            }
            ta = FragToken._createMisc(t);
            if (ta !== null) {
                title.children.push(ta);
                title.endToken = (t = ta.endToken);
                t = t.next;
                if (t === null) 
                    return title;
                continue;
            }
            if (t.isValue("РИСУНОК", null)) {
                let fr = InstrToken1.parse(t, true, null, 0, null, false, 0, true, false);
                if (fr === null) 
                    break;
                if (fr.lengthChar < 20) {
                    title.endToken = (t = fr.endToken);
                    t = t.next;
                    continue;
                }
            }
            if (t.isValue("УТРАТИТЬ", "СИЛУ")) {
                let fr = InstrToken1.parse(t, true, null, 0, null, false, 0, true, false);
                title.isExpired = true;
                title.endToken = fr.endToken;
                title.children.push(FragToken._new2151(t, fr.endToken, InstrumentKind.EDITIONS, true));
                return title;
            }
            if (t.isCharOf(":-") && !t.isNewlineAfter) {
                t = t.next;
                continue;
            }
            break;
        }
        let tt0 = t;
        if ((start && hasForNpa && hasAppKeyword) && tt0.isNewlineBefore) {
            let dty = DecreeToken.tryAttach(tt0, null, false);
            if (dty !== null && dty.typ === DecreeTokenItemType.TYP) {
                let sub = FragToken.createDocument(tt0, 0, InstrumentKind.UNDEFINED);
                if (sub !== null && sub.children.length > 1 && sub.m_Doc.findSlot(InstrumentReferent.ATTR_APPENDIX, null, true) === null) {
                    if (sub.children[0].kind === InstrumentKind.HEAD && sub.children[0].children.length > 1 && sub.children[0].children[0].kind === InstrumentKind.TYP) {
                        title.tag = sub;
                        return title;
                    }
                }
            }
        }
        let nT0 = null;
        for (; t !== null; t = t.next) {
            if (t.isTableControlChar) {
                if (t === tt0) {
                    if (t.isChar(String.fromCharCode(0x1E))) {
                        let rows = TableHelper.tryParseRows(t, 0, true, false);
                        if (rows !== null && rows.length > 2) 
                            break;
                        break;
                    }
                    tt0 = t.next;
                    continue;
                }
                break;
            }
            if (t.isNewlineBefore || t.previous.isTableControlChar) {
                if (FragToken._isStartOfBody(t, t === tt0)) 
                    break;
                if (FragToken._createApproved(t) !== null) 
                    break;
                if (FragToken._createEditions(t) !== null) 
                    break;
                if (t !== tt0 && t.whitespacesBeforeCount > 15) {
                    if (t.previous.isCommaAnd) 
                        continue;
                    if ((t instanceof TextToken) && t.lengthChar > 1 && t.chars.isAllLower) {
                    }
                    else if (t.isChar('(')) {
                    }
                    else {
                        if (DecreeToken.isKeyword(t.previous, false) === null) {
                            if (!t.previous.isValue("ОБРАЗЕЦ", "ЗРАЗОК")) 
                                break;
                        }
                        if (t.whitespacesBeforeCount > 25) 
                            break;
                    }
                }
                if (t.getReferent() instanceof InstrumentParticipantReferent) 
                    break;
                if (t.getReferent() instanceof OrganizationReferent) {
                    if (t.whitespacesBeforeCount > 15) 
                        break;
                }
                let dd = DecreeToken.tryAttach(t, null, false);
                if (dd !== null && ((dd.typ === DecreeTokenItemType.DATE || dd.typ === DecreeTokenItemType.TERR)) && dd.isNewlineAfter) {
                    let npt0 = null;
                    if (dd.typ === DecreeTokenItemType.TERR && (t instanceof ReferentToken)) 
                        npt0 = NounPhraseHelper.tryParse(t.beginToken, NounPhraseParseAttr.NO, 0, null);
                    if (npt0 !== null && !npt0.morph._case.isUndefined && !npt0.morph._case.isNominative) {
                    }
                    else {
                        FragToken._addTitleAttr(null, title, dd);
                        t = title.endToken = dd.endToken;
                        continue;
                    }
                }
                let ltt = InstrToken1.parse(t, true, null, 0, null, false, 0, true, false);
                if (ltt === null) 
                    break;
                if (ltt.numbers.length > 0) {
                    if (!ltt.isNumDoubt) 
                        break;
                    if (ltt.allUpper) {
                    }
                    else if (NumberHelper.tryParseNumberWithPostfix(t) !== null) {
                    }
                    else 
                        break;
                }
                if (ltt.typ === InstrToken1Types.APPROVED) {
                    title.children.push(FragToken._new2000(ltt.beginToken, ltt.beginToken, InstrumentKind.APPROVED));
                    if (ltt.beginToken !== ltt.endToken) 
                        title.children.push(FragToken._new2000(ltt.beginToken.next, ltt.endToken, InstrumentKind.DOCREFERENCE));
                    t = ltt.endToken;
                    if (ltt.beginToken === tt0) {
                        tt0 = t.next;
                        continue;
                    }
                    break;
                }
                if (ltt.hasVerb && !ltt.allUpper) {
                    if (t.chars.isLetter && t.chars.isAllLower) {
                    }
                    else if (t.getReferent() instanceof DecreeChangeReferent) {
                        let dch = Utils.as(t.getReferent(), DecreeChangeReferent);
                        if (dch.kind === DecreeChangeKind.CONTAINER && t.isValue("ИЗМЕНЕНИЕ", null)) {
                        }
                        else 
                            break;
                    }
                    else if (DecreeToken.isKeyword(t, false) !== null) {
                    }
                    else if ((t === tt0 && ltt.endToken.next !== null && ltt.endToken.next.isChar(String.fromCharCode(0x1E))) && !ltt.endToken.isChar(':')) {
                    }
                    else {
                        let npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
                        if ((npt !== null && npt.isNewlineBefore && npt.isNewlineAfter) && npt.chars.isAllUpper) {
                        }
                        else 
                            break;
                    }
                }
                if (ltt.typ === InstrToken1Types.DIRECTIVE) 
                    break;
                if (t.chars.isLetter && t !== tt0) {
                    if (!t.chars.isAllLower && !t.chars.isAllUpper) {
                        if (!(t.getReferent() instanceof OrganizationReferent) && !(t.getReferent() instanceof GeoReferent)) {
                            if (DecreeToken.isKeyword(t.previous, false) === null) {
                                let npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
                                if (npt !== null && npt.morph._case.isGenitive) {
                                }
                                else 
                                    break;
                            }
                        }
                    }
                }
                let hasWords = false;
                for (let ttt = ltt.beginToken; ttt !== null; ttt = ttt.next) {
                    if (ttt.beginChar > ltt.endChar) 
                        break;
                    if (ttt.chars.isCyrillicLetter) {
                        hasWords = true;
                        break;
                    }
                    let r = ttt.getReferent();
                    if ((r instanceof OrganizationReferent) || (r instanceof GeoReferent) || (r instanceof DecreeChangeReferent)) {
                        hasWords = true;
                        break;
                    }
                }
                if (!hasWords) 
                    break;
                let eds = FragToken._createEditions(t);
                if (eds !== null) {
                    if (t !== tt0) 
                        break;
                    title.children.push(eds);
                    t1 = (t = title.endToken = eds.endToken);
                    tt0 = t.next;
                    continue;
                }
                t1 = (t = ltt.endToken);
            }
            else 
                t1 = t;
        }
        let val = (t1 !== null && tt0 !== null ? FragToken.getRestoredName(tt0, t1, false) : null);
        if (val !== null) {
            if (nT0 !== null) 
                tt0 = nT0;
            title.children.push(FragToken._new2064(tt0, t1, InstrumentKind.NAME, val.trim()));
            title.endToken = t1;
            title.name = val;
        }
        while (title.endToken.next !== null) {
            let eds = FragToken._createEditions(title.endToken.next);
            if (eds !== null) {
                title.children.push(eds);
                title.endToken = eds.endToken;
                continue;
            }
            let appr = FragToken._createApproved(title.endToken.next);
            if (appr !== null) {
                title.children.push(appr);
                title.endToken = appr.endToken;
                continue;
            }
            let misc = FragToken._createMisc(title.endToken.next);
            if (misc !== null) {
                title.children.push(misc);
                title.endToken = misc.endToken;
                continue;
            }
            let ltt = InstrToken1.parse(title.endToken.next, true, null, 0, null, false, 0, false, false);
            if (ltt === null) 
                break;
            if (ltt.isPureHiphenLine) {
                t = title.endToken = ltt.endToken;
                continue;
            }
            if (ltt.typ === InstrToken1Types.FOOTNOTE) {
                let fnn = FragToken._new2000(ltt.beginToken, ltt.endToken, InstrumentKind.FOOTNOTE);
                NumberingHelper.createNumber(fnn, ltt);
                title.children.push(fnn);
                t = title.endToken = ltt.endToken;
                continue;
            }
            break;
        }
        if (isApp) {
            if (doc.findSlot(InstrumentReferent.ATTR_APPENDIX, null, true) === null) 
                doc.addSlot(InstrumentReferent.ATTR_APPENDIX, "", false, 0);
            for (const ch of title.children) {
                if (ch.kind === InstrumentKind.DOCREFERENCE) {
                    for (let tt = ch.beginToken; tt !== null && tt.endChar <= ch.endChar; tt = tt.next) {
                        if (tt.getReferent() instanceof DecreeReferent) {
                            for (const s of tt.getReferent().slots) {
                                if (s.typeName === DecreeReferent.ATTR_TYPE) 
                                    doc.addSlot(InstrumentReferent.ATTR_TYPE, s.value, false, 0);
                                else if (s.typeName === DecreeReferent.ATTR_NUMBER) 
                                    doc.addSlot(InstrumentReferent.ATTR_REGNUMBER, s.value, false, 0);
                                else if (s.typeName === DecreeReferent.ATTR_DATE) 
                                    doc.addSlot(InstrumentReferent.ATTR_DATE, s.value, false, 0);
                                else if (s.typeName === DecreeReferent.ATTR_SOURCE) 
                                    doc.addSlot(InstrumentReferent.ATTR_SOURCE, s.value, false, 0);
                                else if (s.typeName === DecreeReferent.ATTR_GEO) 
                                    doc.addSlot(InstrumentReferent.ATTR_GEO, s.value, false, 0);
                            }
                            break;
                        }
                        let dt = DecreeToken.tryAttach(tt, null, false);
                        if (dt !== null) {
                            if (FragToken._addTitleAttr(doc, null, dt)) 
                                tt = dt.endToken;
                        }
                    }
                    break;
                }
            }
        }
        if (title.children.length === 0 && title.endToken === title.beginToken) 
            return null;
        for (t1 = title.endToken.next; t1 !== null; t1 = t1.next) {
            let dt = DecreeToken.tryAttach(t1, null, false);
            if (dt !== null) {
                if (dt.typ === DecreeTokenItemType.DATE || dt.typ === DecreeTokenItemType.TERR) {
                    FragToken._addTitleAttr(null, title, dt);
                    t1 = title.endToken = dt.endToken;
                    continue;
                }
            }
            break;
        }
        while (title.endToken.next !== null) {
            if (title.endToken.next.isTableControlChar && ((!title.endToken.next.isNewlineBefore || title.endToken.next.isNewlineAfter || ((title.endToken.next.next !== null && title.endToken.next.next.isChar(String.fromCharCode(0x1F))))))) 
                title.endToken = title.endToken.next;
            else 
                break;
        }
        return title;
    }
    
    static _isStartOfBody(t, isAppTitle = false) {
        const InstrToken1 = require("./InstrToken1");
        if (t === null || !t.isNewlineBefore) 
            return false;
        if (t.isValue("ТАБЛИЦА", null) || t.isValue("РИСУНОК", null)) {
            let num = ComplexNumToken.tryParse(t.next, null, true, false);
            if (num !== null) 
                return true;
        }
        if (t.isValue("ФОРМА", null)) {
            let pp = PartToken.tryAttach(t, null, false, false);
            if (pp !== null && pp.values.length > 0) 
                return true;
        }
        if (!isAppTitle) {
            let bl = BlockTitleToken.tryAttach(t, false, null);
            if (bl !== null) {
                if (bl.typ !== BlkTyps.UNDEFINED && bl.typ !== BlkTyps.LITERATURE) 
                    return true;
            }
        }
        let li = MailLine.parse(t, 0, 0);
        if (li !== null) {
            if (li.typ === MailLineTypes.HELLO) 
                return true;
        }
        let it1 = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
        if (it1 !== null) {
            if (it1.typ === InstrToken1Types.INDEX) 
                return true;
        }
        let ok = false;
        if (t.isValue("ВВЕДЕНИЕ", "ВВЕДЕННЯ") || t.isValue("АННОТАЦИЯ", "АНОТАЦІЯ") || t.isValue("ПРЕДИСЛОВИЕ", "ПЕРЕДМОВА")) 
            ok = true;
        else if (t.isValue("ОБЩИЙ", "ЗАГАЛЬНИЙ") && t.next !== null && t.next.isValue("ПОЛОЖЕНИЕ", "ПОЛОЖЕННЯ")) {
            t = t.next;
            ok = true;
        }
        else if ((t.next !== null && t.next.chars.isAllLower && t.morph._class.isPreposition) && ((t.next.isValue("СВЯЗЬ", "ЗВЯЗОК") || t.next.isValue("ЦЕЛЬ", "МЕТА") || t.next.isValue("СООТВЕТСТВИЕ", "ВІДПОВІДНІСТЬ")))) 
            return true;
        if (ok) {
            let t1 = t.next;
            if (t1 !== null && t1.isChar(':')) 
                t1 = t1.next;
            if (t1 === null || t1.isNewlineBefore) 
                return true;
            return false;
        }
        let it = InstrToken1.parse(t, false, null, 0, null, false, 0, false, false);
        if (it !== null) {
            if (it.typContainerRank > 0 || it.typ === InstrToken1Types.DIRECTIVE) {
                if (t.isValue("ЧАСТЬ", "ЧАСТИНА") && it.numbers.length === 1) {
                    if (FragToken._createApproved(it.endToken.next) !== null) 
                        return false;
                }
                return true;
            }
            if (it.numbers.length > 0) {
                if (it.numbers.length > 1 || it.numSuffix !== null) 
                    return true;
            }
        }
        if ((t.getReferent() instanceof OrganizationReferent) && t.next !== null) {
            if (t.next.isValue("СОСТАВ", "СКЛАД")) 
                return true;
            if (t.next.isValue("В", "У") && t.next.next !== null && t.next.next.isValue("СОСТАВ", "СКЛАД")) 
                return true;
        }
        if (t.isValue2("В", "ЦЕЛЯХ")) 
            return true;
        let npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
        if (npt !== null && (npt.endToken.next instanceof TextToken) && npt.endToken.next.isPureVerb) 
            return true;
        return false;
    }
    
    static _addTitleAttr(doc, title, dt) {
        if (dt.typ === DecreeTokenItemType.TYP) {
            if (doc !== null) {
                if (doc.typ !== null && dt.value !== doc.typ) {
                    if (doc.typ !== "ПРОЕКТ") 
                        return false;
                    if (dt.value.includes("ЗАКОН")) 
                        doc.typ = "ПРОЕКТ ЗАКОНА";
                    else 
                        return false;
                }
                else 
                    doc.typ = dt.value;
                if (dt.fullValue !== null && dt.fullValue !== dt.value && doc.name === null) 
                    doc.name = dt.fullValue;
            }
            if (title !== null) 
                title.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.TYP, (dt.fullValue != null ? dt.fullValue : dt.value)));
        }
        else if (dt.typ === DecreeTokenItemType.NUMBER) {
            if (dt.isDelo) {
                if (doc !== null) {
                    doc.addSlot(InstrumentReferent.ATTR_CASENUMBER, dt.value, false, 0);
                    if (doc.regNumber === dt.value) 
                        doc.regNumber = null;
                }
                if (title !== null) 
                    title.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.CASENUMBER, dt.value));
            }
            else {
                if (dt.value !== "?" && doc !== null) {
                    if (doc.getStringValue(InstrumentReferent.ATTR_CASENUMBER) === dt.value) {
                    }
                    else 
                        doc.addSlot(InstrumentBlockReferent.ATTR_NUMBER, dt.value, false, 0);
                }
                if (title !== null) 
                    title.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.NUMBER, dt.value));
                if (doc !== null && doc.typ === null && dt.value !== null) {
                    if (LanguageHelper.endsWith(dt.value, "ФКЗ")) 
                        doc.typ = "ФЕДЕРАЛЬНЫЙ КОНСТИТУЦИОННЫЙ ЗАКОН";
                    else if (LanguageHelper.endsWith(dt.value, "ФЗ")) 
                        doc.typ = "ФЕДЕРАЛЬНЫЙ ЗАКОН";
                }
            }
        }
        else if (dt.typ === DecreeTokenItemType.NAME) {
            if (doc !== null) 
                doc.addSlot(InstrumentBlockReferent.ATTR_NAME, dt.value, false, 0);
            if (title !== null) 
                title.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.NAME, dt.value));
        }
        else if (dt.typ === DecreeTokenItemType.DATE) {
            if (doc === null || doc.addDate(dt)) {
                if (title !== null) 
                    title.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.DATE, dt));
            }
        }
        else if (dt.typ === DecreeTokenItemType.TERR) {
            if (title !== null) 
                title.children.push(FragToken._new2064(dt.beginToken, dt.endToken, InstrumentKind.PLACE, dt));
            if (doc !== null && dt.ref !== null) {
                let _geo = doc.getStringValue(InstrumentReferent.ATTR_GEO);
                if (_geo === "Россия") {
                    doc.addSlot(InstrumentReferent.ATTR_GEO, null, true, 0);
                    _geo = null;
                }
                if (_geo === null) {
                    let ss = doc.addSlot(InstrumentReferent.ATTR_GEO, dt.ref.referent.toString(), false, 0);
                    ss.addAnnotation(dt);
                }
            }
        }
        else if (dt.typ === DecreeTokenItemType.OWNER || dt.typ === DecreeTokenItemType.ORG) {
            if (title !== null) 
                title.children.push(FragToken._new2064(dt.beginToken, dt.endToken, (dt.typ === DecreeTokenItemType.ORG ? InstrumentKind.ORGANIZATION : InstrumentKind.INITIATOR), dt));
            if (doc !== null) {
                if (dt.ref !== null) {
                    let ss = doc.addSlot(InstrumentReferent.ATTR_SOURCE, dt.ref.referent, false, 0);
                    ss.tag = dt.getSourceText();
                    ss.addAnnotation(dt);
                    if (dt.ref.referent instanceof PersonPropertyReferent) 
                        doc.addExtReferent(dt.ref);
                }
                else {
                    let ss = doc.addSlot(InstrumentReferent.ATTR_SOURCE, MiscHelper.convertFirstCharUpperAndOtherLower(dt.value), false, 0);
                    ss.tag = dt.getSourceText();
                    ss.addAnnotation(dt);
                }
            }
        }
        else 
            return false;
        return true;
    }
    
    static createZapiskaTitle(t0, doc) {
        const InstrToken1 = require("./InstrToken1");
        let cou = 0;
        for (let t = t0; t !== null && (cou < 30); t = t.next,cou++) {
            let li = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
            if (li === null) 
                break;
            if (li.numbers.length > 0) 
                break;
            let ok = false;
            let npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null && npt.endToken === li.endToken) {
                for (const kv of FragToken.m_ZapiskaKeywords) {
                    if (npt.endToken.isValue(kv, null)) {
                        ok = true;
                        break;
                    }
                }
            }
            if (t.isValue("ОТВЕТ", null)) {
                if (t.isNewlineAfter) 
                    ok = true;
                else if (t.next !== null && t.next.isValue("НА", null)) 
                    ok = true;
            }
            if (ok) {
                let res = FragToken._new2000(t0, li.endToken, InstrumentKind.HEAD);
                if (li.beginToken !== t0) {
                    let hh = FragToken._new2000(t0, li.beginToken.previous, InstrumentKind.APPROVED);
                    res.children.push(hh);
                }
                res.children.push(FragToken._new2029(li.beginToken, li.endToken, InstrumentKind.KEYWORD, true));
                return res;
            }
            t = li.endToken;
        }
        return null;
    }
    
    static createContractTitle(t0, doc) {
        const InstrToken1 = require("./InstrToken1");
        if (t0 === null) 
            return null;
        let isContract = false;
        while ((t0 instanceof TextToken) && t0.next !== null) {
            if (t0.isTableControlChar || !t0.chars.isLetter) 
                t0 = t0.next;
            else 
                break;
        }
        let dt0 = DecreeToken.tryAttach(t0, null, false);
        if (dt0 !== null && dt0.typ === DecreeTokenItemType.TYP) 
            isContract = (dt0.value.includes("ДОГОВОР") || dt0.value.includes("ДОГОВІР") || dt0.value.includes("КОНТРАКТ")) || dt0.value.includes("СОГЛАШЕНИЕ") || dt0.value.includes("УГОДА");
        let cou = 0;
        let t = null;
        let par1 = null;
        for (t = t0; t !== null; t = t.next) {
            if (t instanceof ReferentToken) {
                let rtt = Utils.as(t, ReferentToken);
                if (rtt.beginToken === rtt.endToken) {
                    let r = t.getReferent();
                    if (r instanceof PersonPropertyReferent) {
                        let str = r.toString();
                        if (str.includes("директор") || str.includes("начальник")) {
                        }
                        else 
                            t = t.kit.debedToken(t);
                    }
                    else if ((r instanceof PersonReferent) && (rtt.beginToken.getReferent() instanceof PersonPropertyReferent)) {
                        let str = rtt.beginToken.getReferent().toString();
                        if (str.includes("директор") || str.includes("начальник")) {
                        }
                        else {
                            t = t.kit.debedToken(t);
                            t = t.kit.debedToken(t);
                        }
                    }
                }
            }
        }
        let newlines = 0;
        let types = 0;
        for (t = t0; t !== null && (cou < 300); t = t.next,cou++) {
            if (t.isChar('_')) {
                cou--;
                continue;
            }
            if (t.isNewlineBefore) {
                newlines++;
                if (newlines > 10) 
                    break;
                while (t.isTableControlChar && t.next !== null) {
                    t = t.next;
                }
                let dt = DecreeToken.tryAttach(t, null, false);
                if (dt !== null && dt.typ === DecreeTokenItemType.TYP) {
                    if (((((dt.value === "ОПРЕДЕЛЕНИЕ" || dt.value === "ПОСТАНОВЛЕНИЕ" || dt.value === "РЕШЕНИЕ") || dt.value === "ПРИГОВОР" || dt.value === "ВИЗНАЧЕННЯ") || dt.value === "ПОСТАНОВА" || dt.value === "РІШЕННЯ") || dt.value === "ВИРОК" || dt.value.endsWith("ЗАЯВЛЕНИЕ")) || dt.value.endsWith("ЗАЯВА")) 
                        return null;
                    types++;
                }
                if (t.getReferent() instanceof OrganizationReferent) {
                    let ki = t.getReferent().kind;
                    if (ki === OrganizationKind.JUSTICE) 
                        return null;
                }
            }
            if (t.isValue("ДАЛЕЕ", null)) {
            }
            if (t.isNewlineAfter) 
                continue;
            par1 = ParticipantToken.tryAttach(t, null, null, isContract);
            if (par1 !== null && ((par1.kind === ParticipantTokenKinds.NAMEDAS || par1.kind === ParticipantTokenKinds.NAMEDASPARTS))) {
                t = par1.endToken.next;
                break;
            }
            par1 = null;
        }
        if (par1 === null) 
            return null;
        let par2 = null;
        cou = 0;
        for (; t !== null && (cou < 100); t = t.next,cou++) {
            if (par1.kind === ParticipantTokenKinds.NAMEDASPARTS) 
                break;
            if (t.isChar('_')) {
                cou--;
                continue;
            }
            if (t.isChar('(')) {
                let br2 = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                if (br2 !== null) {
                    t = br2.endToken;
                    continue;
                }
            }
            if (t.isAnd) {
            }
            par2 = ParticipantToken.tryAttach(t, null, null, true);
            if (par2 !== null) {
                if (par2.kind === ParticipantTokenKinds.NAMEDAS && par2.typ !== par1.typ) 
                    break;
                if (par2.kind === ParticipantTokenKinds.PURE && par2.typ !== par1.typ) {
                    if (t.previous.isAnd) 
                        break;
                }
                t = par2.endToken;
            }
            par2 = null;
        }
        if (par1 !== null && par2 !== null && ((par1.typ === null || par2.typ === null))) {
            let stat = new Hashtable();
            for (let tt = t; tt !== null; tt = tt.next) {
                let ttt = tt;
                if (tt instanceof MetaToken) 
                    ttt = tt.beginToken;
                let tok = ParticipantToken.m_Ontology.tryParse(ttt, TerminParseAttr.NO);
                if (tok === null || tok.termin.tag === null) 
                    continue;
                let key = tok.termin.canonicText;
                if (key === par1.typ || key === par2.typ || key === "СТОРОНА") 
                    continue;
                if (!stat.containsKey(key)) 
                    stat.put(key, 1);
                else 
                    stat.put(key, stat.get(key) + 1);
            }
            let max = 0;
            let bestTyp = null;
            for (const kp of stat.entries) {
                if (kp.value > max) {
                    max = kp.value;
                    bestTyp = kp.key;
                }
            }
            if (bestTyp !== null) {
                if (par1.typ === null) 
                    par1.typ = bestTyp;
                else if (par2.typ === null) 
                    par2.typ = bestTyp;
            }
        }
        let contrTyps = ParticipantToken.getDocTypes(par1.typ, (par2 === null ? null : par2.typ));
        let t1 = par1.beginToken.previous;
        let lastT1 = null;
        for (; t1 !== null && t1.beginChar >= t0.beginChar; t1 = t1.previous) {
            if (t1.isNewlineAfter) {
                lastT1 = t1;
                if (t1.isChar(',')) 
                    continue;
                if (t1.next === null) 
                    break;
                if (t1.next.chars.isLetter && t1.next.chars.isAllLower) 
                    continue;
                break;
            }
        }
        if (t1 === null) 
            t1 = lastT1;
        if (t1 === null) 
            return null;
        let p1 = InstrumentParticipantReferent._new2166(par1.typ);
        if (par1.parts !== null) {
            for (const p of par1.parts) {
                p1.addSlot(InstrumentParticipantReferent.ATTR_REF, p, false, 0);
            }
        }
        let p2 = null;
        let allParts = new Array();
        allParts.push(p1);
        if (par1.kind === ParticipantTokenKinds.NAMEDASPARTS) {
            p1.typ = "СТОРОНА 1";
            p1.addSlot(InstrumentParticipantReferent.ATTR_REF, par1.parts[0], false, 0);
            for (let ii = 1; ii < par1.parts.length; ii++) {
                let pp = InstrumentParticipantReferent._new2166(("СТОРОНА " + (ii + 1)));
                pp.addSlot(InstrumentParticipantReferent.ATTR_REF, par1.parts[ii], false, 0);
                if (ii === 1) 
                    p2 = pp;
                allParts.push(pp);
            }
            for (const pp of par1.parts) {
                doc.addSlot(InstrumentReferent.ATTR_SOURCE, pp, false, 0);
            }
        }
        let title = FragToken._new2000(t0, t0, InstrumentKind.HEAD);
        let add = false;
        let namBeg = null;
        let namEnd = null;
        let dttyp = null;
        let dt00 = null;
        let namBeg2 = null;
        let namEnd2 = null;
        for (t = t0; t !== null && t.endChar <= t1.endChar; t = t.next) {
            if (t.getReferent() instanceof DecreeReferent) {
                if (t.isNewlineBefore || ((t.previous !== null && t.previous.isTableControlChar))) {
                    if (t.previous !== null && ((t.previous.isValue("ПРИНЯТ", null) || t.previous.isValue("ДЕЙСТВИЕ", null)))) {
                    }
                    else 
                        t = t.kit.debedToken(t);
                }
            }
            let newLineBef = t.isNewlineBefore;
            if (t.previous !== null && t.previous.isTableControlChar) 
                newLineBef = true;
            let dt = DecreeToken.tryAttach(t, dt00, false);
            if (dt !== null) {
                dt00 = dt;
                if ((dt.typ === DecreeTokenItemType.DATE || dt.typ === DecreeTokenItemType.NUMBER || ((dt.typ === DecreeTokenItemType.TYP && newLineBef))) || ((dt.typ === DecreeTokenItemType.TERR && newLineBef))) {
                    if (namBeg !== null && namEnd === null) 
                        namEnd = t.previous;
                    if (namBeg2 !== null && namEnd2 === null) 
                        namEnd2 = t.previous;
                    if (((dt.typ === DecreeTokenItemType.TYP && doc.typ !== null && !doc.typ.includes("ДОГОВОР")) && !doc.typ.includes("ДОГОВІР") && !isContract) && dt.value !== null && ((dt.value.includes("ДОГОВОР") || dt.value.includes("ДОГОВІР")))) {
                        doc.typ = null;
                        doc.number = 0;
                        doc.regNumber = null;
                        isContract = true;
                        namBeg = (namEnd = null);
                        title.children.splice(0, title.children.length);
                    }
                    FragToken._addTitleAttr(doc, title, dt);
                    title.endToken = (t = dt.endToken);
                    if (dt.typ === DecreeTokenItemType.TYP) 
                        dttyp = dt.value;
                    add = true;
                    continue;
                }
            }
            dt00 = null;
            if (newLineBef && t !== t0) {
                let edss = FragToken._createEditions(t);
                if (edss !== null) {
                    if (namBeg !== null && namEnd === null) 
                        namEnd = t.previous;
                    if (namBeg2 !== null && namEnd2 === null) 
                        namEnd2 = t.previous;
                    title.children.push(edss);
                    title.endToken = edss.endToken;
                    break;
                }
                if (t instanceof NumberToken) {
                    let cnum = ComplexNumToken.tryParse(t, null, false, false);
                    if (cnum !== null && cnum.nums.length === 1 && cnum.suffix !== null) {
                        title.endToken = t.previous;
                        if (namBeg !== null && namEnd === null) 
                            namEnd = t.previous;
                        if (namBeg2 !== null && namEnd2 === null) 
                            namEnd2 = t.previous;
                        break;
                    }
                }
                if ((t.isValue("О", "ПРО") || t.isValue("ОБ", null) || t.isValue("НА", null)) || t.isValue("ПО", null)) {
                    if (namBeg === null) {
                        namBeg = t;
                        continue;
                    }
                    else if (namBeg2 === null && namEnd !== null) {
                        namBeg2 = t;
                        continue;
                    }
                }
                if (add) 
                    title.endToken = t.previous;
                add = false;
                let r = t.getReferent();
                if ((r instanceof GeoReferent) || (r instanceof DateReferent) || (r instanceof DecreeReferent)) {
                    if (namBeg !== null && namEnd === null) 
                        namEnd = t.previous;
                    if (namBeg2 !== null && namEnd2 === null) 
                        namEnd2 = t.previous;
                }
            }
            if ((dttyp !== null && namBeg === null && t.chars.isCyrillicLetter) && (t instanceof TextToken)) {
                if (t.isValue("МЕЖДУ", "МІЖ")) {
                    let pp = ParticipantToken.tryAttachToExist(t.next, p1, p2);
                    if (pp !== null && pp.endToken.next !== null && pp.endToken.next.isAnd) {
                        let pp2 = ParticipantToken.tryAttachToExist(pp.endToken.next.next, p1, p2);
                        if (pp2 !== null) {
                            let fr = FragToken._new2000(t, pp2.endToken, InstrumentKind.PLACE);
                            if (fr.referents === null) 
                                fr.referents = new Array();
                            fr.referents.push(pp.referent);
                            fr.referents.push(pp2.referent);
                            title.children.push(fr);
                            t = title.endToken = fr.endToken;
                            if (t.next !== null) {
                                if (t.next.isValue("О", "ПРО") || t.next.isValue("ОБ", null)) {
                                    namBeg = t.next;
                                    namEnd = null;
                                    namBeg2 = (namEnd2 = null);
                                }
                            }
                            continue;
                        }
                    }
                }
                namBeg = t;
            }
            else if (t.isValue("МЕЖДУ", "МІЖ") || t.isValue("ЗАКЛЮЧИТЬ", "УКЛАСТИ")) {
                if (namBeg !== null && namEnd === null) 
                    namEnd = t.previous;
                if (namBeg2 !== null && namEnd2 === null) 
                    namEnd2 = t.previous;
            }
            if (((newLineBef && t.whitespacesBeforeCount > 15)) || t.isTableControlChar) {
                if (namBeg !== null && namEnd === null && namBeg !== t) 
                    namEnd = t.previous;
                if (namBeg2 !== null && namEnd2 === null && namBeg2 !== t) 
                    namEnd2 = t.previous;
            }
        }
        if (namBeg !== null && namEnd === null && t1 !== null) 
            namEnd = t1;
        if (namBeg2 !== null && namEnd2 === null && t1 !== null) 
            namEnd2 = t1;
        if (namEnd !== null && namBeg !== null) {
            let val = MiscHelper.getTextValue(namBeg, namEnd, GetTextAttr.KEEPQUOTES);
            if (val !== null && val.length > 3) {
                let nam = FragToken._new2064(namBeg, namEnd, InstrumentKind.NAME, val);
                title.children.push(nam);
                title.sortChildren();
                if (namEnd.endChar > title.endChar) 
                    title.endToken = namEnd;
                if (dttyp !== null && !val.includes(dttyp)) 
                    val = (dttyp + " " + val);
                if (namBeg2 !== null && namEnd2 !== null) {
                    let val2 = MiscHelper.getTextValue(namBeg2, namEnd2, GetTextAttr.KEEPQUOTES);
                    if (val2 !== null && val2.length > 3) {
                        nam = FragToken._new2064(namBeg2, namEnd2, InstrumentKind.NAME, val2);
                        title.children.push(nam);
                        title.sortChildren();
                        if (namEnd2.endChar > title.endChar) 
                            title.endToken = namEnd2;
                        val = (val + " " + val2);
                    }
                }
                doc.name = val;
            }
        }
        if (title.children.length > 0 && title.children[0].beginChar > title.beginChar) 
            title.children.splice(0, 0, FragToken._new2000(title.beginToken, title.children[0].beginToken.previous, InstrumentKind.UNDEFINED));
        if (((doc.typ === "ДОГОВОР" || doc.typ === "ДОГОВІР")) && par1.kind !== ParticipantTokenKinds.NAMEDASPARTS) {
            if (title.children.length > 0 && title.children[0].kind === InstrumentKind.TYP) {
                let addi = null;
                for (const ch of title.children) {
                    if (ch.kind === InstrumentKind.NAME) {
                        if (ch.beginToken.morph._class.isPreposition) {
                            let npt = NounPhraseHelper.tryParse(ch.beginToken.next, NounPhraseParseAttr.NO, 0, null);
                            if (npt !== null) {
                                addi = npt.noun.getSourceText().toUpperCase();
                                let vvv = null;
                                try {
                                    vvv = MorphologyService.getAllWordforms(addi, null);
                                } catch (ex2173) {
                                }
                                if (vvv !== null) {
                                    for (const fi of vvv) {
                                        if (fi._case.isGenitive) {
                                            addi = fi.normalCase;
                                            if (addi.endsWith("НЬЯ")) 
                                                addi = addi.substring(0, 0 + addi.length - 2) + "ИЯ";
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            let npt = NounPhraseHelper.tryParse(ch.beginToken, NounPhraseParseAttr.NO, 0, null);
                            if (npt !== null && npt.endChar <= ch.endChar) 
                                addi = npt.noun.getSourceText().toUpperCase();
                        }
                        break;
                    }
                }
                if (addi !== null) {
                    if (addi.startsWith("ОКАЗАН")) 
                        addi = "УСЛУГ";
                    else if (addi.startsWith("НАДАН")) 
                        addi = "ПОСЛУГ";
                    doc.typ = (doc.typ + " " + addi);
                    if (doc.typ === doc.name) 
                        doc.name = null;
                }
                else if (contrTyps.length === 1) {
                    if (doc.typ === null || (doc.typ.length < contrTyps[0].length)) 
                        doc.typ = contrTyps[0];
                }
                else if (contrTyps.length > 0 && doc.typ === null) 
                    doc.typ = contrTyps[0];
            }
        }
        if (doc.typ === "ДОГОВОР УСЛУГ") 
            doc.typ = "ДОГОВОР ОКАЗАНИЯ УСЛУГ";
        if (doc.typ === "ДОГОВІР ПОСЛУГ") 
            doc.typ = "ДОГОВІР НАДАННЯ ПОСЛУГ";
        if (doc.typ === null && contrTyps.length > 0) 
            doc.typ = contrTyps[0];
        if (contrTyps.length === 0 && (title.lengthChar < 20)) 
            return null;
        let ad = t0.kit.getAnalyzerDataByAnalyzerName(InstrumentAnalyzer.ANALYZER_NAME);
        if (ad === null) 
            return null;
        doc.addSlot(InstrumentReferent.ATTR_PARTICIPANT, p1, false, 0);
        let rt = par1.attachFirst(p1, title.endChar + 1, (par2 === null ? 0 : par2.beginChar - 1));
        if (rt === null) 
            return null;
        if (par2 === null) {
            if (p1.slots.length < 2) 
                return null;
            if (!isContract) 
                return null;
            let tt2 = null;
            for (let ttt = rt.endToken.next; ttt !== null; ttt = ttt.next) {
                if (ttt.isComma || ttt.isAnd) 
                    continue;
                if (ttt.morph._class.isPreposition) 
                    continue;
                let npt = NounPhraseHelper.tryParse(ttt, NounPhraseParseAttr.PARSENUMERICASADJECTIVE, 0, null);
                if (npt !== null) {
                    if (npt.endToken.isValue("СТОРОНА", null)) {
                        ttt = npt.endToken;
                        continue;
                    }
                }
                tt2 = ttt;
                break;
            }
            if (tt2 !== null && par1 !== null) {
                let stat = new Hashtable();
                let cou1 = 0;
                for (let ttt = tt2; ttt !== null; ttt = ttt.next) {
                    if (ttt.isValue(par1.typ, null)) {
                        cou1++;
                        continue;
                    }
                    let tok = ParticipantToken.m_Ontology.tryParse(ttt, TerminParseAttr.NO);
                    if (tok !== null && tok.termin.tag !== null && tok.termin.canonicText !== "СТОРОНА") {
                        if (!stat.containsKey(tok.termin.canonicText)) 
                            stat.put(tok.termin.canonicText, 1);
                        else 
                            stat.put(tok.termin.canonicText, stat.get(tok.termin.canonicText) + 1);
                    }
                }
                let typ2 = null;
                if (cou1 > 10) {
                    let minCou = Math.floor(((cou1) * 0.6));
                    let maxCou = Math.floor(((cou1) * 1.4));
                    for (const kp of stat.entries) {
                        if (kp.value >= minCou && kp.value <= maxCou) {
                            typ2 = kp.key;
                            break;
                        }
                    }
                }
                if (typ2 !== null) 
                    par2 = ParticipantToken._new2174(tt2, tt2, typ2);
            }
        }
        rt.referent = (p1 = Utils.as(ad.registerReferent(p1), InstrumentParticipantReferent));
        t0.kit.embedToken(rt);
        if (par2 !== null) {
            p2 = InstrumentParticipantReferent._new2166(par2.typ);
            if (par2.parts !== null) {
                for (const p of par2.parts) {
                    p2.addSlot(InstrumentParticipantReferent.ATTR_REF, p, false, 0);
                }
            }
            p2 = Utils.as(ad.registerReferent(p2), InstrumentParticipantReferent);
            doc.addSlot(InstrumentReferent.ATTR_PARTICIPANT, p2, false, 0);
            rt = par2.attachFirst(p2, rt.endChar + 1, 0);
            if (rt === null) 
                return title;
            t0.kit.embedToken(rt);
        }
        else if (allParts.length > 1) {
            for (const pp of allParts) {
                let ppp = Utils.as(ad.registerReferent(pp), InstrumentParticipantReferent);
                doc.addSlot(InstrumentReferent.ATTR_PARTICIPANT, ppp, false, 0);
                if (pp === allParts[1]) 
                    p2 = ppp;
            }
        }
        let reqRegim = 0;
        for (t = rt.next; t !== null; t = (t === null ? null : t.next)) {
            if (t.beginChar >= 712 && (t.beginChar < 740)) {
            }
            if (t.isNewlineBefore) {
                let ii = InstrToken1.parse(t, true, null, 0, null, false, 0, true, false);
                if (ii !== null && ii.titleTyp === InstrToken1StdTitleType.REQUISITES) {
                    reqRegim = 5;
                    t = ii.endToken;
                    continue;
                }
            }
            if (t.isValue("ПРИЛОЖЕНИЕ", null) && t.isNewlineBefore) {
            }
            if (reqRegim === 5 && t.isChar(String.fromCharCode(0x1E))) {
                let rows = TableHelper.tryParseRows(t, 0, true, false);
                if (rows !== null && rows.length > 0 && ((rows[0].cells.length === 2 || rows[0].cells.length === 3))) {
                    let i0 = rows[0].cells.length - 2;
                    let rt0 = ParticipantToken.tryAttachToExist(rows[0].cells[i0].beginToken, p1, p2);
                    let rt1 = ParticipantToken.tryAttachToExist(rows[0].cells[i0 + 1].beginToken, p1, p2);
                    if (rt0 !== null && rt1 !== null && rt1.referent !== rt0.referent) {
                        for (let ii = 0; ii < rows.length; ii++) {
                            if (rows[ii].cells.length === rows[0].cells.length) {
                                rt = ParticipantToken.tryAttachRequisites(rows[ii].cells[i0].beginToken, Utils.as(rt0.referent, InstrumentParticipantReferent), Utils.as(rt1.referent, InstrumentParticipantReferent), false);
                                if (rt !== null && rt.endChar <= rows[ii].cells[i0].endChar) 
                                    t0.kit.embedToken(rt);
                                rt = ParticipantToken.tryAttachRequisites(rows[ii].cells[i0 + 1].beginToken, Utils.as(rt1.referent, InstrumentParticipantReferent), Utils.as(rt0.referent, InstrumentParticipantReferent), false);
                                if (rt !== null && rt.endChar <= rows[ii].cells[i0 + 1].endChar) 
                                    t0.kit.embedToken(rt);
                            }
                        }
                        t = rows[rows.length - 1].endToken;
                        reqRegim = 0;
                        continue;
                    }
                }
            }
            rt = ParticipantToken.tryAttachToExist(t, p1, p2);
            if (rt === null && reqRegim > 0) {
                for (let tt = t; tt !== null; tt = tt.next) {
                    if (tt.isTableControlChar) {
                    }
                    else if (tt.isCharOf(".)") || (tt instanceof NumberToken)) {
                    }
                    else {
                        rt = ParticipantToken.tryAttachToExist(tt, p1, p2);
                        if (rt !== null && !t.isTableControlChar) 
                            rt.beginToken = t;
                        break;
                    }
                }
            }
            if (rt === null) {
                reqRegim--;
                continue;
            }
            let ps = new Array();
            ps.push(Utils.as(rt.referent, InstrumentParticipantReferent));
            if (reqRegim > 0) {
                let rt1 = ParticipantToken.tryAttachRequisites(rt.endToken.next, ps[0], (ps[0] === p1 ? p2 : p1), false);
                if (rt1 !== null) 
                    rt.endToken = rt1.endToken;
            }
            t0.kit.embedToken(rt);
            t = rt;
            if (reqRegim <= 0) {
                if (t.isNewlineBefore) {
                }
                else if (t.previous !== null && t.previous.isTableControlChar) {
                }
                else 
                    continue;
            }
            else {
            }
            if (rt.endToken.next !== null && rt.endToken.next.isTableControlChar && !rt.endToken.next.isChar(String.fromCharCode(0x1E))) {
                for (let tt = rt.endToken.next; tt !== null; tt = tt.next) {
                    if (tt.isTableControlChar) {
                    }
                    else if (tt.isCharOf(".)") || (tt instanceof NumberToken)) {
                    }
                    else {
                        let rt1 = ParticipantToken.tryAttachRequisites(tt, (ps[0] === p1 ? p2 : p1), ps[0], true);
                        if (rt1 !== null) {
                            ps.push(Utils.as(rt1.referent, InstrumentParticipantReferent));
                            t0.kit.embedToken(rt1);
                            t = rt1;
                        }
                        break;
                    }
                }
            }
            t = t.next;
            if (t === null) 
                break;
            while (t.isTableControlChar && t.next !== null) {
                t = t.next;
            }
            let cur = 0;
            for (; t !== null; t = t.next) {
                if (t.isTableControlChar && t.isChar(String.fromCharCode(0x1F))) {
                    reqRegim = 0;
                    break;
                }
                rt = ParticipantToken.tryAttachRequisites(t, ps[cur], (p1 === ps[cur] ? p2 : p1), reqRegim <= 0);
                if (rt !== null) {
                    reqRegim = 5;
                    t0.kit.embedToken(rt);
                    t = rt;
                }
                else {
                    t = t.previous;
                    break;
                }
                if (ps.length === 2 && t.next.isTableControlChar) {
                    let tt = t.next;
                    for (; tt !== null; tt = tt.next) {
                        if (tt.isTableControlChar && tt.isChar(String.fromCharCode(0x1F))) 
                            break;
                        if (tt.isTableControlChar) {
                            cur = 1 - cur;
                            if (TableHelper.isCellEnd(tt) && TableHelper.isRowEnd(tt.next)) 
                                tt = tt.next;
                            t = tt;
                            continue;
                        }
                        break;
                    }
                    continue;
                }
                if (t.isTableControlChar && ps.length === 2) {
                    if (TableHelper.isCellEnd(t) && TableHelper.isRowEnd(t.next)) 
                        t = t.next;
                    cur = 1 - cur;
                    continue;
                }
                if (!t.isNewlineAfter) 
                    continue;
                let it1 = InstrToken1.parse(t.next, true, null, 0, null, false, 0, false, false);
                if (it1 !== null) {
                    if (it1.allUpper || it1.titleTyp !== InstrToken1StdTitleType.UNDEFINED || it1.numbers.length > 0) 
                        break;
                }
            }
        }
        return title;
    }
    
    static createProjectTitle(t0, doc) {
        const InstrToken1 = require("./InstrToken1");
        if (t0 === null) 
            return null;
        let isProject = false;
        let isEntered = false;
        let isTyp = false;
        if (t0.isTableControlChar && t0.next !== null) 
            t0 = t0.next;
        let title = FragToken._new2000(t0, t0, InstrumentKind.HEAD);
        let t = null;
        for (t = t0; t !== null; t = t.next) {
            if (t.isTableControlChar) 
                continue;
            if (t.getReferent() instanceof DecreeReferent) 
                t = t.kit.debedToken(t);
            if ((t instanceof TextToken) && ((t.term === "ПРОЕКТ" || t.term === "ЗАКОНОПРОЕКТ"))) {
                if ((t.isValue("ПРОЕКТ", null) && t === t0 && (t.next instanceof ReferentToken)) && (t.next.getReferent() instanceof OrganizationReferent)) 
                    return null;
                isProject = true;
                title.children.push(FragToken._new2026(t, t, InstrumentKind.KEYWORD, true));
                doc.addSlot(InstrumentReferent.ATTR_TYPE, "ПРОЕКТ", false, 0);
                continue;
            }
            let tt = FragToken._attachProjectEnter(t);
            if (tt !== null) {
                isEntered = true;
                title.children.push(FragToken._new2000(t, tt, InstrumentKind.APPROVED));
                t = tt;
                continue;
            }
            tt = FragToken._attachProjectMisc(t);
            if (tt !== null) {
                title.children.push(FragToken._new2000(t, tt, (tt.isValue("ЧТЕНИЕ", "ЧИТАННЯ") ? InstrumentKind.EDITIONS : InstrumentKind.UNDEFINED)));
                t = tt;
                continue;
            }
            if (t.isNewlineBefore && (t.getReferent() instanceof DecreeReferent) && ((isProject || isEntered))) 
                t = t.kit.debedToken(t);
            let dt = DecreeToken.tryAttach(t, null, false);
            if (dt !== null) {
                if ((dt.typ === DecreeTokenItemType.DATE || dt.typ === DecreeTokenItemType.TYP || dt.typ === DecreeTokenItemType.TERR) || dt.typ === DecreeTokenItemType.NUMBER) {
                    if (FragToken._addTitleAttr(doc, title, dt)) {
                        if (dt.typ === DecreeTokenItemType.TYP) 
                            isTyp = true;
                        t = dt.endToken;
                        continue;
                    }
                }
            }
            break;
        }
        if (isProject) {
        }
        else if (isEntered && isTyp) {
        }
        else 
            return null;
        title.endToken = t.previous;
        let t00 = t;
        let t11 = null;
        let isBr = BracketHelper.canBeStartOfSequence(t00, false, false);
        for (t = t00; t !== null; t = t.next) {
            if (t.isNewlineAfter) {
                if (t.next !== null && t.next.chars.isAllLower) 
                    continue;
            }
            if (t.whitespacesAfterCount > 15) {
                t11 = t;
                break;
            }
            else if (t.isNewlineAfter && t.next !== null) {
                if (t.next.getMorphClassInDictionary().equals(MorphClass.VERB)) {
                    t11 = t;
                    break;
                }
                if (t.next.chars.isCapitalUpper && t.next.morph._class.isVerb) {
                    t11 = t;
                    break;
                }
            }
            if (t.isWhitespaceAfter && isBr && BracketHelper.canBeEndOfSequence(t, false, null, false)) {
                t11 = t;
                break;
            }
            if (!t.isNewlineBefore) 
                continue;
            let it = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
            if (it !== null && it.numbers.length > 0 && it.lastNumber === 1) {
                t11 = t.previous;
                break;
            }
        }
        if (t11 === null) 
            return null;
        let nam = FragToken._new2026(t00, t11, InstrumentKind.NAME, true);
        doc.addSlot(InstrumentBlockReferent.ATTR_NAME, nam.value, false, 0);
        title.children.push(nam);
        title.endToken = t11;
        let appr1 = FragToken._createApproved(t11.next);
        if (appr1 !== null) {
            title.children.push(appr1);
            title.endToken = appr1.endToken;
        }
        return title;
    }
    
    static _attachProjectMisc(t) {
        if (t === null) 
            return null;
        let br = false;
        if (t.isChar('(') && t.next !== null) {
            br = true;
            t = t.next;
        }
        if (t.morph._class.isPreposition) 
            t = t.next;
        if ((t instanceof NumberToken) && t.next !== null && t.next.isValue("ЧТЕНИЕ", "ЧИТАННЯ")) {
            t = t.next;
            if (br && t.next !== null && t.next.isChar(')')) 
                t = t.next;
            return t;
        }
        return null;
    }
    
    static _attachProjectEnter(t) {
        if (t === null) 
            return null;
        if (t.isValue("ВНОСИТЬ", "ВНОСИТИ") || t.isValue("ВНЕСТИ", null)) {
        }
        else 
            return null;
        let cou = 0;
        for (t = t.next; t !== null; t = t.next) {
            if (t.morph._class.isPreposition || t.morph._class.isConjunction) 
                continue;
            if (((t.isValue("ПЕРИОД", "ПЕРІОД") || t.isValue("РАССМОТРЕНИЕ", "РОЗГЛЯД") || t.isValue("ДЕПУТАТ", null)) || t.isValue("ПОЛНОМОЧИЕ", "ПОВНОВАЖЕННЯ") || t.isValue("ПЕРЕДАЧА", null)) || t.isValue("ИСПОЛНЕНИЕ", "ВИКОНАННЯ")) 
                continue;
            let r = t.getReferent();
            if (r instanceof OrganizationReferent) {
                if (cou > 0 && t.isNewlineBefore) 
                    return t.previous;
                cou++;
                continue;
            }
            if ((r instanceof PersonReferent) || (r instanceof PersonPropertyReferent)) {
                cou++;
                continue;
            }
            if (t.isNewlineBefore) 
                return t.previous;
        }
        return null;
    }
    
    static _createJusticeParticipants(title, doc) {
        let typ = doc.typ;
        let ok = ((((typ === "ПОСТАНОВЛЕНИЕ" || typ === "РЕШЕНИЕ" || typ === "ОПРЕДЕЛЕНИЕ") || typ === "ПРИГОВОР" || ((typ != null ? typ : "")).endsWith("ЗАЯВЛЕНИЕ")) || typ === "ПОСТАНОВА" || typ === "РІШЕННЯ") || typ === "ВИЗНАЧЕННЯ" || typ === "ВИРОК") || ((typ != null ? typ : "")).endsWith("ЗАЯВА");
        for (const s of doc.slots) {
            if (s.typeName === InstrumentReferent.ATTR_SOURCE && (s.value instanceof OrganizationReferent)) {
                let ki = s.value.kind;
                if (ki === OrganizationKind.JUSTICE) 
                    ok = true;
            }
            else if (s.typeName === InstrumentReferent.ATTR_CASENUMBER) 
                ok = true;
        }
        let pIst = null;
        let pOtv = null;
        let pZayav = null;
        let cou = 0;
        let t = null;
        let tmp = new StringBuilder();
        for (t = title.beginToken; t !== null && t.endChar <= title.endChar; t = t.next) {
            if (t.isNewlineBefore) {
            }
            else if (t.previous !== null && t.previous.isTableControlChar) {
            }
            else 
                continue;
            if (t.next !== null && ((t.next.isChar(':') || t.next.isTableControlChar))) {
                if (t.isValue("ЗАЯВИТЕЛЬ", "ЗАЯВНИК")) {
                    pZayav = FragToken._createJustParticipant(t.next, null);
                    if (pZayav !== null) {
                        pZayav.beginToken = t;
                        pZayav.referent.typ = "ЗАЯВИТЕЛЬ";
                    }
                }
                else if (t.isValue("ИСТЕЦ", "ПОЗИВАЧ")) {
                    pIst = FragToken._createJustParticipant(t.next, null);
                    if (pIst !== null) {
                        pIst.beginToken = t;
                        pIst.referent.typ = "ИСТЕЦ";
                    }
                }
                else if (t.isValue("ОТВЕТЧИК", "ВІДПОВІДАЧ") || t.isValue("ДОЛЖНИК", "БОРЖНИК")) {
                    pOtv = FragToken._createJustParticipant(t.next, null);
                    if (pOtv !== null) {
                        pOtv.beginToken = t;
                        pOtv.referent.typ = "ОТВЕТЧИК";
                    }
                }
            }
        }
        for (t = title.endToken.next; t !== null; t = t.next) {
            if ((++cou) > 1000) 
                break;
            if (t.isValue("ЗАЯВЛЕНИЕ", "ЗАЯВА")) {
            }
            else if (t.isValue("ИСК", "ПОЗОВ") && t.previous !== null && t.previous.morph._class.isPreposition) {
            }
            else 
                continue;
            if (t.next !== null && t.next.isChar('(')) {
                let br = BracketHelper.tryParse(t.next, BracketParseAttr.NO, 100);
                if (br !== null) 
                    t = br.endToken;
            }
            if (pIst !== null) 
                break;
            pIst = FragToken._createJustParticipant(t.next, (t.next.morph.language.isUa ? "ПОЗИВАЧ" : "ИСТЕЦ"));
            if (pIst === null) 
                break;
            t = pIst.endToken.next;
            if (t !== null && t.isChar(',')) 
                t = t.next;
            if (t === null) 
                break;
            if (pOtv !== null) 
                break;
            if (t.isValue("О", "ПРО") && t.next !== null && t.next.isValue("ПРИВЛЕЧЕНИЕ", "ЗАЛУЧЕННЯ")) {
                if (t.next.morph.language.isUa) 
                    tmp.append("ПРО ПРИТЯГНЕННЯ");
                else 
                    tmp.append("О ПРИВЛЕЧЕНИИ");
                t = t.next.next;
                pOtv = FragToken._createJustParticipant(t, (t.next.morph.language.isUa ? "ВІДПОВІДАЧ" : "ОТВЕТЧИК"));
            }
            else if (t.isValue("О", "ПРО") && t.next !== null && t.next.isValue("ПРИЗНАНИЕ", "ВИЗНАННЯ")) {
                if (t.next.morph.language.isUa) 
                    tmp.append("ПРО ВИЗНАННЯ");
                else 
                    tmp.append("О ПРИЗНАНИИ");
                t = t.next.next;
                pOtv = FragToken._createJustParticipant(t, (t.next.morph.language.isUa ? "ВІДПОВІДАЧ" : "ОТВЕТЧИК"));
            }
            else if (t.isValue("О", "ПРО") && t.next !== null && t.next.isValue("ВЗЫСКАНИЕ", "СТЯГНЕННЯ")) {
                if (t.next.morph.language.isUa) 
                    tmp.append("ПРО СТЯГНЕННЯ");
                else 
                    tmp.append("О ВЗЫСКАНИИ");
                t = t.next.next;
                if (t !== null && t.morph._class.isPreposition) 
                    t = t.next;
                pOtv = FragToken._createJustParticipant(t, (t.next.morph.language.isUa ? "ВІДПОВІДАЧ" : "ОТВЕТЧИК"));
            }
            else {
                if (t === null || !t.isValue("К", "ПРО")) 
                    break;
                pOtv = FragToken._createJustParticipant(t.next, (t.next.morph.language.isUa ? "ВІДПОВІДАЧ" : "ОТВЕТЧИК"));
            }
            if (pOtv !== null) 
                t = pOtv.endToken.next;
            break;
        }
        if (((pIst === null && pZayav === null)) || ((pOtv === null && tmp.length === 0))) 
            return;
        let ad = title.kit.getAnalyzerDataByAnalyzerName(InstrumentAnalyzer.ANALYZER_NAME);
        if (pZayav !== null) {
            pZayav.referent = ad.registerReferent(pZayav.referent);
            pZayav.kit.embedToken(pZayav);
            doc.addSlot(InstrumentReferent.ATTR_PARTICIPANT, pZayav.referent, false, 0);
        }
        if (pIst !== null) {
            pIst.referent = ad.registerReferent(pIst.referent);
            pIst.kit.embedToken(pIst);
            doc.addSlot(InstrumentReferent.ATTR_PARTICIPANT, pIst.referent, false, 0);
        }
        if (pOtv !== null) {
            pOtv.referent = ad.registerReferent(pOtv.referent);
            pOtv.kit.embedToken(pOtv);
            doc.addSlot(InstrumentReferent.ATTR_PARTICIPANT, pOtv.referent, false, 0);
        }
        if (t !== null && t.isChar(',')) 
            t = t.next;
        if (t === null) 
            return;
        let npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
        if (npt !== null && npt.endToken.isValue("ЛИЦО", "ОСОБА")) {
            t = npt.endToken.next;
            if (t !== null && t.isChar(':')) 
                t = t.next;
            for (; t !== null; t = t.next) {
                if (t.isChar(',')) 
                    continue;
                let tret = FragToken._createJustParticipant(t, (t.morph.language.isUa ? "ТРЕТЯ ОСОБА" : "ТРЕТЬЕ ЛИЦО"));
                if (tret === null) 
                    break;
                tret.referent = ad.registerReferent(tret.referent);
                tret.kit.embedToken(tret);
                doc.addSlot(InstrumentReferent.ATTR_PARTICIPANT, tret.referent, false, 0);
                t = tret;
            }
        }
        let tt00 = t;
        while (t !== null) {
            let t0 = t;
            if (!t.isValue("О", "ПРО") && !t.isValue("ОБ", null)) {
                if (tmp.length === 0) {
                    if (t !== tt00) 
                        break;
                    let cou2 = 0;
                    let hasIsk = true;
                    for (let tt = t.next; tt !== null && (cou2 < 140); tt = tt.next,cou2++) {
                        if (tt.isValue("ЗАЯВЛЕНИЕ", "ЗАЯВА") || tt.isValue("ИСК", "ПОЗОВ")) {
                            cou2 = 0;
                            hasIsk = true;
                        }
                        if ((hasIsk && ((tt.isValue("О", "ПРО") || tt.isValue("ОБ", null))) && tt.next.getMorphClassInDictionary().isNoun) && tt.next.morph._case.isPrepositional) {
                            tmp.append(MiscHelper.getTextValue(tt, tt.next, GetTextAttr.NO));
                            t0 = tt;
                            t = tt.next.next;
                            break;
                        }
                    }
                    if (tmp.length === 0 || t === null) 
                        break;
                }
            }
            let arefs = new Array();
            let t1 = null;
            for (; t !== null; t = t.next) {
                if (t.isNewlineBefore && t !== t0) {
                    if (t.whitespacesBeforeCount > 15) 
                        break;
                }
                if (t.isValue("ПРИ", "ЗА") && t.next !== null && t.next.isValue("УЧАСТИЕ", "УЧАСТЬ")) 
                    break;
                if (t.isValue("БЕЗ", null) && t.next !== null && t.next.isValue("ВЫЗОВ", null)) 
                    break;
                let r = t.getReferent();
                if (r !== null) {
                    if (r instanceof MoneyReferent) {
                        arefs.push(r);
                        if (t.previous !== null && t.previous.isValue("СУММА", "СУМА")) {
                        }
                        else 
                            tmp.append(" СУММЫ");
                        t1 = t;
                        continue;
                    }
                    if ((r instanceof DecreePartReferent) || (r instanceof DecreeReferent)) {
                        arefs.push(r);
                        if (t.previous !== null && t.previous.isValue("ПО", null)) 
                            tmp.length = tmp.length - 3;
                        t1 = t;
                        for (let tt = t.next; tt !== null; tt = tt.next) {
                            if (tt.isCommaAnd) 
                                continue;
                            r = tt.getReferent();
                            if ((r instanceof DecreePartReferent) || (r instanceof DecreeReferent)) {
                                arefs.push(r);
                                t1 = (t = tt);
                                continue;
                            }
                            break;
                        }
                        break;
                    }
                    if (r instanceof PersonReferent) 
                        continue;
                    break;
                }
                if (t.isCharOf(",.") || t.isHiphen) 
                    break;
                if (t instanceof TextToken) {
                    let term = t.term;
                    if (term === "ИП") 
                        continue;
                }
                if (t.isAnd) {
                    if (t.next === null) 
                        break;
                    if (t.next.isValue("О", "ПРО") || t.next.isValue("ОБ", null)) {
                        t = t.next;
                        break;
                    }
                }
                if (t.isNewlineAfter) {
                    if (t.next === null) {
                    }
                    else if (t.next.chars.isAllLower) {
                    }
                    else 
                        break;
                }
                if (t.isWhitespaceBefore && tmp.length > 0) 
                    tmp.append(' ');
                tmp.append(MiscHelper.getTextValue(t, t, GetTextAttr.NO));
                t1 = t;
            }
            if (tmp.length > 10 && t1 !== null) {
                let art = InstrumentArtefactReferent._new2181("предмет");
                let str = tmp.toString();
                str = Utils.replaceString(str, "В РАЗМЕРЕ СУММЫ", "СУММЫ").trim();
                if (str.endsWith("В РАЗМЕРЕ")) 
                    str = str.substring(0, 0 + str.length - 9) + "СУММЫ";
                if (str.endsWith("В СУММЕ")) 
                    str = str.substring(0, 0 + str.length - 7) + "СУММЫ";
                art.value = str;
                for (const a of arefs) {
                    art.addSlot(InstrumentArtefactReferent.ATTR_REF, a, false, 0);
                }
                let rta = new ReferentToken(art, t0, t1);
                rta.referent = ad.registerReferent(rta.referent);
                doc.addSlot(InstrumentReferent.ATTR_ARTEFACT, rta.referent, false, 0);
                rta.kit.embedToken(rta);
                tmp.length = 0;
            }
            else 
                break;
        }
        for (t = (pOtv === null ? t : pOtv.next); t !== null; t = t.next) {
            let rt = null;
            let checkDel = false;
            if (t.isValue("ИСТЕЦ", "ПОЗИВАЧ") && pIst !== null) {
                rt = new ReferentToken(pIst.referent, t, t);
                checkDel = true;
            }
            else if (t.isValue("ЗАЯВИТЕЛЬ", "ЗАЯВНИК") && pZayav !== null) {
                rt = new ReferentToken(pZayav.referent, t, t);
                checkDel = true;
            }
            else if (((t.isValue("ОТВЕТЧИК", "ВІДПОВІДАЧ") || t.isValue("ДОЛЖНИК", "БОРЖНИК"))) && pOtv !== null) {
                rt = new ReferentToken(pOtv.referent, t, t);
                checkDel = true;
            }
            else {
                let r = t.getReferent();
                if (!(r instanceof OrganizationReferent) && !(r instanceof PersonReferent)) 
                    continue;
                if (pIst !== null && pIst.referent.findSlot(InstrumentParticipantReferent.ATTR_REF, r, true) !== null) 
                    rt = new ReferentToken(pIst.referent, t, t);
                else if (pZayav !== null && pZayav.referent.findSlot(InstrumentParticipantReferent.ATTR_REF, r, true) !== null) 
                    rt = new ReferentToken(pZayav.referent, t, t);
                else if (pOtv !== null && pOtv.referent.findSlot(InstrumentParticipantReferent.ATTR_REF, r, true) !== null) 
                    rt = new ReferentToken(pOtv.referent, t, t);
            }
            if (rt === null) 
                continue;
            if (checkDel && t.previous !== null && t.previous.isValue("ОТ", null)) {
                let tt = t.previous;
                if (tt.previous !== null && tt.previous.isHiphen) 
                    tt = tt.previous;
                if (tt.isWhitespaceBefore) {
                    let tt1 = t.next;
                    if (tt1 !== null && ((tt1.isHiphen || tt1.isChar(':')))) 
                        tt1 = tt1.next;
                    if (tt1.getReferent() instanceof PersonReferent) {
                        rt.beginToken = tt;
                        rt.endToken = tt1;
                        rt.referent.addSlot(InstrumentParticipantReferent.ATTR_DELEGATE, Utils.as(tt1.getReferent(), PersonReferent), false, 0);
                    }
                }
            }
            if (rt !== null && rt.endToken.next !== null && rt.endToken.next.isChar('(')) {
                let tt = rt.endToken.next.next;
                if (tt !== null && tt.next !== null && tt.next.isChar(')')) {
                    if (tt.isValue("ИСТЕЦ", "ПОЗИВАЧ") && pIst !== null && rt.referent === pIst.referent) 
                        rt.endToken = tt.next;
                    else if (tt.isValue("ЗАЯВИТЕЛЬ", "ЗАЯВНИК") && pZayav !== null && rt.referent === pZayav.referent) 
                        rt.endToken = tt.next;
                    else if (((tt.isValue("ОТВЕТЧИК", "ВІДПОВІДАЧ") || tt.isValue("ДОЛЖНИК", "БОРЖНИК"))) && pOtv !== null && rt.referent === pOtv.referent) 
                        rt.endToken = tt.next;
                    else if ((tt.getReferent() instanceof PersonReferent) || (tt.getReferent() instanceof OrganizationReferent)) {
                        if (pIst !== null && rt.referent === pIst.referent) {
                            if (pIst.referent.findSlot(null, tt.getReferent(), true) !== null) 
                                rt.endToken = tt.next;
                            else if (pOtv !== null && pOtv.referent.findSlot(null, tt.getReferent(), true) === null) {
                                rt.endToken = tt.next;
                                pIst.referent.addSlot(InstrumentParticipantReferent.ATTR_REF, tt.getReferent(), false, 0);
                            }
                        }
                        else if (pOtv !== null && rt.referent === pOtv.referent) {
                            if (pOtv.referent.findSlot(null, tt.getReferent(), true) !== null) 
                                rt.endToken = tt.next;
                            else if (pIst !== null && pIst.referent.findSlot(null, tt.getReferent(), true) === null) {
                                rt.endToken = tt.next;
                                pOtv.referent.addSlot(InstrumentParticipantReferent.ATTR_REF, tt.getReferent(), false, 0);
                            }
                        }
                    }
                }
            }
            t.kit.embedToken(rt);
            t = rt;
        }
    }
    
    static _createJustParticipant(t, typ) {
        if (t === null) 
            return null;
        let r0 = null;
        let t0 = t;
        let t1 = t;
        let ok = false;
        let br = false;
        let refs = new Array();
        for (; t !== null; t = t.next) {
            if (t.isNewlineBefore && t !== t0) {
                if (t.whitespacesBeforeCount > 15) 
                    break;
            }
            if (t.isHiphen || t.isCharOf(":,") || t.isTableControlChar) 
                continue;
            if (!br) {
                if (t.isValue("К", null) || t.isValue("О", "ПРО")) 
                    break;
            }
            if (t.isChar('(')) {
                if (br) 
                    break;
                br = true;
                continue;
            }
            if (t.isChar(')') && br) {
                br = false;
                t1 = t;
                break;
            }
            let r = t.getReferent();
            if ((r instanceof PersonReferent) || (r instanceof OrganizationReferent)) {
                if (r0 === null) {
                    refs.push(r);
                    r0 = r;
                    t1 = t;
                    ok = true;
                    continue;
                }
                break;
            }
            if (r instanceof UriReferent) {
                let ur = Utils.as(r, UriReferent);
                if (ur.scheme === "ИНН" || ur.scheme === "ИИН" || ur.scheme === "ОГРН") 
                    ok = true;
                refs.push(r);
                t1 = t;
                continue;
            }
            if (!br) {
                if ((r instanceof DecreeReferent) || (r instanceof DecreePartReferent)) 
                    break;
            }
            if (r !== null || br) {
                if ((r instanceof PhoneReferent) || (r instanceof AddressReferent)) 
                    refs.push(r);
                t1 = t;
                continue;
            }
            if (BracketHelper.canBeStartOfSequence(t, true, false)) {
                let brr = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                if (brr !== null) {
                    ok = true;
                    t1 = (t = brr.endToken);
                    continue;
                }
            }
            if (t.previous.isComma && !br) 
                break;
            if (t.previous.morph._class.isPreposition && t.isValue("УЧАСТИЕ", "УЧАСТЬ")) 
                break;
            if ((t.previous instanceof NumberToken) && t.isValue("ЛИЦО", "ОСОБА")) 
                break;
            let npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null) {
                if ((npt.noun.isValue("УЧРЕЖДЕНИЕ", "УСТАНОВА") || npt.noun.isValue("ПРЕДПРИЯТИЕ", "ПІДПРИЄМСТВО") || npt.noun.isValue("ОРГАНИЗАЦИЯ", "ОРГАНІЗАЦІЯ")) || npt.noun.isValue("КОМПЛЕКС", null)) {
                    t1 = (t = npt.endToken);
                    ok = true;
                    continue;
                }
            }
            let ty = OrgItemTypeToken.tryAttach(t, true);
            if (ty !== null) {
                t1 = (t = ty.endToken);
                ok = true;
                continue;
            }
            if ((t instanceof TextToken) && t.chars.isCyrillicLetter && t.chars.isAllLower) {
                if (t.morph._class.equals(MorphClass.VERB) || t.morph._class.equals(MorphClass.ADVERB)) 
                    break;
            }
            if (t.isNewlineBefore && typ === null) 
                break;
            else if (!t.morph._class.isPreposition && !t.morph._class.isConjunction) 
                t1 = t;
            else if (t.isNewlineBefore) 
                break;
        }
        if (!ok) 
            return null;
        let pat = InstrumentParticipantReferent._new2166(typ);
        for (const r of refs) {
            pat.addSlot(InstrumentParticipantReferent.ATTR_REF, r, false, 0);
        }
        return new ReferentToken(pat, t0, t1);
    }
    
    _createJusticeResolution() {
        let ad = this.kit.getAnalyzerDataByAnalyzerName(InstrumentAnalyzer.ANALYZER_NAME);
        if (ad === null) 
            return;
        let res = this._findResolution();
        if (res === null) 
            return;
        for (const r of res) {
            for (let t = r.beginToken; t !== null && t.endChar <= r.endChar; t = t.next) {
                if (t === r.beginToken) {
                }
                else if (t.previous !== null && t.previous.isChar('.') && t.isWhitespaceBefore) {
                }
                else if (!t.isValue("ПРИЗНАТЬ", "ВИЗНАТИ")) 
                    continue;
                if (t.morph._class.isPreposition && t.next !== null) 
                    t = t.next;
                let arts = new Array();
                let tt = null;
                let te = null;
                if (t.isValue("ВЗЫСКАТЬ", "СТЯГНУТИ")) {
                    let gosposh = false;
                    let sum = null;
                    te = null;
                    for (tt = t.next; tt !== null && tt.endChar <= r.endChar; tt = tt.next) {
                        if (tt.morph._class.isPreposition) 
                            continue;
                        if (tt.isChar('.')) 
                            break;
                        if (tt.isValue("ТОМ", "ТОМУ") && tt.next !== null && tt.next.isValue("ЧИСЛО", null)) 
                            break;
                        if (tt.isValue("ГОСПОШЛИНА", "ДЕРЖМИТО")) 
                            gosposh = true;
                        else if (tt.isValue("ФЕДЕРАЛЬНЫЙ", "ФЕДЕРАЛЬНИЙ") && tt.next !== null && tt.next.isValue("БЮДЖЕТ", null)) 
                            gosposh = true;
                        if (tt.getReferent() instanceof MoneyReferent) {
                            te = tt;
                            sum = Utils.as(tt.getReferent(), MoneyReferent);
                        }
                    }
                    if (sum !== null) {
                        let art = InstrumentArtefactReferent._new2181("РЕЗОЛЮЦИЯ");
                        if (gosposh) 
                            art.value = "ВЗЫСКАТЬ ГОСПОШЛИНУ";
                        else 
                            art.value = "ВЗЫСКАТЬ СУММУ";
                        art.addSlot(InstrumentArtefactReferent.ATTR_REF, sum, false, 0);
                        arts.push(new ReferentToken(art, t, te));
                    }
                }
                if ((t.isValue("ЗАЯВЛЕНИЕ", "ЗАЯВА") || t.isValue("ИСК", "ПОЗОВ") || t.isValue("ТРЕБОВАНИЕ", "ВИМОГА")) || t.isValue("ЗАЯВЛЕННЫЙ", "ЗАЯВЛЕНИЙ") || t.isValue("УДОВЛЕТВОРЕНИЕ", "ЗАДОВОЛЕННЯ")) {
                    for (tt = t.next; tt !== null && tt.endChar <= r.endChar; tt = tt.next) {
                        if (tt.morph._class.isPreposition) 
                            continue;
                        if (tt.isChar('.')) {
                            if (tt.isWhitespaceAfter) 
                                break;
                        }
                        if (tt.isValue("УДОВЛЕТВОРИТЬ", "ЗАДОВОЛЬНИТИ")) {
                            let val = "УДОВЛЕТВОРИТЬ";
                            te = tt;
                            if (tt.next !== null && tt.next.isValue("ПОЛНОСТЬЮ", "ПОВНІСТЮ")) {
                                val += " ПОЛНОСТЬЮ";
                                te = tt.next;
                            }
                            else if (tt.previous !== null && tt.previous.isValue("ПОЛНОСТЬЮ", "ПОВНІСТЮ")) 
                                val += " ПОЛНОСТЬЮ";
                            let art = InstrumentArtefactReferent._new2181("РЕЗОЛЮЦИЯ");
                            art.value = val;
                            arts.push(new ReferentToken(art, t, te));
                            break;
                        }
                        if (tt.isValue("ОТКАЗАТЬ", "ВІДМОВИТИ")) {
                            let art = InstrumentArtefactReferent._new2181("РЕЗОЛЮЦИЯ");
                            art.value = "ОТКАЗАТЬ";
                            arts.push(new ReferentToken(art, t, (te = tt)));
                            break;
                        }
                    }
                }
                if (t.isValue("ПРИЗНАТЬ", "ВИЗНАТИ")) {
                    let zak = -1;
                    let otm = -1;
                    for (tt = t.next; tt !== null && tt.endChar <= r.endChar; tt = tt.next) {
                        if (tt.morph._class.isPreposition) 
                            continue;
                        if (tt.isChar('.')) 
                            break;
                        if (tt.isValue("НЕЗАКОННЫЙ", "НЕЗАКОННИЙ")) {
                            zak = 0;
                            te = tt;
                        }
                        else if (tt.isValue("ЗАКОННЫЙ", "ЗАКОННИЙ")) {
                            zak = 1;
                            te = tt;
                        }
                        else if (tt.isValue("ОТМЕНИТЬ", "СКАСУВАТИ")) {
                            otm = 1;
                            te = tt;
                        }
                    }
                    if (zak >= 0) {
                        let val = ("ПРИЗНАТЬ " + (zak > 0 ? "ЗАКОННЫМ" : "НЕЗАКОННЫМ"));
                        if (otm > 0) 
                            val += " И ОТМЕНИТЬ";
                        let art = InstrumentArtefactReferent._new2181("РЕЗОЛЮЦИЯ");
                        art.value = val;
                        arts.push(new ReferentToken(art, t, te));
                    }
                    else 
                        continue;
                }
                for (const rt of arts) {
                    rt.referent = ad.registerReferent(rt.referent);
                    this.m_Doc.addSlot(InstrumentReferent.ATTR_ARTEFACT, rt.referent, false, 0);
                    if (r.beginToken === rt.beginToken) 
                        r.beginToken = rt;
                    if (r.endToken === rt.endToken) 
                        r.endToken = rt;
                    this.kit.embedToken(rt);
                    t = rt;
                }
            }
        }
    }
    
    _findResolution() {
        if (this.kind === InstrumentKind.APPENDIX) 
            return null;
        let dir = false;
        let res = null;
        for (let i = 0; i < this.children.length; i++) {
            if (this.children[i].kind === InstrumentKind.DIRECTIVE && ((i + 1) < this.children.length)) {
                let v = this.children[i].value;
                if (v === null) 
                    continue;
                let s = v.toString();
                if ((((s === "РЕШЕНИЕ" || s === "ОПРЕДЕЛЕНИЕ" || s === "ПОСТАНОВЛЕНИЕ") || s === "ПРИГОВОР" || s === "РІШЕННЯ") || s === "ВИЗНАЧЕННЯ" || s === "ПОСТАНОВА") || s === "ВИРОК") {
                    let ii = i + 1;
                    for (let j = ii + 1; j < this.children.length; j++) {
                        ii = j;
                    }
                    if (res === null) 
                        res = new Array();
                    if (ii === (i + 1)) 
                        res.push(this.children[i + 1]);
                    else 
                        res.push(FragToken._new2000(this.children[i + 1].beginToken, this.children[ii].endToken, InstrumentKind.CONTENT));
                }
                else 
                    dir = true;
            }
        }
        if (res !== null) 
            return res;
        if (dir) 
            return null;
        for (const ch of this.children) {
            let re = ch._findResolution();
            if (re !== null) {
                if (res === null) 
                    res = re;
                else 
                    res.splice(res.length, 0, ...re);
            }
        }
        return res;
    }
    
    static __createActionQuestion(t, maxChar) {
        const InstrToken = require("./InstrToken");
        const InstrToken1 = require("./InstrToken1");
        let li = new Array();
        let ok = false;
        for (let tt = t; tt !== null; tt = tt.next) {
            let it = InstrToken.parse(tt, maxChar, null);
            if (it === null) 
                break;
            li.push(it);
            if (li.length > 5) 
                return null;
            if (it.typ === ILTypes.QUESTION) {
                ok = true;
                break;
            }
            tt = it.endToken;
        }
        if (!ok) 
            return null;
        let t1 = li[li.length - 1].endToken;
        let li2 = new Array();
        ok = false;
        for (let tt = t1.next; tt !== null; tt = tt.next) {
            if (!tt.isNewlineBefore) 
                continue;
            let it = InstrToken.parse(tt, maxChar, null);
            if (it === null) 
                break;
            li2.push(it);
            tt = it.endToken;
            if (it.typ !== ILTypes.TYP) 
                continue;
            let it1 = InstrToken1.parse(tt, true, null, 0, null, false, maxChar, false, false);
            if (it1 !== null && it1.hasVerb) {
                tt = it1.endToken;
                continue;
            }
            let tt2 = DecreeToken.isKeyword(it.beginToken, false);
            if (tt2 !== null && tt2 === it.endToken) {
                ok = true;
                break;
            }
        }
        if (!ok) 
            return null;
        let t2 = li2[li2.length - 1].beginToken;
        while (li2.length > 1 && li2[li2.length - 2].typ === ILTypes.ORGANIZATION) {
            t2 = li2[li2.length - 2].beginToken;
            li2.splice(li2.length - 1, 1);
        }
        let res = FragToken.createDocument(t2, maxChar, InstrumentKind.UNDEFINED);
        if (res === null) 
            return null;
        let ques = FragToken._new2000(t, t2.previous, InstrumentKind.QUESTION);
        res.children.splice(0, 0, ques);
        ques.children.push(FragToken._new2000(li[li.length - 1].beginToken, li[li.length - 1].endToken, InstrumentKind.KEYWORD));
        let content = FragToken._new2000(li[li.length - 1].endToken.next, t2.previous, InstrumentKind.CONTENT);
        ques.children.push(content);
        content._analizeContent(res, maxChar > 0, InstrumentKind.UNDEFINED);
        if (li.length > 1) {
            let fr = FragToken._new2029(t, li[li.length - 2].endToken, InstrumentKind.NAME, true);
            ques.children.splice(0, 0, fr);
        }
        res.beginToken = t;
        return res;
    }
    
    static createGostTitle(t0, doc) {
        const InstrToken1 = require("./InstrToken1");
        if (t0 === null) 
            return null;
        let ok = false;
        if (t0.isTableControlChar && t0.next !== null) 
            t0 = t0.next;
        let t = null;
        let cou = 0;
        for (t = t0; t !== null && (cou < 300); t = t.next,cou++) {
            let dr = Utils.as(t.getReferent(), DecreeReferent);
            if (dr !== null && t.isNewlineBefore) {
                if (dr.kind === DecreeKind.STANDARD) {
                    t = t.kit.debedToken(t);
                    if (t.beginChar === t0.beginChar) 
                        t0 = t;
                    ok = true;
                }
            }
            if (t.isNewlineBefore || ((t.previous !== null && t.previous.isTableControlChar))) {
                if (((t.isValue2("ГОСУДАРСТВЕННЫЙ", "СТАНДАРТ") || t.isValue2("НАЦИОНАЛЬНЫЙ", "СТАНДАРТ"))) && t.next.next !== null && (t.next.next.getReferent() instanceof GeoReferent)) {
                    ok = true;
                    break;
                }
            }
            if (t.isTableControlChar) 
                continue;
            if (t.isNewlineBefore || ((t.previous !== null && t.previous.isTableControlChar))) {
                if (FragToken._isStartOfBody(t, false)) 
                    break;
                let dt = DecreeToken.tryAttach(t, null, false);
                if (dt !== null) {
                    if (dt.typ === DecreeTokenItemType.TYP) {
                        if (dt.typKind === DecreeKind.STANDARD) 
                            ok = true;
                        break;
                    }
                }
            }
        }
        if (!ok) 
            return null;
        let title = FragToken._new2000(t0, t0, InstrumentKind.HEAD);
        cou = 0;
        let hasNum = false;
        let hasName = false;
        for (t = t0; t !== null && (cou < 100); t = t.next) {
            let appr1 = FragToken._createApproved(t);
            if (appr1 !== null) {
                t = appr1.endToken;
                title.children.push(appr1);
                title.endToken = appr1.endToken;
                continue;
            }
            let edss = FragToken._createEditions(t);
            if (edss !== null) {
                title.children.push(edss);
                t = title.endToken = edss.endToken;
                continue;
            }
            if (t.isNewlineBefore && t !== t0) {
                title.endToken = t.previous;
                if (t.isValue("ЧАСТЬ", null)) {
                    t = t.next;
                    let tt1 = MiscHelper.checkNumberPrefix(t);
                    if (tt1 !== null) 
                        t = tt1;
                    if (t instanceof NumberToken) {
                        let tmp = new StringBuilder();
                        for (; t !== null; t = t.next) {
                            if (t instanceof NumberToken) 
                                tmp.append(t.value);
                            else if (((t.isHiphen || t.isChar('.'))) && !t.isWhitespaceAfter && (t.next instanceof NumberToken)) 
                                tmp.append(t.term);
                            else 
                                break;
                            if (t.isWhitespaceAfter) 
                                break;
                        }
                        doc.addSlot(InstrumentReferent.ATTR_PART, tmp.toString(), true, 0);
                    }
                    continue;
                }
                if (FragToken._isStartOfBody(t, false)) 
                    break;
                cou++;
            }
            if (!hasNum) {
                let dr = Utils.as(t.getReferent(), DecreeReferent);
                if (dr !== null && dr.kind === DecreeKind.STANDARD) 
                    t = t.kit.debedToken(t);
            }
            title.endToken = t;
            let dt = DecreeToken.tryAttach(t, null, false);
            if (dt === null) 
                continue;
            if (dt.typ === DecreeTokenItemType.TYP) {
                if (dt.typKind !== DecreeKind.STANDARD) 
                    continue;
                FragToken._addTitleAttr(doc, title, dt);
                t = dt.endToken;
                if (dt.srcRef !== null) {
                    hasName = true;
                    let _name = MiscHelper.getTextValueOfMetaToken(dt, GetTextAttr.RESTOREREGISTER);
                    doc.addSlot(DecreeReferent.ATTR_NAME, _name, false, 0);
                    title.children[title.children.length - 1].kind = InstrumentKind.NAME;
                    title.children[title.children.length - 1].value = _name;
                }
                if (!hasNum) {
                    let num = DecreeToken.tryAttach(t.next, dt, false);
                    if (num !== null && num.typ === DecreeTokenItemType.NUMBER) {
                        FragToken._addTitleAttr(doc, title, num);
                        if (num.numYear > 0) 
                            doc.addSlot(InstrumentReferent.ATTR_DATE, num.numYear, false, 0);
                        t = dt.endToken;
                        hasNum = true;
                        continue;
                    }
                }
                if ((!hasName && t.isNewlineAfter && (t.next instanceof TextToken)) && t.next.lengthChar > 3 && t.next.chars.isCyrillicLetter) {
                    let nam = DecreeToken.tryAttachNameToEndOfLine(t.next, true);
                    if (nam !== null && nam.lengthChar > 20) {
                        for (let tt = nam.endToken.next; tt !== null; tt = tt.next) {
                            if (!(tt instanceof TextToken)) 
                                break;
                            if (tt.chars.isLatinLetter) 
                                break;
                            let nam2 = DecreeToken.tryAttachNameToEndOfLine(tt, true);
                            if (nam2 === null || (nam2.lengthChar < 20)) 
                                break;
                            nam.value = (nam.value + ". " + nam2.value);
                            tt = nam.endToken = nam2.endToken;
                        }
                        FragToken._addTitleAttr(doc, title, nam);
                        t = nam.endToken;
                        hasName = true;
                        continue;
                    }
                }
                continue;
            }
        }
        title.tag = DecreeKind.STANDARD;
        let empty = null;
        for (t = title.endToken.next; t !== null; t = t.next) {
            if (t.beginChar > 10000) 
                break;
            if (t.isNewlineBefore && t.isValue("ПРЕДИСЛОВИЕ", null) && t.isNewlineAfter) {
                empty = FragToken._new2000(t, t, InstrumentKind.IGNORED);
                title.children.push(empty);
            }
            let li = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
            if (li === null) 
                break;
            if (li.value !== null) {
                if (li.value.startsWith("ОБЛАСТЬ ПРИМЕНЕНИЯ") || li.value === "СОДЕРЖАНИЕ") {
                    title.endToken = t.previous;
                    break;
                }
            }
            if (t.isValue("СОДЕРЖАНИЕ", null) && t.isNewlineAfter) {
                title.endToken = t.previous;
                break;
            }
            t = li.endToken;
        }
        if (empty !== null) 
            empty.endToken = title.endToken;
        return title;
    }
    
    _analizeContent(topDoc, isCitat, rootKind = InstrumentKind.UNDEFINED) {
        const ContentAnalyzeWhapper = require("./ContentAnalyzeWhapper");
        this.kind = InstrumentKind.CONTENT;
        if (this.beginToken.previous !== null && this.beginToken.previous.isChar(String.fromCharCode(0x1E))) 
            this.beginToken = this.beginToken.previous;
        let wr = new ContentAnalyzeWhapper();
        wr.analyze(this, topDoc, isCitat, rootKind);
        for (const ch of topDoc.children) {
            if (ch.kind === InstrumentKind.HEAD) {
                for (const chh of ch.children) {
                    if (chh.kind === InstrumentKind.EDITIONS && chh.referents !== null) {
                        if (topDoc.referents === null) 
                            topDoc.referents = new Array();
                        for (const r of chh.referents) {
                            if (!topDoc.referents.includes(r)) 
                                topDoc.referents.push(r);
                        }
                    }
                }
            }
        }
    }
    
    static createTZTitle(t0, doc) {
        let tz = null;
        let cou = 0;
        let t = null;
        for (t = t0; t !== null && (cou < 300); t = t.next) {
            if ((t instanceof TextToken) && t.lengthChar > 1) 
                cou++;
            if (!t.isNewlineBefore) {
                if (t.previous !== null && t.previous.isTableControlChar) {
                }
                else 
                    continue;
            }
            let dt = DecreeToken.tryAttach(t, null, false);
            if (dt !== null && dt.typ === DecreeTokenItemType.TYP) {
                if (dt.value === "ТЕХНИЧЕСКОЕ ЗАДАНИЕ") 
                    tz = dt;
                break;
            }
        }
        if (tz === null) 
            return null;
        let title = FragToken._new2000(t0, tz.endToken, InstrumentKind.HEAD);
        for (t = t0; t !== null; t = t.next) {
            if (!t.isNewlineBefore) {
                title.endToken = t;
                continue;
            }
            if (FragToken._isStartOfBody(t, false)) 
                break;
            if (t.isValue("СОДЕРЖИМОЕ", null) || t.isValue("СОДЕРЖАНИЕ", null) || t.isValue("ОГЛАВЛЕНИЕ", null)) 
                break;
            let dt = DecreeToken.tryAttach(t, null, false);
            if (dt !== null) {
                FragToken._addTitleAttr(doc, title, dt);
                title.endToken = (t = dt.endToken);
                if (dt.typ !== DecreeTokenItemType.TYP) 
                    continue;
                let br = BracketHelper.tryParse(t.next, BracketParseAttr.CANBEMANYLINES, 100);
                if (br !== null && BracketHelper.isBracket(t.next, true)) {
                    let nam = FragToken._new2029(br.beginToken, br.endToken, InstrumentKind.NAME, true);
                    title.children.push(nam);
                    title.endToken = (t = br.endToken);
                    continue;
                }
                if (t.next !== null && t.next.isValue("НА", null)) {
                    let t1 = t.next;
                    for (let tt = t1.next; tt !== null; tt = tt.next) {
                        if (tt.isNewlineBefore) {
                            if (MiscHelper.canBeStartOfSentence(tt)) 
                                break;
                            if (tt.isValue("СОДЕРЖИМОЕ", null) || tt.isValue("СОДЕРЖАНИЕ", null) || tt.isValue("ОГЛАВЛЕНИЕ", null)) 
                                break;
                        }
                        let br1 = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                        if (br1 !== null) {
                            t1 = (tt = br1.endToken);
                            continue;
                        }
                        let npt = NounPhraseHelper.tryParse(tt, NounPhraseParseAttr.PARSEPREPOSITION, 0, null);
                        if (npt !== null) 
                            tt = npt.endToken;
                        t1 = tt;
                    }
                    let nam = FragToken._new2029(t.next, t1, InstrumentKind.NAME, true);
                    title.children.push(nam);
                    title.endToken = (t = t1);
                    continue;
                }
            }
            let appr1 = FragToken._createApproved(t);
            if (appr1 !== null) {
                t = appr1.endToken;
                title.children.push(appr1);
                title.endToken = appr1.endToken;
                continue;
            }
            let eds = FragToken._createEditions(t);
            if (eds !== null) {
                title.children.push(eds);
                title.endToken = (t = eds.endToken);
                continue;
            }
            appr1 = FragToken._createMisc(t);
            if (appr1 !== null) {
                t = appr1.endToken;
                title.children.push(appr1);
                title.endToken = appr1.endToken;
                continue;
            }
        }
        return title;
    }
    
    static _new2000(_arg1, _arg2, _arg3) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        return res;
    }
    
    static _new2004(_arg1, _arg2, _arg3, _arg4) {
        let res = new FragToken(_arg1, _arg2);
        res.itok = _arg3;
        res.isExpired = _arg4;
        return res;
    }
    
    static _new2005(_arg1, _arg2, _arg3, _arg4, _arg5) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.defVal2 = _arg4;
        res.itok = _arg5;
        return res;
    }
    
    static _new2012(_arg1, _arg2, _arg3) {
        let res = new FragToken(_arg1, _arg2);
        res.itok = _arg3;
        return res;
    }
    
    static _new2013(_arg1, _arg2, _arg3, _arg4) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.itok = _arg4;
        return res;
    }
    
    static _new2024(_arg1, _arg2, _arg3, _arg4) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.number = _arg4;
        return res;
    }
    
    static _new2026(_arg1, _arg2, _arg3, _arg4) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.defVal2 = _arg4;
        return res;
    }
    
    static _new2029(_arg1, _arg2, _arg3, _arg4) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.defVal = _arg4;
        return res;
    }
    
    static _new2041(_arg1, _arg2, _arg3, _arg4, _arg5) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.value = _arg4;
        res.itok = _arg5;
        return res;
    }
    
    static _new2052(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.number = _arg4;
        res.isExpired = _arg5;
        res.referents = _arg6;
        return res;
    }
    
    static _new2064(_arg1, _arg2, _arg3, _arg4) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.value = _arg4;
        return res;
    }
    
    static _new2070(_arg1, _arg2, _arg3, _arg4) {
        let res = new FragToken(_arg1, _arg2);
        res.m_Doc = _arg3;
        res.kind = _arg4;
        return res;
    }
    
    static _new2151(_arg1, _arg2, _arg3, _arg4) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.isExpired = _arg4;
        return res;
    }
    
    static _new2253(_arg1, _arg2, _arg3, _arg4, _arg5) {
        let res = new FragToken(_arg1, _arg2);
        res.kind = _arg3;
        res.defVal = _arg4;
        res.itok = _arg5;
        return res;
    }
    
    static static_constructor() {
        FragToken.m_ZapiskaKeywords = ["ЗАЯВЛЕНИЕ", "ЗАПИСКА", "РАПОРТ", "ДОКЛАД", "ОТЧЕТ", "ПЛАН"];
    }
}


FragToken.static_constructor();

module.exports = FragToken