/*
 * 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 NounPhraseParseAttr = require("./../core/NounPhraseParseAttr");
const NounPhraseHelper = require("./../core/NounPhraseHelper");
const InstrToken1Types = require("./../instrument/internal/InstrToken1Types");
const MorphNumber = require("./../../morph/MorphNumber");
const TerminParseAttr = require("./../core/TerminParseAttr");
const MorphClass = require("./../../morph/MorphClass");
const DecreeChangeKind = require("./DecreeChangeKind");
const MorphCase = require("./../../morph/MorphCase");
const MorphGender = require("./../../morph/MorphGender");
const ComplexNumToken = require("./../core/ComplexNumToken");
const DecreeChangeValueKind = require("./DecreeChangeValueKind");
const DecreeChangeTokenTyp = require("./internal/DecreeChangeTokenTyp");
const Termin = require("./../core/Termin");
const MetaDecreeChangeValue = require("./internal/MetaDecreeChangeValue");
const TerminCollection = require("./../core/TerminCollection");
const PersonReferent = require("./../person/PersonReferent");
const PullentiNerCoreInternalResourceHelper = require("./../core/internal/PullentiNerCoreInternalResourceHelper");
const MorphologyService = require("./../../morph/MorphologyService");
const Slot = require("./../Slot");
const ProcessorService = require("./../ProcessorService");
const MetaDecree = require("./internal/MetaDecree");
const SourceOfAnalysis = require("./../SourceOfAnalysis");
const DecreeKind = require("./DecreeKind");
const MetaDecreeChange = require("./internal/MetaDecreeChange");
const LanguageHelper = require("./../../morph/LanguageHelper");
const GetTextAttr = require("./../core/GetTextAttr");
const BracketParseAttr = require("./../core/BracketParseAttr");
const DecreeTokenItemType = require("./internal/DecreeTokenItemType");
const ReferentsEqualType = require("./../core/ReferentsEqualType");
const Token = require("./../Token");
const ReferentToken = require("./../ReferentToken");
const Referent = require("./../Referent");
const PartTokenItemType = require("./internal/PartTokenItemType");
const TextToken = require("./../TextToken");
const NumberToken = require("./../NumberToken");
const MetaToken = require("./../MetaToken");
const DecreeChangeReferent = require("./DecreeChangeReferent");
const Analyzer = require("./../Analyzer");
const MiscHelper = require("./../core/MiscHelper");
const PersonPropertyReferent = require("./../person/PersonPropertyReferent");
const DateReferent = require("./../date/DateReferent");
const BracketHelper = require("./../core/BracketHelper");
const OrganizationReferent = require("./../org/OrganizationReferent");
const DateRangeReferent = require("./../date/DateRangeReferent");
const GeoReferent = require("./../geo/GeoReferent");

/**
 * Анализатор ссылок на НПА
 */
class DecreeAnalyzer extends Analyzer {
    
    static tryAttach(dts, baseTyp, ad) {
        const DecreeReferent = require("./DecreeReferent");
        if (ad === null) 
            ad = DecreeAnalyzer.getData(dts[0]);
        if (ad.level > 2) 
            return null;
        ad.level++;
        let res = DecreeAnalyzer._TryAttach(dts, baseTyp, false, ad);
        if (res === null && ((dts.length === 1 || ((dts.length === 2 && dts[1].typ === DecreeTokenItemType.ORG)))) && dts[0].typRefBack) {
            for (let t = dts[0].beginToken.previous; t !== null; t = t.previous) {
                let dr = Utils.as(t.getReferent(), DecreeReferent);
                if (dr === null) 
                    continue;
                if ((typeof t.tag === 'string' || t.tag instanceof String)) {
                    if ((Utils.asString(t.tag)) === "ignored") 
                        continue;
                }
                if (dr.checkTypename(dts[0].value)) {
                }
                else if (dr.owner !== null && dr.owner.checkTypename(dts[0].value)) 
                    dr = dr.owner;
                else 
                    continue;
                if (dts.length === 2 && dts[1].ref !== null) {
                    let org = Utils.as(dr.getSlotValue(DecreeReferent.ATTR_SOURCE), Referent);
                    if (org !== null) {
                        if (!org.canBeEquals(dts[1].ref.referent, ReferentsEqualType.WITHINONETEXT)) 
                            continue;
                    }
                }
                res = new Array();
                res.push(new ReferentToken(dr, dts[0].beginToken, dts[dts.length - 1].endToken));
                break;
            }
        }
        ad.level--;
        return res;
    }
    
    static _TryAttach(dts, baseTyp, afterDecree, ad) {
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeReferent = require("./DecreeReferent");
        const DecreeToken = require("./internal/DecreeToken");
        const PartToken = require("./internal/PartToken");
        if (dts === null || (dts.length < 1)) 
            return null;
        if (dts[0].typ === DecreeTokenItemType.EDITION && dts.length > 1) 
            dts.splice(0, 1);
        if (dts.length === 2 && dts[0].typ === DecreeTokenItemType.ORG && dts[1].typ === DecreeTokenItemType.TYP) 
            return null;
        if (dts.length === 2 && dts[0].typ === DecreeTokenItemType.TYP && dts[1].typ === DecreeTokenItemType.NUMBER) {
            if ((dts[0].lengthChar < 3) && !dts[0].isWhitespaceAfter && dts[0].isDoubtful) 
                return null;
            if (dts[0].isNewlineAfter) 
                return null;
        }
        if (dts.length === 1) {
            if (dts[0].typ === DecreeTokenItemType.DECREEREF && dts[0].ref !== null) {
                if (baseTyp !== null) {
                    let re = dts[0].ref.getReferent();
                    let dre = Utils.as(re, DecreeReferent);
                    if (dre === null && (re instanceof DecreePartReferent)) 
                        dre = re.owner;
                    if (dre !== null) {
                        if (!dre.checkTypename(baseTyp.value)) 
                            return null;
                    }
                }
                let reli = new Array();
                reli.push(new ReferentToken(dts[0].ref.referent, dts[0].beginToken, dts[0].endToken));
                return reli;
            }
        }
        let dec0 = null;
        let kodeks = false;
        let canbesingle = false;
        let maxEmpty = 30;
        for (let t = dts[0].beginToken.previous; t !== null; t = t.previous) {
            if (t.isCommaAnd) 
                continue;
            if (t.isChar(')')) {
                let cou = 0;
                for (t = t.previous; t !== null; t = t.previous) {
                    if (t.isChar('(')) 
                        break;
                    else if ((++cou) > 200) 
                        break;
                }
                if (t !== null && t.isChar('(')) 
                    continue;
                break;
            }
            if ((--maxEmpty) < 0) 
                break;
            if (!t.chars.isLetter) 
                continue;
            dec0 = Utils.as(t.getReferent(), DecreeReferent);
            if (dec0 !== null) {
                if (DecreeToken.getKind(dec0.typ, null) === DecreeKind.KODEX) 
                    kodeks = true;
                else if (dec0.kind === DecreeKind.PUBLISHER) 
                    dec0 = null;
            }
            break;
        }
        let dec = new DecreeReferent();
        let i = 0;
        let _morph = null;
        let isNounDoubt = false;
        let numTok = null;
        let typTok = null;
        let nl = 0;
        for (i = 0; i < dts.length; i++) {
            if (dts[i].typ === DecreeTokenItemType.TYP) {
                if (dts[i].value === null) 
                    break;
                if (dts[i].value.startsWith("ПРОЕКТ")) {
                    if (i > 0) 
                        return null;
                }
                if (dts[i].isNewlineBefore) {
                    if (dec.date !== null || dec.number !== null) 
                        break;
                }
                if (dec.typ !== null) {
                    if (((dec.typ === "РЕШЕНИЕ" || dec.typ === "РІШЕННЯ")) && dts[i].value === "ПРОТОКОЛ") {
                    }
                    else if (((dec.typ === dts[i].value || dts[i].value === "ТЕХНИЧЕСКИЙ РЕГЛАМЕНТ")) && dec.typ === "ГОСТ") {
                        if (((i + 1) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.NUMBER) {
                            if (dec.number !== null) 
                                break;
                            if (i > 0 && dts[i - 1].typ === DecreeTokenItemType.NUMBER) 
                                break;
                        }
                        continue;
                    }
                    else if (dts[i].value === dec.typ) {
                        if ((i + 1) >= dts.length || dts[i + 1].typ === DecreeTokenItemType.NAME) 
                            continue;
                        else if ((((i + 1) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.NUMBER && dts[i - 1].typ === DecreeTokenItemType.NAME) && dec.number === null) {
                        }
                        else 
                            break;
                    }
                    else 
                        break;
                }
                let ki = DecreeToken.getKind(dts[i].value, null);
                if (ki === DecreeKind.STANDARD) {
                    if (i > 0) {
                        if (dts.length === 2 && dts[0].typ === DecreeTokenItemType.NUMBER && dts[i].value === "ТЕХНИЧЕСКИЕ УСЛОВИЯ") {
                        }
                        else 
                            return null;
                    }
                }
                if (ki === DecreeKind.KODEX) {
                    if (i > 0) 
                        break;
                    if (dts[i].value !== "ОСНОВЫ ЗАКОНОДАТЕЛЬСТВА" && dts[i].value !== "ОСНОВИ ЗАКОНОДАВСТВА") 
                        kodeks = true;
                    else 
                        kodeks = false;
                }
                else 
                    kodeks = false;
                _morph = dts[i].morph;
                dec.addTyp(dts[i]);
                if (typTok === null) 
                    typTok = dts[i];
                if (dts[i].canBeSingleDecree) 
                    canbesingle = true;
                if (dts[i].fullValue !== null) 
                    dec.addNameStr(dts[i].fullValue, dts[i]);
                isNounDoubt = dts[i].isDoubtful;
                if (isNounDoubt && i === 0) {
                    if (PartToken.isPartBefore(dts[i].beginToken)) 
                        isNounDoubt = false;
                }
                if (dts[i].ref !== null) {
                    if (dec.findSlot(DecreeReferent.ATTR_GEO, null, true) === null) {
                        let ss = dec.addSlot(DecreeReferent.ATTR_GEO, dts[i].ref.referent, false, 0);
                        ss.addAnnotation(dts[i].ref);
                        dec.addExtReferent(dts[i].ref);
                    }
                }
                if (dts[i].srcRef !== null) {
                    let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts[i].srcRef, false, 0);
                    ss.addAnnotation(dts[i]);
                }
            }
            else if (dts[i].typ === DecreeTokenItemType.DATE) {
                if (dec.date !== null) 
                    break;
                if (kodeks) {
                    if (i > 0 && dts[i - 1].typ === DecreeTokenItemType.NUMBER) {
                    }
                    else if (((i + 1) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.NUMBER) {
                    }
                    else 
                        break;
                }
                if (i === (dts.length - 1)) {
                    if (!dts[i].beginToken.isValue("ОТ", "ВІД")) {
                        let ty = DecreeToken.getKind(dec.typ, null);
                        if ((ty === DecreeKind.KONVENTION || ty === DecreeKind.CONTRACT || ty === DecreeKind.LICENSE) || dec.typ0 === "ПИСЬМО" || dec.typ0 === "ЛИСТ") {
                        }
                        else 
                            break;
                    }
                }
                dec.addDate(dts[i]);
                dec.addExtReferent(dts[i].ref);
            }
            else if (dts[i].typ === DecreeTokenItemType.DATERANGE) {
                if (dec.kind !== DecreeKind.PROGRAM) 
                    break;
                dec.addDate(dts[i]);
                dec.addExtReferent(dts[i].ref);
            }
            else if (dts[i].typ === DecreeTokenItemType.EDITION) {
                if (dts[i].isNewlineBefore && !dts[i].beginToken.chars.isAllLower && !dts[i].beginToken.isChar('(')) 
                    break;
                if (((i + 2) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.TYP) 
                    break;
            }
            else if (dts[i].typ === DecreeTokenItemType.NUMBER) {
                if (kodeks) {
                    if (((i + 1) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.DATE) {
                    }
                    else if (i > 0 && dts[i - 1].typ === DecreeTokenItemType.DATE) {
                    }
                    else 
                        break;
                }
                numTok = dts[i];
                if (dts[i].isDelo) {
                    if (dec.caseNumber !== null) 
                        break;
                    let ss = dec.addSlot(DecreeReferent.ATTR_CASENUMBER, dts[i].value, true, 0);
                    ss.addAnnotation(dts[i]);
                    continue;
                }
                if (dec.number !== null) {
                    if (i > 2 && ((dts[i - 1].typ === DecreeTokenItemType.OWNER || dts[i - 1].typ === DecreeTokenItemType.ORG)) && dts[i - 2].typ === DecreeTokenItemType.NUMBER) {
                    }
                    else 
                        break;
                }
                if (dts[i].isNewlineBefore) {
                    if (dec.typ === null && dec0 === null) 
                        break;
                }
                if (LanguageHelper.endsWith(dts[i].value, "ФЗ")) 
                    dec.typ = "ФЕДЕРАЛЬНЫЙ ЗАКОН";
                if (LanguageHelper.endsWith(dts[i].value, "ФКЗ")) 
                    dec.typ = "ФЕДЕРАЛЬНЫЙ КОНСТИТУЦИОННЫЙ ЗАКОН";
                if (dts[i].value !== null && Utils.startsWithString(dts[i].value, "ПР", true) && dec.typ === null) 
                    dec.typ = "ПОРУЧЕНИЕ";
                if (dec.typ === null) {
                    if (dec0 === null && !afterDecree && baseTyp === null) 
                        break;
                }
                dec.addNumber(dts[i]);
                if (dts[i].children !== null) {
                    let cou = 0;
                    for (const s of dec.slots) {
                        if (s.typeName === DecreeReferent.ATTR_SOURCE) 
                            cou++;
                    }
                    if (cou === (dts[i].children.length + 1)) {
                        for (const dd of dts[i].children) {
                            dec.addNumber(dd);
                        }
                        dts[i].children = null;
                    }
                }
                continue;
            }
            else if (dts[i].typ === DecreeTokenItemType.NAME) {
                if (dec.typ === null && dec.number === null && dec0 === null) {
                    if (dts[i].typKind === DecreeKind.CLASSIFIER || dts[i].typKind === DecreeKind.STANDARD) {
                    }
                    else if ((i === 0 && ((i + 1) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.TYP) && (dts[i + 1].whitespacesBeforeCount < 3)) {
                    }
                    else 
                        break;
                }
                if (dec.getStringValue(DecreeReferent.ATTR_NAME) !== null) {
                    if (kodeks) 
                        break;
                    if (i > 0 && dts[i - 1].endToken.next === dts[i].beginToken) {
                    }
                    else if (dts[i].typKind === DecreeKind.CLASSIFIER) {
                    }
                    else 
                        break;
                }
                let tt0 = dts[i].beginToken;
                let tt1 = dts[i].endToken;
                if ((i > 0 && dts[i - 1].isNewlineAfter && ((i + 1) < dts.length)) && dts[i + 1].typ === DecreeTokenItemType.TYP && (dts[i + 1].whitespacesBeforeCount < 3)) 
                    break;
                if (BracketHelper.canBeStartOfSequence(tt0, true, false) && BracketHelper.canBeEndOfSequence(tt1, true, tt0, false)) {
                    tt0 = tt0.next;
                    tt1 = tt1.previous;
                    for (let tt = tt0; tt !== null && (tt.endChar < tt1.endChar); tt = tt.next) {
                        if (BracketHelper.canBeStartOfSequence(tt, true, false)) {
                            let br1 = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                            if (br1 !== null && br1.endToken === dts[i].endToken) {
                                tt1 = tt1.next;
                                break;
                            }
                        }
                    }
                }
                let nam = MiscHelper.getTextValue(tt0, tt1, GetTextAttr.RESTOREREGISTER);
                if (kodeks && !nam.toUpperCase().includes("КОДЕКС")) 
                    nam = "Кодекс " + nam;
                if (dts[i].fullValue !== null) 
                    dec.addNameStr(dts[i].fullValue, dts[i]);
                dec.addNameStr(nam, (tt0.beginChar <= tt1.beginChar ? new MetaToken(tt0, tt1) : null));
            }
            else if (dts[i].typ === DecreeTokenItemType.BETWEEN) {
                if (dec.kind !== DecreeKind.CONTRACT) 
                    break;
                for (const chh of dts[i].children) {
                    let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, chh.ref.referent, false, 0);
                    ss.tag = chh.getSourceText();
                    ss.addAnnotation(chh);
                    if (chh.ref.referent instanceof PersonPropertyReferent) 
                        dec.addExtReferent(chh.ref);
                }
            }
            else if (dts[i].typ === DecreeTokenItemType.OWNER) {
                if (kodeks) 
                    break;
                if (dec.name !== null) 
                    break;
                if (((i === 0 || i === (dts.length - 1))) && dts[i].beginToken.chars.isAllLower) 
                    break;
                if (i === 0 && dts.length > 1 && dts[1].typ === DecreeTokenItemType.TYP) 
                    break;
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) !== null) {
                }
                if (dts[i].ref !== null) {
                    let ty = DecreeToken.getKind(dec.typ, null);
                    if (ty === DecreeKind.USTAV) {
                        if (!(dts[i].ref.referent instanceof OrganizationReferent)) 
                            break;
                    }
                    let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts[i].ref.referent, false, 0);
                    ss.tag = dts[i].getSourceText();
                    ss.addAnnotation(dts[i]);
                    if (dts[i].ref.referent instanceof PersonPropertyReferent) 
                        dec.addExtReferent(dts[i].ref);
                }
                else {
                    let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, MiscHelper.convertFirstCharUpperAndOtherLower(dts[i].value), false, 0);
                    ss.tag = dts[i].getSourceText();
                    ss.addAnnotation(dts[i]);
                }
            }
            else if (dts[i].typ === DecreeTokenItemType.ORG) {
                if (kodeks) {
                    if (i !== 1 || dts[i].whitespacesBeforeCount > 3) 
                        break;
                    if (dts.length === 2 || ((dts.length === 3 && dts[2].typ === DecreeTokenItemType.MISC))) {
                    }
                    else 
                        break;
                    isNounDoubt = false;
                }
                else if (dec.name !== null) 
                    break;
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) !== null) {
                    if (i > 2 && dts[i - 1].typ === DecreeTokenItemType.NUMBER && ((dts[i - 2].typ === DecreeTokenItemType.ORG || dts[i - 2].typ === DecreeTokenItemType.OWNER))) {
                    }
                    else if (dts[i].beginToken.previous !== null && dts[i].beginToken.previous.isAnd) {
                    }
                    else if (i > 0 && ((dts[i - 1].typ === DecreeTokenItemType.OWNER || dts[i - 1].typ === DecreeTokenItemType.ORG))) {
                    }
                    else if (i > 0 && dts[i - 1].typ === DecreeTokenItemType.TYP && dts[i - 1].srcRef === dec.getSlotValue(DecreeReferent.ATTR_SOURCE)) {
                    }
                    else 
                        break;
                }
                let ttt = Utils.as(dts[i].beginToken, ReferentToken);
                if (ttt !== null && ttt === dts[i].endToken && ttt.beginToken !== ttt.endToken) {
                    if ((ttt.beginToken.getReferent() instanceof OrganizationReferent) && ttt.beginToken.next.isComma) {
                        let sl1 = dec.addSlot(DecreeReferent.ATTR_SOURCE, ttt.beginToken.getReferent(), false, 0);
                        sl1.tag = ttt.beginToken.getSourceText();
                        sl1.addAnnotation(Utils.as(ttt.beginToken, ReferentToken));
                    }
                }
                let sl = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts[i].ref.referent, false, 0);
                sl.tag = dts[i].getSourceText();
                sl.addAnnotation(dts[i]);
                if (((i + 2) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.UNKNOWN && (dts[i + 1].whitespacesBeforeCount < 2)) {
                    if (dts[i + 2].typ === DecreeTokenItemType.NUMBER || dts[i + 2].typ === DecreeTokenItemType.DATE) {
                        sl.tag = new MetaToken(dts[i].beginToken, dts[i + 1].endToken).getSourceText();
                        i++;
                    }
                }
            }
            else if (dts[i].typ === DecreeTokenItemType.TERR) {
                if (dec.findSlot(DecreeReferent.ATTR_GEO, null, true) !== null) 
                    break;
                if (i > 0 && dts[i - 1].typ === DecreeTokenItemType.NAME) 
                    break;
                if (dts[i].isNewlineBefore && ((i + 1) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.DATE) 
                    break;
                let ss = dec.addSlot(DecreeReferent.ATTR_GEO, dts[i].ref.referent, false, 0);
                ss.addAnnotation(dts[i]);
            }
            else if (dts[i].typ === DecreeTokenItemType.UNKNOWN) {
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) !== null) 
                    break;
                if (kodeks) 
                    break;
                if ((dec.kind === DecreeKind.CONTRACT && i === 1 && ((i + 1) < dts.length)) && dts[i + 1].typ === DecreeTokenItemType.NUMBER) {
                    dec.addNameStr(MiscHelper.getTextValueOfMetaToken(dts[i], GetTextAttr.KEEPREGISTER), dts[i]);
                    continue;
                }
                if (i === 0) {
                    if (dec0 === null && !afterDecree) 
                        break;
                    let ok1 = false;
                    if (((i + 1) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.NUMBER) 
                        ok1 = true;
                    else if (((i + 2) < dts.length) && dts[i + 1].typ === DecreeTokenItemType.TERR && dts[i + 2].typ === DecreeTokenItemType.NUMBER) 
                        ok1 = true;
                    if (!ok1) 
                        break;
                }
                else if (dts[i - 1].typ === DecreeTokenItemType.OWNER || dts[i - 1].typ === DecreeTokenItemType.ORG) 
                    continue;
                if ((i + 1) >= dts.length) 
                    break;
                if (dts[0].typ === DecreeTokenItemType.TYP && dts[0].isDoubtful) 
                    break;
                if (dts[i + 1].typ === DecreeTokenItemType.NUMBER || dts[i + 1].typ === DecreeTokenItemType.DATE || dts[i + 1].typ === DecreeTokenItemType.NAME) {
                    let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts[i].value, false, 0);
                    ss.tag = dts[i].getSourceText();
                    ss.addAnnotation(dts[i]);
                    continue;
                }
                if (dts[i + 1].typ === DecreeTokenItemType.TERR) {
                    let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts[i].value, false, 0);
                    ss.tag = dts[i].getSourceText();
                    ss.addAnnotation(dts[i]);
                    continue;
                }
                if (dts[i + 1].typ === DecreeTokenItemType.OWNER) {
                    let s = MiscHelper.getTextValue(dts[i].beginToken, dts[i + 1].endToken, GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
                    dts[i].endToken = dts[i + 1].endToken;
                    let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, s, false, 0);
                    ss.tag = dts[i].getSourceText();
                    ss.addAnnotation(dts[i]);
                    i++;
                    continue;
                }
                break;
            }
            else if (dts[i].typ === DecreeTokenItemType.MISC) {
                if (i === 0 || kodeks) 
                    break;
                if ((i + 1) >= dts.length) {
                    if (BracketHelper.canBeStartOfSequence(dts[i].endToken.next, true, false)) 
                        continue;
                    if (i > 0 && dts[i - 1].typ === DecreeTokenItemType.NUMBER) {
                        if (DecreeToken.tryAttachName(dts[i].endToken.next, null, true, false, false) !== null) 
                            continue;
                    }
                }
                else if (dts[i + 1].typ === DecreeTokenItemType.NAME || dts[i + 1].typ === DecreeTokenItemType.NUMBER || dts[i + 1].typ === DecreeTokenItemType.DATE) 
                    continue;
                break;
            }
            else 
                break;
        }
        if (i === 0) 
            return null;
        if (dec.typ === null || ((dec0 !== null && dts[0].typ !== DecreeTokenItemType.TYP))) {
            if (dec0 !== null) {
                if (dec.number === null && dec.date === null && dec.findSlot(DecreeReferent.ATTR_NAME, null, true) === null) 
                    return null;
                if (dec.typ === null) 
                    dec.typ = dec0.typ;
                if (dec.findSlot(DecreeReferent.ATTR_GEO, null, true) === null) 
                    dec.addSlot(DecreeReferent.ATTR_GEO, dec0.getStringValue(DecreeReferent.ATTR_GEO), false, 0);
                if (dec.findSlot(DecreeReferent.ATTR_DATE, null, true) === null && dec0.date !== null) 
                    dec.addSlot(DecreeReferent.ATTR_DATE, dec0.getSlotValue(DecreeReferent.ATTR_DATE), false, 0);
                let sl = null;
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) === null) {
                    if ((((sl = dec0.findSlot(DecreeReferent.ATTR_SOURCE, null, true)))) !== null) {
                        let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, sl.value, false, 0);
                        ss.tag = sl.tag;
                        ss.mergeOccurence(sl);
                    }
                }
            }
            else if (baseTyp !== null && afterDecree) 
                dec.addTyp(baseTyp);
            else 
                return null;
        }
        let et = dts[i - 1].endToken;
        if ((((!afterDecree && dts.length === i && i === 3) && dts[0].typ === DecreeTokenItemType.TYP && dts[i - 1].typ === DecreeTokenItemType.NUMBER) && dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) !== null && et.next !== null) && et.next.isComma && dec.number !== null) {
            for (let tt = et.next; tt !== null; tt = tt.next) {
                if (!tt.isChar(',')) 
                    break;
                let ddd = DecreeToken.tryAttachList(tt.next, dts[0], 10, false);
                if (ddd === null || (ddd.length < 2) || ddd[0].typ === DecreeTokenItemType.TYP) 
                    break;
                let hasNum = false;
                for (const d of ddd) {
                    if (d.typ === DecreeTokenItemType.NUMBER) 
                        hasNum = true;
                    else if (d.typ === DecreeTokenItemType.TYP) {
                        hasNum = false;
                        break;
                    }
                }
                if (!hasNum) 
                    break;
                let rtt = DecreeAnalyzer._TryAttach(ddd, dts[0], true, ad);
                if (rtt === null) 
                    break;
                dec.mergeSlots(rtt[0].referent, true);
                et = (tt = rtt[0].endToken);
            }
        }
        if (((et.next !== null && et.next.isChar('<') && (et.next.next instanceof ReferentToken)) && et.next.next.next !== null && et.next.next.next.isChar('>')) && et.next.next.getReferent().typeName === "URI") 
            et = et.next.next.next;
        let num = dec.number;
        if ((dec.findSlot(DecreeReferent.ATTR_NAME, null, true) === null && (i < dts.length) && dts[i].typ === DecreeTokenItemType.TYP) && dec.kind === DecreeKind.PROJECT) {
            let dts1 = Array.from(dts);
            dts1.splice(0, i);
            let rt1 = DecreeAnalyzer._TryAttach(dts1, null, true, ad);
            if (rt1 !== null) {
                dec.addNameStr(MiscHelper.getTextValueOfMetaToken(rt1[0], GetTextAttr.KEEPREGISTER), rt1[0]);
                et = rt1[0].endToken;
            }
        }
        if (dec.typ === "РУКОВОДЯЩИЙ ДОКУМЕНТ" && !et.isNewlineAfter) {
            let typ1 = DecreeToken.tryAttach(et.next, null, false);
            if (typ1 !== null && typ1.typ === DecreeTokenItemType.TYP && typ1.value === dec.typ) {
                let tt = typ1.endToken.next;
                for (; tt !== null; tt = tt.next) {
                    if (tt.isChar('.') || tt.isHiphen || tt.isValue("ОТРАСЛЬ", null)) {
                    }
                    else 
                        break;
                }
                let dn = DecreeToken.tryAttachName(tt, dec.typ, false, false, false);
                if (dn !== null) {
                    if (dn.fullValue !== null) 
                        dec.addNameStr(dn.fullValue, dn);
                    if (dn.value !== null) 
                        dec.addNameStr(dn.value, dn);
                    et = dn.endToken;
                }
            }
        }
        if (dec.findSlot(DecreeReferent.ATTR_NAME, null, true) === null && !kodeks && et.next !== null) {
            let dn = DecreeToken.tryAttachName((et.next.isChar(':') ? et.next.next : et.next), dec.typ, false, false, false);
            if (dn !== null && et.next.chars.isAllLower && num !== null) {
                if (ad !== null) {
                    for (const r of ad.referents) {
                        if (r.findSlot(DecreeReferent.ATTR_NUMBER, num, true) !== null) {
                            if (r.canBeEquals(dec, ReferentsEqualType.WITHINONETEXT)) {
                                if (r.findSlot(DecreeReferent.ATTR_NAME, dn.value, true) === null) 
                                    dn = null;
                                break;
                            }
                        }
                    }
                }
            }
            if (dts[i - 1].typ === DecreeTokenItemType.TYP && dn !== null && et.isNewlineAfter) 
                dn = null;
            if (dn !== null) {
                if (dec.kind === DecreeKind.PROGRAM) {
                    dn.beginToken = dts[0].beginToken;
                    dn.fullValue = MiscHelper.getTextValueOfMetaToken(dn, GetTextAttr.of((GetTextAttr.FIRSTNOUNGROUPTONOMINATIVESINGLE.value()) | (GetTextAttr.KEEPREGISTER.value())));
                    if (Utils.startsWithString(dn.fullValue, "ГОСПРОГРАММА", true)) 
                        dn.fullValue = "Государственная программа" + dn.fullValue.substring(12);
                }
                if (dec.kind === DecreeKind.PROGRAM) {
                    for (let tt1 = dn.endToken.previous; tt1 !== null && tt1.beginChar > dn.beginChar; tt1 = (tt1 === null ? null : tt1.previous)) {
                        if (tt1.isChar(')') && tt1.previous !== null) 
                            tt1 = tt1.previous;
                        if (tt1.getReferent() instanceof DateRangeReferent) 
                            dec.addSlot(DecreeReferent.ATTR_DATE, tt1.getReferent(), false, 0);
                        else if ((tt1.getReferent() instanceof DateReferent) && tt1.previous !== null && tt1.previous.isValue("ДО", null)) {
                            let rt11 = tt1.kit.processReferent("DATE", tt1.previous, null);
                            if (rt11 !== null && (rt11.referent instanceof DateRangeReferent)) {
                                dec.addSlot(DecreeReferent.ATTR_DATE, rt11.referent, false, 0);
                                dec.addExtReferent(rt11);
                                tt1 = tt1.previous;
                            }
                            else 
                                break;
                        }
                        else if ((tt1.getReferent() instanceof DateReferent) && tt1.previous !== null && ((tt1.previous.isValue("НА", null) || tt1.previous.isValue("В", null)))) {
                            dec.addSlot(DecreeReferent.ATTR_DATE, tt1.getReferent(), false, 0);
                            tt1 = tt1.previous;
                        }
                        else 
                            break;
                        for (tt1 = tt1.previous; tt1 !== null && tt1.beginChar > dn.beginChar; tt1 = (tt1 === null ? null : tt1.previous)) {
                            if (tt1.morph._class.isConjunction || tt1.morph._class.isPreposition) 
                                continue;
                            if (tt1.isValue("ПЕРИОД", "ПЕРІОД") || tt1.isValue("ПЕРСПЕКТИВА", null)) 
                                continue;
                            if (tt1.isChar('(')) 
                                continue;
                            break;
                        }
                        if (tt1 !== null && tt1.endChar > dn.beginChar) {
                            if (dn.fullValue === null) 
                                dn.fullValue = dn.value;
                            dn.value = MiscHelper.getTextValue(dn.beginToken, tt1, GetTextAttr.of((GetTextAttr.FIRSTNOUNGROUPTONOMINATIVESINGLE.value()) | (GetTextAttr.KEEPREGISTER.value())));
                        }
                        tt1 = tt1.next;
                    }
                }
                if (dn.fullValue !== null) 
                    dec.addNameStr(dn.fullValue, dn);
                if ((dts.length === 1 && dec.kind !== DecreeKind.PROGRAM && dts[0].typ === DecreeTokenItemType.TYP) && dn.beginToken.morph._case.isGenitive && !dn.beginToken.morph._class.isPreposition) {
                    let str = MiscHelper.getTextValue(dts[0].beginToken, dn.endToken, GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
                    dec.addNameStr(str, new MetaToken(dts[0].beginToken, dn.endToken));
                }
                else 
                    dec.addNameStr(dn.value, new MetaToken(dts[0].beginToken, dn.endToken));
                et = dn.endToken;
                let br = false;
                for (let tt = et.next; tt !== null; tt = tt.next) {
                    if (tt.isChar('(')) {
                        br = true;
                        continue;
                    }
                    if (tt.isChar(')') && br) {
                        et = tt;
                        continue;
                    }
                    if ((tt.getReferent() instanceof DateRangeReferent) && dec.kind === DecreeKind.PROGRAM) {
                        dec.addSlot(DecreeReferent.ATTR_DATE, tt.getReferent(), false, 0);
                        et = tt;
                        continue;
                    }
                    dn = DecreeToken.tryAttach(tt, null, false);
                    if (dn === null) 
                        break;
                    if (dn.typ === DecreeTokenItemType.DATE && dec.date === null) {
                        if (dec.addDate(dn)) {
                            et = (tt = dn.endToken);
                            continue;
                        }
                    }
                    if (dn.typ === DecreeTokenItemType.NUMBER && dec.number === null) {
                        dec.addNumber(dn);
                        et = (tt = dn.endToken);
                        continue;
                    }
                    if (dn.typ === DecreeTokenItemType.DATERANGE && dec.kind === DecreeKind.PROGRAM) {
                        if (dec.addDate(dn)) {
                            et = (tt = dn.endToken);
                            continue;
                        }
                    }
                    if (dn.typ === DecreeTokenItemType.TERR && dec.findSlot(DecreeReferent.ATTR_GEO, null, true) === null && dn.ref !== null) {
                        dec.addSlot(DecreeReferent.ATTR_GEO, dn.ref.referent, false, 0);
                        et = (tt = dn.endToken);
                        continue;
                    }
                    break;
                }
            }
        }
        if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) === null) {
            let tt0 = dts[0].beginToken.previous;
            if ((tt0 !== null && tt0.isValue("В", "У") && tt0.previous !== null) && (tt0.previous.getReferent() instanceof OrganizationReferent)) {
                let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, tt0.previous.getReferent(), false, 0);
                ss.addAnnotation(Utils.as(tt0.previous, ReferentToken));
            }
        }
        if (!canbesingle && !dec.checkCorrection(isNounDoubt)) {
            let ty = dec.typ;
            let sl = null;
            if (dec0 !== null && dec.date !== null && dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) === null) 
                sl = dec0.findSlot(DecreeReferent.ATTR_SOURCE, null, true);
            if (sl !== null && (((((ty === "ПОСТАНОВЛЕНИЕ" || ty === "ПОСТАНОВА" || ty === "ОПРЕДЕЛЕНИЕ") || ty === "ВИЗНАЧЕННЯ" || ty === "РЕШЕНИЕ") || ty === "РІШЕННЯ" || ty === "ПРИГОВОР") || ty === "ВИРОК"))) 
                dec.addSlot(sl.typeName, sl.value, false, 0).tag = sl.tag;
            else {
                let eqDecs = 0;
                let dr0 = null;
                if (num !== null) {
                    if (ad !== null) {
                        for (const r of ad.referents) {
                            if (r.findSlot(DecreeReferent.ATTR_NUMBER, num, true) !== null) {
                                if (r.canBeEquals(dec, ReferentsEqualType.WITHINONETEXT)) {
                                    eqDecs++;
                                    dr0 = Utils.as(r, DecreeReferent);
                                }
                            }
                        }
                    }
                }
                if (eqDecs === 1) 
                    dec.mergeSlots(dr0, true);
                else {
                    let ok1 = false;
                    if (num !== null) {
                        for (let tt = dts[0].beginToken.previous; tt !== null; tt = tt.previous) {
                            if (tt.isCharOf(":,") || tt.isHiphen || BracketHelper.canBeStartOfSequence(tt, false, false)) {
                            }
                            else {
                                if (tt.isValue("ДАЛЕЕ", "ДАЛІ") || tt.isValue("УТВЕРЖДЕННЫЙ", null)) 
                                    ok1 = true;
                                break;
                            }
                        }
                    }
                    if (!ok1) 
                        return null;
                }
            }
        }
        let rt = new ReferentToken(dec, dts[0].beginToken, et);
        if (dec.slots.length === 2 && dec.slots[0].typeName === DecreeReferent.ATTR_TYPE && dec.slots[1].typeName === DecreeReferent.ATTR_NAME) {
            let err = true;
            for (let tt = rt.beginToken; tt !== null && tt.endChar <= rt.endChar; tt = tt.next) {
                if (tt.getReferent() instanceof GeoReferent) {
                }
                else if ((tt instanceof TextToken) && tt.chars.isLetter && !tt.chars.isAllLower) {
                    err = false;
                    break;
                }
            }
            if (err) 
                return null;
        }
        if (_morph !== null) 
            rt.morph = _morph;
        if (rt.chars.isAllLower) {
            if (dec.typ0 === "ДЕКЛАРАЦИЯ" || dec.typ0 === "ДЕКЛАРАЦІЯ") 
                return null;
            if (((dec.typ0 === "КОНСТИТУЦИЯ" || dec.typ0 === "КОНСТИТУЦІЯ")) && rt.beginToken === rt.endToken) {
                let ok1 = false;
                let cou = 10;
                for (let tt = rt.beginToken.previous; tt !== null && cou > 0; tt = tt.previous,cou--) {
                    if (tt.isNewlineAfter) 
                        break;
                    let pt = PartToken.tryAttach(tt, null, false, false);
                    if (pt !== null && pt.typ !== PartTokenItemType.PREFIX && pt.endToken.next === rt.beginToken) {
                        ok1 = true;
                        break;
                    }
                }
                if (!ok1) 
                    return null;
            }
        }
        if (num !== null && ((num.indexOf('/') > 0 || num.indexOf(',') > 0))) {
            let cou = 0;
            for (const s of dec.slots) {
                if (s.typeName === DecreeReferent.ATTR_NUMBER) 
                    cou++;
            }
            if (cou === 1) {
                let owns = 0;
                for (const s of dec.slots) {
                    if (s.typeName === DecreeReferent.ATTR_SOURCE) 
                        owns++;
                }
                if (owns > 1) {
                    let nums = Utils.splitString(num, '/', false);
                    let nums2 = Utils.splitString(num, ',', false);
                    let strNum = null;
                    for (let ii = 0; ii < dts.length; ii++) {
                        if (dts[ii].typ === DecreeTokenItemType.NUMBER) {
                            strNum = dts[ii].getSourceText();
                            break;
                        }
                    }
                    if (nums2.length === owns && owns > 1) {
                        dec.addSlot(DecreeReferent.ATTR_NUMBER, null, true, 0);
                        for (const n of nums2) {
                            dec.addSlot(DecreeReferent.ATTR_NUMBER, n.trim(), false, 0).tag = strNum;
                        }
                    }
                    else if (nums.length === owns && owns > 1) {
                        dec.addSlot(DecreeReferent.ATTR_NUMBER, null, true, 0);
                        for (const n of nums) {
                            dec.addSlot(DecreeReferent.ATTR_NUMBER, n.trim(), false, 0).tag = strNum;
                        }
                    }
                }
            }
        }
        if (BracketHelper.canBeStartOfSequence(rt.beginToken.previous, true, false) && BracketHelper.canBeEndOfSequence(rt.endToken.next, true, rt.beginToken.previous, false)) {
            rt.beginToken = rt.beginToken.previous;
            rt.endToken = rt.endToken.next;
            let dts1 = DecreeToken.tryAttachList(rt.endToken.next, null, 10, false);
            if (dts1 !== null && dts1[0].typ === DecreeTokenItemType.DATE && dec.findSlot(DecreeReferent.ATTR_DATE, null, true) === null) {
                dec.addDate(dts1[0]);
                rt.endToken = dts1[0].endToken;
                if (dts1.length > 1 && dts1[1].typ === DecreeTokenItemType.NUMBER && dec.number === null) {
                    dec.addNumber(dts1[1]);
                    rt.endToken = dts1[1].endToken;
                }
            }
        }
        if (dec.kind === DecreeKind.STANDARD && dec.name === null && BracketHelper.canBeStartOfSequence(rt.endToken.next, true, false)) {
            let br = BracketHelper.tryParse(rt.endToken.next, BracketParseAttr.NO, 100);
            if (br !== null) {
                dec.addNameStr(MiscHelper.getTextValueOfMetaToken(br, GetTextAttr.KEEPREGISTER), br);
                rt.endToken = br.endToken;
            }
        }
        if (dec.kind === DecreeKind.PROGRAM && dec.findSlot(DecreeReferent.ATTR_DATE, null, true) === null) {
            if (rt.beginToken.previous !== null && rt.beginToken.previous.isValue("ПАСПОРТ", null)) {
                let cou = 0;
                for (let tt = rt.endToken.next; tt !== null && (cou < 1000); tt = (tt === null ? null : tt.next)) {
                    if (tt.isValue("СРОК", "ТЕРМІН") && tt.next !== null && tt.next.isValue("РЕАЛИЗАЦИЯ", "РЕАЛІЗАЦІЯ")) {
                    }
                    else 
                        continue;
                    tt = tt.next.next;
                    if (tt === null) 
                        break;
                    let dtok = DecreeToken.tryAttach(tt, null, false);
                    if (dtok !== null && dtok.typ === DecreeTokenItemType.TYP && ((dtok.value === "ПРОГРАММА" || dtok.value === "ПРОГРАМА"))) 
                        tt = dtok.endToken.next;
                    for (; tt !== null; tt = tt.next) {
                        if (tt.isHiphen || tt.isTableControlChar || tt.isValue("ПРОГРАММА", "ПРОГРАМА")) {
                        }
                        else if (tt.getReferent() instanceof DateRangeReferent) {
                            dec.addSlot(DecreeReferent.ATTR_DATE, tt.getReferent(), false, 0);
                            break;
                        }
                        else 
                            break;
                    }
                    break;
                }
            }
        }
        if (rt.endToken.next !== null && rt.endToken.next.isChar('(')) {
            let dt = null;
            let ok = false;
            for (let tt = rt.endToken.next.next; tt !== null; tt = tt.next) {
                let r = tt.getReferent();
                if (r instanceof GeoReferent) 
                    continue;
                if (r instanceof DateReferent) {
                    dt = Utils.as(r, DateReferent);
                    continue;
                }
                if (tt.morph._class.isPreposition) 
                    continue;
                if (tt.morph._class.isVerb) 
                    continue;
                if (tt.isChar(')') && dt !== null) {
                    dec.addSlot(DecreeReferent.ATTR_DATE, dt, false, 0);
                    rt.endToken = tt;
                    ok = true;
                }
                break;
            }
            if (!ok) {
                let dts1 = DecreeToken.tryAttachList(rt.endToken.next.next, null, 10, false);
                if (dts1 !== null) {
                    let rtt = DecreeAnalyzer._TryAttach(dts1, typTok, true, ad);
                    if ((rtt !== null && rtt.length === 1 && rtt[0].endToken.next !== null) && rtt[0].endToken.next.isChar(')')) {
                        let dec1 = Utils.as(rtt[0].referent, DecreeReferent);
                        ok = dec.typ === dec1.typ;
                        if ((ok && dec1.number !== null && dec.number !== null) && dec.number !== dec1.number) 
                            ok = false;
                        if ((ok && dec1.date !== null && dec.date !== null) && dec.date !== dec1.date) 
                            ok = false;
                        if (ok) {
                            dec.mergeSlots(rtt[0].referent, true);
                            rt.endToken = rtt[0].endToken.next;
                        }
                    }
                }
                else if (dec.kind === DecreeKind.CLASSIFIER) {
                    let br = BracketHelper.tryParse(rt.endToken.next, BracketParseAttr.NO, 100);
                    if (br !== null) 
                        rt.endToken = br.endToken;
                }
            }
        }
        if (dec.findSlot(DecreeReferent.ATTR_NAME, null, true) === null && !rt.isNewlineBefore) {
            let tt0 = null;
            let cou = 40;
            for (let tt = rt.beginToken.previous; tt !== null && cou > 0; tt = tt.previous,cou--) {
                if (BracketHelper.canBeStartOfSequence(tt, true, false)) 
                    tt0 = tt;
                else if ((tt instanceof TextToken) && tt.chars.isLetter) 
                    tt0 = tt;
                if (tt.isNewlineBefore) 
                    break;
            }
            let nam = DecreeToken.tryAttachName(tt0, dec.typ, false, false, false);
            if (nam !== null && (nam.endChar < rt.beginChar)) {
                if (nam.endToken.next === rt.beginToken || ((nam.endToken.next.isComma && nam.endToken.next.next === rt.beginToken))) {
                    rt.beginToken = tt0;
                    dec.addNameStr(nam.value, nam);
                }
            }
        }
        if (dec.findSlot(DecreeReferent.ATTR_NAME, null, true) === null && !rt.isNewlineAfter) {
            if (rt.isNewlineBefore || ((rt.beginToken.previous !== null && rt.beginToken.previous.lengthChar === 1 && ((rt.beginToken.previous.isNewlineBefore || rt.beginToken.previous.isTableControlChar))))) {
                if (dec.kind === DecreeKind.STANDARD && dec.number !== null) {
                    let nam = DecreeToken.tryAttachNameToEndOfLine(rt.endToken.next, false);
                    if (nam !== null) {
                        rt.endToken = nam.endToken;
                        dec.addNameStr(nam.value, nam);
                    }
                }
            }
        }
        let rtLi = new Array();
        if (((i + 1) < dts.length) && dts[i].typ === DecreeTokenItemType.EDITION && !dts[i].isNewlineBefore) {
            dts.splice(0, i + 1);
            let ed = DecreeAnalyzer._TryAttach(dts, baseTyp, true, ad);
            if (ed !== null && ed.length > 0) {
                rtLi.splice(rtLi.length, 0, ...ed);
                for (const e of ed) {
                    dec.addSlot(DecreeReferent.ATTR_EDITION, e.referent, false, 0);
                }
                rt.endToken = ed[ed.length - 1].endToken;
            }
        }
        else if (((i < (dts.length - 1)) && i > 0 && dts[i - 1].typ === DecreeTokenItemType.EDITION) && !dts[i - 1].isNewlineBefore) {
            dts.splice(0, i);
            let ed = DecreeAnalyzer._TryAttach(dts, baseTyp, true, ad);
            if (ed !== null && ed.length > 0) {
                rtLi.splice(rtLi.length, 0, ...ed);
                for (const e of ed) {
                    dec.addSlot(DecreeReferent.ATTR_EDITION, e.referent, false, 0);
                }
                rt.endToken = ed[ed.length - 1].endToken;
            }
        }
        if (dec.kind === DecreeKind.LAW || dec.kind === DecreeKind.ORDER) {
        }
        else {
            let rt22 = DecreeAnalyzer._tryAttachApproved(rt.endToken.next, ad, true, false, null);
            if (rt22 !== null) {
                rt.endToken = rt22.endToken;
                let dr00 = Utils.as(rt22.referent, DecreeReferent);
                if (dr00.typ === null) {
                    for (const s of dr00.slots) {
                        if (s.typeName === DecreeReferent.ATTR_DATE || s.typeName === DecreeReferent.ATTR_SOURCE) {
                            if (dec.findSlot(s.typeName, null, true) === null) 
                                dec.addSlot(s.typeName, s.value, false, 0);
                        }
                    }
                    dr00 = null;
                }
                if (dr00 !== null) {
                    rtLi.push(rt22);
                    dec.addSlot(DecreeReferent.ATTR_OWNER, rt22.referent, false, 0);
                }
            }
        }
        if (dts[0].typ === DecreeTokenItemType.TYP && dts[0].typKind === DecreeKind.CLASSIFIER) {
            if (((rt.beginToken.previous !== null && rt.beginToken.previous.isChar(')') && (rt.beginToken.previous.previous instanceof TextToken)) && rt.beginToken.previous.previous.chars.isAllUpper && rt.beginToken.previous.previous.previous !== null) && rt.beginToken.previous.previous.previous.isChar('(')) {
                rt.beginToken = rt.beginToken.previous.previous.previous;
                dec.addNameStr(rt.beginToken.next.term, new MetaToken(rt.beginToken.next, rt.beginToken.next));
            }
        }
        rtLi.push(rt);
        if (numTok !== null && numTok.children !== null) {
            let end = rt.endToken;
            rt.endToken = numTok.children[0].beginToken.previous;
            if (rt.endToken.isCommaAnd) 
                rt.endToken = rt.endToken.previous;
            for (let ii = 0; ii < numTok.children.length; ii++) {
                let dr1 = new DecreeReferent();
                for (const s of rt.referent.slots) {
                    if (s.typeName === DecreeReferent.ATTR_NUMBER) 
                        dr1.addSlot(s.typeName, numTok.children[ii].value, false, 0).tag = numTok.children[ii].getSourceText();
                    else {
                        let ss = dr1.addSlot(s.typeName, s.value, false, 0);
                        if (ss !== null) 
                            ss.tag = s.tag;
                    }
                }
                let rt1 = new ReferentToken(dr1, numTok.children[ii].beginToken, numTok.children[ii].endToken);
                if (ii === (numTok.children.length - 1)) 
                    rt1.endToken = end;
                rtLi.push(rt1);
            }
        }
        if ((dts.length === 2 && dts[0].typ === DecreeTokenItemType.TYP && dts[0].typKind === DecreeKind.STANDARD) && dts[1].typ === DecreeTokenItemType.NUMBER) {
            for (let ttt = dts[1].endToken.next; ttt !== null; ttt = ttt.next) {
                if (!ttt.isCommaAnd) 
                    break;
                let nu = DecreeToken.tryAttach(ttt.next, dts[0], false);
                if (nu === null || nu.typ !== DecreeTokenItemType.NUMBER) 
                    break;
                let dr1 = new DecreeReferent();
                dr1.typ = dec.typ;
                dr1.addNumber(nu);
                rtLi.push(new ReferentToken(dr1, ttt.next, nu.endToken));
                if (!ttt.isComma) 
                    break;
                ttt = nu.endToken;
            }
        }
        return rtLi;
    }
    
    _processPartsAndChanges(kit, baseTyp) {
        const DecreeReferent = require("./DecreeReferent");
        const DecreeChangeValueReferent = require("./DecreeChangeValueReferent");
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeChangeToken = require("./internal/DecreeChangeToken");
        const PartToken = require("./internal/PartToken");
        const InstrToken1 = require("./../instrument/internal/InstrToken1");
        let ad = kit.getAnalyzerData(this);
        let undefinedDecrees = new Array();
        let rootChange = null;
        let rootChangeQues = null;
        let lastChange = null;
        let changeDecree = null;
        let changePart = new DecreePartReferent();
        let changeStack = new Array();
        let expireRegime = 0;
        let hasStartChange = 0;
        let lastAppend2 = null;
        let hasChangeKeyword = false;
        for (let t = kit.firstToken; t !== null; t = t.next) {
            if (t.isIgnored) 
                continue;
            let dts = null;
            if (t.isNewlineBefore && t.isChar('(')) {
            }
            let dcht = null;
            let ok1 = t.isNewlineBefore;
            let ignNl = false;
            if (!ok1) {
                if (rootChange !== null && t.previous !== null && t.previous.isChar(':')) 
                    ok1 = true;
            }
            if (!ok1) {
                if ((t.previous instanceof ReferentToken) && (t.previous.getReferent() instanceof DecreeChangeReferent)) {
                    ok1 = true;
                    ignNl = expireRegime > 0;
                    for (; t.next !== null; t = t.next) {
                        if (t.isCharOf(";,:.")) {
                        }
                        else if (t.isAnd && !t.isNewlineBefore && !t.next.isCharOf(").>")) {
                        }
                        else if (t.isValue2("А", "ТАКЖЕ") && t.next.next !== null) 
                            t = t.next;
                        else 
                            break;
                    }
                }
            }
            if (!ok1 && t.previous !== null && t.previous.isTableControlChar) {
                if (t.previous.isNewlineBefore || rootChange !== null) 
                    ok1 = true;
            }
            if (ok1) {
                if (t.isValue("Е", null) && t.next !== null && t.next.isChar(')')) {
                }
                if (t.isValue2("ДОПОЛНИТЕЛЬНОЕ", "СОГЛАШЕНИЕ")) 
                    hasChangeKeyword = true;
                if ((t instanceof NumberToken) && t.value === "15") {
                }
                dcht = DecreeChangeToken.tryAttach(t, (rootChange === null ? null : Utils.as(rootChange.referent, DecreeChangeReferent)), false, changeStack, false, false, null, ignNl);
                if (dcht !== null && t.isValue("ПРИЛОЖЕНИЕ", null)) {
                    let line = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
                    if (line !== null && (line.lengthChar < 30)) 
                        dcht = null;
                }
                if (((dcht !== null && dcht.parts !== null && dcht.parts.length === 1) && dcht.beginToken === dcht.parts[0].beginToken && dcht.endToken === dcht.parts[0].endToken) && dcht.isNewlineAfter && dcht.parts[0].typ === PartTokenItemType.CLAUSE) {
                    dcht = null;
                    rootChange = null;
                    changePart.slots.splice(0, changePart.slots.length);
                    expireRegime = 0;
                    changeStack.splice(0, changeStack.length);
                }
                if (dcht !== null) {
                    if (dcht.hasChangeKeyword) 
                        hasChangeKeyword = true;
                    if (dcht.actKind2 === DecreeChangeKind.APPEND && dcht.parts !== null) 
                        lastAppend2 = dcht;
                    else if (lastAppend2 !== null && dcht.parts !== null && dcht.actKind === DecreeChangeKind.UNDEFINED) {
                        dcht.newParts = dcht.parts;
                        dcht.parts = lastAppend2.parts;
                        dcht.realPart = lastAppend2.realPart;
                        if (dcht.realPart !== null) 
                            dcht.parts = null;
                        dcht.actKind = DecreeChangeKind.APPEND;
                    }
                }
            }
            if (dcht !== null && ((dcht.isStart || dcht.changeVal !== null)) && !dcht.ignorable) {
                if (dcht.typ === DecreeChangeTokenTyp.STARTMULTU) {
                    if (rootChange !== null && dcht.decree === null && dcht.parts !== null) 
                        dcht.typ = DecreeChangeTokenTyp.SINGLE;
                    else {
                        expireRegime = 0;
                        hasStartChange = 3;
                        lastAppend2 = null;
                        rootChange = null;
                        changePart.slots.splice(0, changePart.slots.length);
                        changeDecree = null;
                    }
                }
                else if (dcht.typ === DecreeChangeTokenTyp.SINGLE) {
                    let dcht1 = DecreeChangeToken.tryAttach(dcht.endToken.next, (rootChange === null ? null : Utils.as(rootChange.referent, DecreeChangeReferent)), false, changeStack, false, false, null, false);
                    if (dcht1 !== null && dcht1.isStart && !dcht1.ignorable) {
                        hasStartChange = 2;
                        if (dcht.decreeTok !== null && dcht.decree !== null) {
                            let rt = new ReferentToken(dcht.decree, dcht.decreeTok.beginToken, dcht.decreeTok.endToken);
                            kit.embedToken(rt);
                            t = rt;
                            if (dcht.endChar === t.endChar) 
                                dcht.endToken = t;
                        }
                    }
                }
                else if (dcht.typ === DecreeChangeTokenTyp.STARTSINGLE && dcht.decree !== null && expireRegime === 0) {
                    let ok = (dcht.hasChangeKeyword || lastChange !== null || hasChangeKeyword) || dcht.changeVal !== null || dcht.actKind !== DecreeChangeKind.UNDEFINED;
                    if (!ok && t.getReferent() !== dcht.decree) {
                        for (let tt2 = dcht.endToken.next; tt2 !== null; tt2 = tt2.next) {
                            let next = DecreeChangeToken.tryAttach(tt2, null, true, null, false, false, null, false);
                            if (next !== null) {
                                if (next.changeVal !== null || next.actKind !== DecreeChangeKind.UNDEFINED) 
                                    ok = true;
                                break;
                            }
                            if (tt2.isComma) 
                                continue;
                            if (tt2.isValue("ВНЕСТИ", null)) 
                                ok = true;
                            break;
                        }
                    }
                    if (ok) {
                        hasStartChange = 2;
                        hasChangeKeyword = true;
                        if (dcht.decreeTok !== null) {
                            let rt = new ReferentToken(dcht.decree, dcht.decreeTok.beginToken, dcht.decreeTok.endToken);
                            kit.embedToken(rt);
                            t = rt;
                            if (dcht.endChar === t.endChar) 
                                dcht.endToken = t;
                        }
                    }
                    else 
                        dts = (dcht.parts != null ? dcht.parts : dcht.newParts);
                }
                if (dcht.typ === DecreeChangeTokenTyp.STARTSINGLE && rootChange !== null && dcht.decree === null) 
                    hasStartChange = 2;
                else if ((dcht.typ === DecreeChangeTokenTyp.SINGLE && dcht.decree !== null && dcht.endToken.isChar(':')) && dcht.isNewlineAfter) 
                    hasStartChange = 2;
                if (hasStartChange <= 0 && expireRegime === 0) {
                    dts = PartToken.tryAttachList(t, false, 40);
                    changeStack.splice(0, changeStack.length);
                    if (dcht.actKind === DecreeChangeKind.EXPIRE) 
                        expireRegime = 1;
                    else if (dcht.actKind === DecreeChangeKind.SUSPEND) 
                        expireRegime = 2;
                    if (!dcht.ignorable) 
                        dts = (dcht.parts != null ? dcht.parts : dcht.newParts);
                }
                else {
                    if (dcht.decree !== null) {
                        if (changeDecree !== dcht.decree) 
                            rootChange = null;
                        changeDecree = dcht.decree;
                        changePart.slots.splice(0, changePart.slots.length);
                        changeStack.splice(0, changeStack.length);
                    }
                    if (dcht.actKind === DecreeChangeKind.EXPIRE) 
                        expireRegime = 1;
                    else if (dcht.actKind === DecreeChangeKind.SUSPEND) 
                        expireRegime = 2;
                    else if (dcht.actKind === DecreeChangeKind.EXPIRECHANGES) 
                        expireRegime = 3;
                    if (!dcht.ignorable) {
                        dts = dcht.parts;
                        if ((dts === null && dcht.newParts !== null && dcht.actKind === DecreeChangeKind.UNDEFINED) && dcht.changeVal === null) 
                            dts = dcht.newParts;
                    }
                }
            }
            else {
                dts = PartToken.tryAttachList(t, false, 40);
                if ((dcht === null && t.isNewlineBefore && !t.isCharOf("[")) && !t.isTableControlChar) {
                    let keepExpire = false;
                    if (expireRegime > 0) {
                        let tt3 = t;
                        for (let kk = 0; kk < 3; kk++) {
                            let line = InstrToken1.parse(tt3, true, null, 0, null, false, 0, false, false);
                            if (line === null) 
                                break;
                            if (line.numbers.length > 0) {
                                let ddd = DecreeChangeToken.tryAttach(tt3, null, false, null, false, false, null, false);
                                if (ddd !== null) {
                                    if (ddd.isNewlineAfter) 
                                        keepExpire = true;
                                    else if (ddd.endToken.next.isCharOf(";.")) 
                                        keepExpire = true;
                                }
                            }
                            tt3 = line.endToken.next;
                        }
                    }
                    if (!keepExpire) {
                        expireRegime = 0;
                        hasStartChange--;
                    }
                }
            }
            if (dts !== null && dts.length > 0 && rootChange !== null) {
                if (dts[0].beginChar < rootChange.beginChar) 
                    dts = null;
            }
            if (dts !== null && dts.length === 1) {
                if ((dts[0].typ === PartTokenItemType.FORM || dts[0].typ === PartTokenItemType.FORMULA || dts[0].typ === PartTokenItemType.NAME) || dts[0].typ === PartTokenItemType.TABLE || dts[0].typ === PartTokenItemType.LIST) {
                    if (rootChange === null && ((rootChangeQues === null || dts[0].values.length === 0))) 
                        dts = null;
                }
            }
            if (dts !== null && dts.length === 2 && dts[0].typ === PartTokenItemType.PREFIX) {
                if ((dts[1].typ === PartTokenItemType.FORM || dts[1].typ === PartTokenItemType.FORMULA || dts[1].typ === PartTokenItemType.NAME) || dts[1].typ === PartTokenItemType.TABLE || dts[1].typ === PartTokenItemType.LIST) {
                    if (rootChange === null && ((rootChangeQues === null || dts[0].values.length === 0))) 
                        dts = null;
                }
            }
            if (dts !== null && dts.length >= 1) {
                if (dts[0].typ === PartTokenItemType.FORM || dts[0].typ === PartTokenItemType.TABLE || dts[0].typ === PartTokenItemType.LIST) {
                    if (rootChange === null && ((rootChangeQues === null || dts[0].values.length === 0))) 
                        dts = null;
                }
            }
            if (dcht !== null && dts !== null && !dcht.ignorable) {
                for (const pp of dts) {
                    if (pp.typ === PartTokenItemType.APPENDIX && pp.values.length === 0) {
                        if (!Utils.isNullOrEmpty(changePart.appendix)) 
                            pp.values.push(PartToken.PartValue._new1053(pp.beginToken, pp.endToken, changePart.appendix));
                    }
                    else 
                        changePart.removeSlots(pp.typ);
                }
            }
            if (dcht !== null && dcht.newParts !== null) {
                for (const pp of dcht.newParts) {
                    changePart.removeSlots(pp.typ);
                }
            }
            if (changePart.preamble !== null && changePart.slots.length > 2) 
                changePart.preamble = null;
            if (changePart.nameAsItem !== null) 
                changePart.nameAsItem = null;
            if (changePart.freetext !== null) 
                changePart.freetext = null;
            let rts = DecreeAnalyzer.tryAttachParts(dts, baseTyp, (hasStartChange > 0 ? changeDecree : null), rootChange !== null);
            if (rts !== null) {
            }
            if (dcht !== null && dcht.addParts !== null) {
                for (const dts2 of dcht.addParts) {
                    let rts2 = DecreeAnalyzer.tryAttachParts(dts2, baseTyp, (hasStartChange > 0 ? changeDecree : null), rootChange !== null);
                    if (rts2 === null || rts2.length === 0) 
                        continue;
                    if (rts === null) 
                        rts = rts2;
                    else 
                        rts.splice(rts.length, 0, ...rts2);
                }
            }
            let dprs = null;
            let diaps = null;
            let begs = null;
            let ends = null;
            if (rts !== null) {
                for (const kp of rts) {
                    let dprList = Utils.as(kp.tag, Array);
                    if (dprList === null) 
                        continue;
                    for (let i = 0; i < dprList.length; i++) {
                        let dr = dprList[i];
                        if (dr.owner === null && dr.clause !== null && dr.localTyp === null) {
                            if (!undefinedDecrees.includes(dr)) 
                                undefinedDecrees.push(dr);
                        }
                        if ((dr.clause === null && dr.docPart !== null && dr.part === null) && changePart.clause !== null) {
                            dr.part = dr.docPart;
                            dr.docPart = null;
                        }
                        if (dr.owner !== null && dr.clause !== null) 
                            undefinedDecrees.splice(0, undefinedDecrees.length);
                        let ignLast = false;
                        if (dts.length === 1) {
                            if ((dts[0].typ === PartTokenItemType.SENTENCE || dts[0].typ === PartTokenItemType.INDENTION || dts[0].typ === PartTokenItemType.FORMULA) || dts[0].typ === PartTokenItemType.PREAMBLE) 
                                ignLast = true;
                        }
                        if (dcht !== null && !dcht.ignorable) 
                            dr.addHighLevelInfo(changePart);
                        if (lastChange !== null && lastChange.owners.length > 0) {
                            let dr0 = Utils.as(lastChange.owners[0], DecreePartReferent);
                            if (dr0 !== null && dr.owner === dr0.owner) {
                                if (dr0.appendix !== null && dr.appendix !== null && dr0.appendix !== dr.appendix) {
                                    lastChange = null;
                                    if (changeStack.length === 1) 
                                        changeStack.splice(0, 0, dr);
                                }
                                else {
                                    let mle = dr.getMinLevel();
                                    if (mle === 1 && dr.docPart !== null && dr0.docPart === null) {
                                        dr.part = dr.docPart;
                                        dr.docPart = null;
                                        mle = dr.getMinLevel();
                                    }
                                    if (mle === 0 || mle <= PartToken._getRank(PartTokenItemType.CLAUSE)) {
                                    }
                                    else if (dr.indention !== null && dr.slots.length === 2) 
                                        dr.addHighLevelInfo(dr0);
                                }
                            }
                        }
                        if (dr.tableColumn !== null) {
                            if (rootChange !== null) 
                                dr.table = "0";
                            else 
                                continue;
                        }
                        if (dr.tableRow !== null || dr.tableItem !== null || dr.tableSubItem !== null) {
                            if (dr.table === null) {
                                if (rootChange !== null) 
                                    dr.table = "0";
                                else 
                                    continue;
                            }
                        }
                        dr = Utils.as(ad.registerReferent(dr), DecreePartReferent);
                        if (rts.length === 1 && dprList.length === 1) {
                            if (lastAppend2 !== null && lastAppend2.parts === dts) 
                                lastAppend2.realPart = dr;
                            if (dcht !== null && dcht.parts === dts) 
                                dcht.realPart = dr;
                            if (dcht !== null && dcht.alias !== null && dr.appendix !== null) {
                                let partAliases = null;
                                let oo = null;
                                let wrapoo1444 = new RefOutArgWrapper();
                                let inoutres1445 = kit.miscData.tryGetValue("partAliases", wrapoo1444);
                                oo = wrapoo1444.value;
                                if (!inoutres1445) 
                                    kit.miscData.put("partAliases", (partAliases = new TerminCollection()));
                                else 
                                    partAliases = oo;
                                let term = new Termin();
                                term.initBy(dcht.alias.beginToken, dcht.alias.endToken.previous, dr, false);
                                partAliases.add(term);
                            }
                            if (changeDecree !== null) {
                                if (dr.owner !== null && dr.owner !== changeDecree) {
                                }
                                else if (changeStack.length === 0 || ((dcht !== null && ((dcht.typ === DecreeChangeTokenTyp.SINGLE || dcht.typ === DecreeChangeTokenTyp.STARTSINGLE))))) {
                                    changePart = Utils.as(dr.clone(), DecreePartReferent);
                                    changePart.nameAsItem = null;
                                    changePart.preamble = null;
                                    changeStack.splice(0, 0, changePart);
                                }
                            }
                        }
                        if (dprs === null) 
                            dprs = new Array();
                        dprs.push(dr);
                        let rt = null;
                        if (i === 0) 
                            rt = ReferentToken._new958(dr, kp.beginToken, kp.endToken, kp.morph);
                        else 
                            rt = new ReferentToken(dr, t, t);
                        kit.embedToken(rt);
                        t = rt;
                        if (dprs.length > 1 && t.previous !== null && ((t.previous.isHiphen || t.previous.isValue("ПО", null)))) {
                            if (diaps === null) 
                                diaps = new Hashtable();
                            if (!diaps.containsKey(dprs[dprs.length - 2])) 
                                diaps.put(dprs[dprs.length - 2], dprs[dprs.length - 1]);
                        }
                        if (begs === null) 
                            begs = new Hashtable();
                        if (!begs.containsKey(t.beginChar)) 
                            begs.put(t.beginChar, t);
                        else 
                            begs.put(t.beginChar, t);
                        if (ends === null) 
                            ends = new Hashtable();
                        if (!ends.containsKey(t.endChar)) 
                            ends.put(t.endChar, t);
                        else 
                            ends.put(t.endChar, t);
                        if (dcht !== null && !dcht.ignorable) {
                            if (dcht.beginChar === t.beginChar) 
                                dcht.beginToken = t;
                            if (dcht.endChar === t.endChar) 
                                dcht.endToken = t;
                            if (t.endChar > dcht.endChar) 
                                dcht.endToken = t;
                            dcht.realPart = dr;
                        }
                    }
                }
            }
            if (dts !== null && dts.length > 0 && dts[dts.length - 1].endChar > t.endChar) 
                t = dts[dts.length - 1].endToken;
            if (dcht !== null && ((hasStartChange > 0 || expireRegime > 0)) && !dcht.ignorable) {
                if (dcht.endChar > t.endChar) 
                    t = dcht.endToken;
                let chrt = null;
                if ((dcht.typ === DecreeChangeTokenTyp.SINGLE && dcht.decree !== null && dcht.endToken.isChar(':')) && dcht.actKind === DecreeChangeKind.UNDEFINED) {
                    if (rootChange === null || changeDecree === null) 
                        dcht.typ = DecreeChangeTokenTyp.STARTMULTU;
                    else if (changeDecree !== dcht.decree) 
                        dcht.typ = DecreeChangeTokenTyp.STARTMULTU;
                }
                if (dcht.typ === DecreeChangeTokenTyp.STARTMULTU && ((rootChangeQues === null || rootChangeQues.decree !== dcht.decree))) {
                    rootChange = null;
                    changeStack.splice(0, changeStack.length);
                    if (dcht.decree !== null) {
                        while (dcht.addDecrees !== null && dcht.addDecrees.length > 0) {
                            let d0 = dcht.addDecrees[0];
                            if (d0.owner !== null) {
                                if (dcht.decree.owner === d0.owner) {
                                    dcht.decree = d0.owner;
                                    dcht.addDecrees.splice(0, 1);
                                    continue;
                                }
                                if (d0.owner === dcht.decree || d0 === dcht.decree) {
                                    dcht.addDecrees.splice(0, 1);
                                    continue;
                                }
                            }
                            else if (dcht.decree.owner === d0) {
                                dcht.decree = d0.owner;
                                dcht.addDecrees.splice(0, 1);
                                continue;
                            }
                            break;
                        }
                        changeDecree = dcht.decree;
                    }
                    if (dprs !== null && dprs.length > 0) {
                        if (changeDecree === null && dprs[0].owner !== null) 
                            changeDecree = dprs[0].owner;
                        changeStack.splice(0, 0, dprs[0]);
                        changePart = Utils.as(dprs[0].clone(), DecreePartReferent);
                    }
                    if (((changeStack.length > 0 || dcht.decree !== null)) && expireRegime === 0) {
                        let rch = Utils.as(ad.registerReferent(DecreeChangeReferent._new1447(DecreeChangeKind.CONTAINER)), DecreeChangeReferent);
                        if (changeStack.length > 0) 
                            rch.addSlot(DecreeChangeReferent.ATTR_OWNER, changeStack[0], false, 0);
                        else {
                            rch.addSlot(DecreeChangeReferent.ATTR_OWNER, dcht.decree, false, 0);
                            if (dcht.addDecrees !== null) {
                                for (const d of dcht.addDecrees) {
                                    rch.addSlot(DecreeChangeReferent.ATTR_OWNER, d, false, 0);
                                }
                            }
                        }
                        if (dcht.appExtChanges !== null && rch.value === null) {
                            let appCh = DecreeChangeValueReferent._new1049(DecreeChangeValueKind.EXTAPPENDIX);
                            appCh.value = (dcht.appExtChanges.values.length === 0 ? "" : dcht.appExtChanges.values[0].toString());
                            rch.value = Utils.as(ad.registerReferent(appCh), DecreeChangeValueReferent);
                        }
                        rootChange = new ReferentToken(rch, dcht.beginToken, dcht.endToken);
                        if (rootChange.endToken.isChar(':')) 
                            rootChange.endToken = rootChange.endToken.previous;
                        for (let tt0 = dcht.beginToken.previous; tt0 !== null; tt0 = tt0.previous) {
                            if (tt0.isNewlineBefore && (dcht.beginChar - tt0.beginChar) > 30) {
                                let dcht0 = DecreeChangeToken.tryAttach(tt0, null, false, null, false, false, null, false);
                                if ((dcht0 !== null && dcht0.typ === DecreeChangeTokenTyp.STARTSINGLE && dcht0.decree !== null) && dcht.decree !== null) {
                                    if (dcht0.decree.canBeEquals(dcht.decree, ReferentsEqualType.WITHINONETEXT) || dcht0.decree.canBeEquals(dcht.decree.owner, ReferentsEqualType.WITHINONETEXT)) 
                                        rootChange.beginToken = dcht0.beginToken;
                                }
                                break;
                            }
                        }
                        kit.embedToken(rootChange);
                        t = rootChange;
                        if (t.next !== null && t.next.isChar(':')) 
                            t = t.next;
                    }
                    if (expireRegime === 0) {
                        if (t.isNewlineAfter) 
                            continue;
                        let tt2 = DecreeChangeToken.tryAttach(t.next, null, false, null, false, false, null, false);
                        if (tt2 !== null && tt2.actKind !== DecreeChangeKind.UNDEFINED) {
                        }
                        else 
                            continue;
                    }
                }
                if (dcht.typ === DecreeChangeTokenTyp.SINGLE && dprs !== null && dprs.length === 1) {
                    while (changeStack.length > 0) {
                        if (dprs[0].isAllItemsLessLevel(changeStack[0], true)) 
                            break;
                        else 
                            changeStack.splice(0, 1);
                    }
                    changeStack.splice(0, 0, dprs[0]);
                    if (dprs[0].owner !== null && changeDecree !== dprs[0].owner) {
                        changeDecree = dprs[0].owner;
                        changeStack.splice(0, changeStack.length);
                        changeStack.splice(0, 0, dprs[0]);
                    }
                    changePart = Utils.as(dprs[0].clone(), DecreePartReferent);
                    continue;
                }
                if (dprs === null && dcht.realPart !== null) {
                    dprs = new Array();
                    dprs.push(dcht.realPart);
                }
                if ((dprs === null && dcht.actKind === DecreeChangeKind.REMOVE && changeStack.length > 0) && (changeStack[0] instanceof DecreePartReferent)) {
                    dprs = new Array();
                    dprs.push(Utils.as(changeStack[0], DecreePartReferent));
                }
                let prevPart = null;
                let prev = null;
                for (let tt2 = dcht.beginToken.previous; tt2 !== null; tt2 = tt2.previous) {
                    if (tt2.getReferent() instanceof DecreePartReferent) {
                        if (changeStack.length > 0 && changeStack[0].parentReferent === tt2.getReferent().parentReferent) {
                            prevPart = Utils.as(tt2.getReferent(), DecreePartReferent);
                            break;
                        }
                        if (changeStack.length === 0 && tt2.getReferent().parentReferent === changeDecree) {
                            prevPart = Utils.as(tt2.getReferent(), DecreePartReferent);
                            break;
                        }
                    }
                    if (tt2.lengthChar === 1 || (tt2 instanceof NumberToken)) 
                        continue;
                    prev = Utils.as(tt2.getReferent(), DecreeChangeReferent);
                    if (prev !== null) {
                        if (prev.kind === DecreeChangeKind.NEW) 
                            continue;
                        prevPart = Utils.as(prev.getSlotValue(DecreeChangeReferent.ATTR_OWNER), DecreePartReferent);
                        if (prevPart !== null && ((prevPart.nameAsItem !== null || prevPart.preamble !== null || prevPart.freetext !== null))) {
                            prevPart = null;
                            continue;
                        }
                        if (rootChange !== null && prev !== rootChange.referent && prevPart === null) 
                            changeStack.splice(0, changeStack.length);
                    }
                    break;
                }
                if (dcht.hasAnafor && dcht.parts === null && prevPart !== null) 
                    dcht.realPart = prevPart;
                if (dcht.parts === null && dcht.newParts !== null && dcht.actKind === DecreeChangeKind.UNDEFINED) {
                    if (lastChange !== null && lastChange.kind === DecreeChangeKind.APPEND) {
                        dcht.actKind = DecreeChangeKind.APPEND;
                        dcht.realPart = Utils.as(lastChange.parentReferent, DecreePartReferent);
                    }
                    else if (lastAppend2 !== null && lastAppend2.realPart !== null) {
                        dcht.actKind = DecreeChangeKind.APPEND;
                        dcht.realPart = lastAppend2.realPart;
                    }
                }
                if (dprs !== null && dprs.length > 0) {
                    if (dcht.inPart !== null && dcht.realPart !== null && dprs[0] === dcht.realPart) {
                        let ppp = PartToken.tryAttach(dcht.inPart, null, false, true);
                        if (ppp !== null) {
                            let rp = Utils.as(dcht.realPart.clone(), DecreePartReferent);
                            rp.addSlot(PartToken._getAttrNameByTyp(ppp.typ), "?", false, 0);
                            dcht.realPart = Utils.as(ad.registerReferent(rp), DecreePartReferent);
                            dprs[0] = dcht.realPart;
                        }
                    }
                    chrt = DecreeChangeToken.attachReferents(dprs[0], dcht);
                    if (chrt === null && expireRegime > 0) {
                        chrt = new Array();
                        let dcr = DecreeChangeReferent._new1447((expireRegime === 1 ? DecreeChangeKind.EXPIRE : DecreeChangeKind.SUSPEND));
                        chrt.push(new ReferentToken(dcr, dcht.beginToken, dcht.endToken));
                    }
                    if ((((chrt === null && dcht.actKind === DecreeChangeKind.UNDEFINED && dcht.actKind2 === DecreeChangeKind.UNDEFINED) && prev !== null && prev.kind === DecreeChangeKind.APPEND) && dcht.changeVal !== null && prevPart !== null) && dcht.realPart === null) {
                        dcht.actKind = DecreeChangeKind.APPEND;
                        if (dcht.newParts === null) 
                            dcht.newParts = dcht.parts;
                        dcht.realPart = prevPart;
                        dcht.parts = null;
                        chrt = DecreeChangeToken.attachReferents(prevPart, dcht);
                    }
                }
                else if (dcht.actKind !== DecreeChangeKind.EXPIRE) {
                    let ee = false;
                    if (dcht.partTyp === PartTokenItemType.UNDEFINED) {
                        if (changeStack.length === 0) {
                            ee = true;
                            chrt = DecreeChangeToken.attachReferents(changeDecree, dcht);
                        }
                        else if (prevPart !== null) {
                            ee = true;
                            chrt = DecreeChangeToken.attachReferents(prevPart, dcht);
                        }
                    }
                    if (!ee && changeDecree !== null) {
                        let dr = changeDecree;
                        if (prevPart !== null && prevPart.owner === dr && prevPart.isAllItemsOverThisLevel(dcht.partTyp)) 
                            dr = prevPart;
                        else if (rootChange !== null) {
                            for (let tt2 = t.previous; tt2 !== null && tt2.beginChar > rootChange.endChar; tt2 = tt2.previous) {
                                let rr = tt2.getReferent();
                                if (rr === null) 
                                    continue;
                                let pp = Utils.as(rr, DecreePartReferent);
                                if (pp === null && (rr instanceof DecreeChangeReferent)) 
                                    pp = Utils.as(rr.getSlotValue(DecreePartReferent.ATTR_OWNER), DecreePartReferent);
                                if (pp === null) 
                                    continue;
                                if (pp.owner !== null && pp.owner.kind === DecreeKind.PUBLISHER) 
                                    continue;
                                pp = Utils.as(pp.clone(), DecreePartReferent);
                                let sl = pp.findSlot(PartToken._getAttrNameByTyp(dcht.partTyp), null, true);
                                if (sl !== null) 
                                    Utils.removeItem(pp.slots, sl);
                                if (pp.slots.length > 1 && pp.isAllItemsOverThisLevel(dcht.partTyp)) {
                                    dr = Utils.as(ad.registerReferent(pp), DecreePartReferent);
                                    break;
                                }
                            }
                        }
                        if (dr === changeDecree && changePart.slots.length > 1 && dcht.actKind === DecreeChangeKind.APPEND) {
                            if (changePart.isAllItemsOverThisLevel(dcht.partTyp)) 
                                dr = Utils.as(ad.registerReferent(changePart), DecreePartReferent);
                        }
                        if ((dr instanceof DecreeReferent) && changePart.appendix !== null) 
                            dr = Utils.as(ad.registerReferent(changePart), DecreePartReferent);
                        ee = true;
                        chrt = DecreeChangeToken.attachReferents(dr, dcht);
                    }
                    if (lastChange !== null && !ee && lastChange.owners.length > 0) 
                        chrt = DecreeChangeToken.attachReferents(lastChange.owners[0], dcht);
                }
                if ((dprs === null && chrt === null && ((dcht.typ === DecreeChangeTokenTyp.VALUE || dcht.changeVal !== null))) && changeStack.length > 0) 
                    chrt = DecreeChangeToken.attachReferents((dcht.realPart !== null ? dcht.realPart : (prevPart === null || (changeStack[0] instanceof DecreePartReferent) ? changeStack[0] : prevPart)), dcht);
                if (chrt === null && ((expireRegime > 0 || dcht.actKind === DecreeChangeKind.EXPIRE || dcht.actKind === DecreeChangeKind.SUSPEND)) && dprs === null) {
                    chrt = new Array();
                    if (dcht.decree !== null) {
                        let dcr = DecreeChangeReferent._new1447(DecreeChangeKind.EXPIRE);
                        dcr.addSlot(DecreeChangeReferent.ATTR_OWNER, dcht.decree, false, 0);
                        chrt.push(new ReferentToken(dcr, dcht.beginToken, dcht.endToken));
                    }
                    for (let tt = dcht.endToken.next; tt !== null; tt = tt.next) {
                        if (tt.next === null) 
                            break;
                        if (tt.isCharOf("(<")) {
                            let br = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                            if (br !== null) {
                                tt = br.endToken;
                                chrt[chrt.length - 1].endToken = tt;
                                continue;
                            }
                        }
                        if (!tt.isCommaAnd && !tt.isChar(';')) {
                            if (chrt.length > 0) 
                                break;
                        }
                        else 
                            tt = tt.next;
                        if (tt.getReferent() instanceof DecreeReferent) {
                            let dcr = DecreeChangeReferent._new1447((expireRegime === 1 || dcht.actKind === DecreeChangeKind.EXPIRE ? DecreeChangeKind.EXPIRE : DecreeChangeKind.SUSPEND));
                            dcr.addSlot(DecreeChangeReferent.ATTR_OWNER, tt.getReferent(), false, 0);
                            let rt = new ReferentToken(dcr, tt, tt);
                            if (tt.next !== null && tt.next.isChar('(')) {
                                let br = BracketHelper.tryParse(tt.next, BracketParseAttr.NO, 100);
                                if (br !== null) 
                                    rt.endToken = (tt = br.endToken);
                            }
                            chrt.push(rt);
                            continue;
                        }
                        break;
                    }
                }
                if (chrt === null && dcht.decree !== null && rootChange === null) {
                    if (rootChangeQues !== null && rootChangeQues.decree === dcht.decree && rootChangeQues.typ === DecreeChangeTokenTyp.STARTMULTU) {
                    }
                    else 
                        rootChangeQues = dcht;
                }
                if (chrt !== null) {
                    if (((dprs !== null && dprs.length === 2 && chrt.length === 2) && (chrt[0].referent instanceof DecreeChangeValueReferent) && (chrt[1].referent instanceof DecreeChangeReferent)) && chrt[1].referent.kind === DecreeChangeKind.NEW) {
                        let vals = DecreeChangeToken.splitValue(chrt[0], dprs[0]);
                        let diap = null;
                        if (diaps === null) {
                            diap = new Array();
                            diap.push(dprs[0]);
                            diap.push(dprs[1]);
                        }
                        else if (diaps.length === 1) {
                            for (const kp of diaps.entries) {
                                diap = PartToken.tryCreateBetween(kp.key, kp.value);
                                if (diap !== null) {
                                    diap.splice(0, 0, dprs[0]);
                                    diap.push(dprs[1]);
                                }
                                break;
                            }
                        }
                        if (diap !== null && vals !== null && vals.length === diap.length) {
                            for (let i = 0; i < diap.length; i++) {
                                let drc = new DecreeChangeReferent();
                                drc.kind = DecreeChangeKind.NEW;
                                if (i > 0 && ((i + 1) < diap.length)) 
                                    diap[i] = Utils.as(ad.registerReferent(diap[i]), DecreePartReferent);
                                drc.addSlot(DecreeChangeReferent.ATTR_OWNER, diap[i], false, 0);
                                drc.addSlot(DecreeChangeReferent.ATTR_VALUE, vals[i].referent, false, 0);
                                let rt = new ReferentToken(drc, vals[i].beginToken, vals[i].endToken);
                                if (i === 0) 
                                    rt.beginToken = chrt[1].beginToken;
                                else 
                                    drc.addSlot("SPLIT", "true", false, 0);
                                vals.push(rt);
                            }
                            chrt = vals;
                            diaps = null;
                            dprs = null;
                        }
                    }
                    for (const rt of chrt) {
                        rt.referent = ad.registerReferent(rt.referent);
                        if (rt.referent instanceof DecreeChangeReferent) {
                            lastChange = Utils.as(rt.referent, DecreeChangeReferent);
                            if (dprs !== null && dprs.length > 0) {
                                if (rt.referent.kind !== DecreeChangeKind.NEW) 
                                    changePart = Utils.as(dprs[0].clone(), DecreePartReferent);
                                let ii = 0;
                                for (ii = 0; ii < (dprs.length - 1); ii++) {
                                    lastChange.addSlot(DecreeChangeReferent.ATTR_OWNER, dprs[ii], false, 0);
                                }
                                if (diaps !== null) {
                                    for (const kp of diaps.entries) {
                                        let diap = PartToken.tryCreateBetween(kp.key, kp.value);
                                        if (diap !== null && diap.length > 0) {
                                            kp.key.addSlot("RANGE", "START", false, 0);
                                            kp.value.addSlot("RANGE", "END", false, 0);
                                            for (const d of diap) {
                                                d.addSlot("RANGE", "MIDDLE", false, 0);
                                                let dd = ad.registerReferent(d);
                                                lastChange.addSlot(DecreeChangeReferent.ATTR_OWNER, dd, false, 0);
                                            }
                                        }
                                    }
                                }
                                for (; ii < dprs.length; ii++) {
                                    lastChange.addSlot(DecreeChangeReferent.ATTR_OWNER, dprs[ii], false, 0);
                                }
                            }
                        }
                        if (rt.beginToken === null || rt.endToken === null) 
                            continue;
                        if (begs !== null && begs.containsKey(rt.beginChar)) 
                            rt.beginToken = begs.get(rt.beginChar);
                        if (ends !== null && ends.containsKey(rt.endChar)) 
                            rt.endToken = ends.get(rt.endChar);
                        if (rootChange === null && rootChangeQues !== null) {
                            let rch = Utils.as(ad.registerReferent(DecreeChangeReferent._new1447(DecreeChangeKind.CONTAINER)), DecreeChangeReferent);
                            rch.addSlot(DecreeChangeReferent.ATTR_OWNER, rootChangeQues.decree, false, 0);
                            rootChange = new ReferentToken(rch, rootChangeQues.beginToken, rootChangeQues.endToken);
                            if (rootChange.endToken.isChar(':')) 
                                rootChange.endToken = rootChange.endToken.previous;
                            kit.embedToken(rootChange);
                            rootChangeQues = null;
                        }
                        if (rootChange !== null && (rt.referent instanceof DecreeChangeReferent)) 
                            rootChange.referent.addSlot(DecreeChangeReferent.ATTR_CHILD, rt.referent, false, 0);
                        if (changePart.tableSubItem !== null) 
                            changePart.tableSubItem = null;
                        else 
                            changePart.tableItem = null;
                        kit.embedToken(rt);
                        t = rt;
                        if (begs === null) 
                            begs = new Hashtable();
                        if (!begs.containsKey(t.beginChar)) 
                            begs.put(t.beginChar, t);
                        else 
                            begs.put(t.beginChar, t);
                        if (ends === null) 
                            ends = new Hashtable();
                        if (!ends.containsKey(t.endChar)) 
                            ends.put(t.endChar, t);
                        else 
                            ends.put(t.endChar, t);
                    }
                }
            }
        }
        let own = null;
        for (let t = kit.firstToken; t !== null; t = t.next) {
            let ch = Utils.as(t.getReferent(), DecreeChangeReferent);
            if (ch === null) 
                continue;
            let t0 = Utils.as(t, ReferentToken);
            t = t0;
            if (ch.kind === DecreeChangeKind.CONTAINER) {
                if (ch.children.length === 0) 
                    continue;
                own = ch;
                let dec = Utils.as(ch.getSlotValue(DecreeChangeReferent.ATTR_OWNER), DecreeReferent);
                if (dec !== null && dec.kind === DecreeKind.CONTRACT) 
                    continue;
            }
            let tt = t.next;
            let notAttachVal = false;
            let isPsevdoApp = false;
            while (tt !== null) {
                for (; tt !== null; tt = tt.next) {
                    if (tt.isNewlineBefore) 
                        break;
                }
                if (tt === null) 
                    break;
                let pp = PartToken.tryAttach(tt, null, false, false);
                if (pp !== null) {
                    let tte = pp.endToken.next;
                    if (tte !== null && tte.isCharOf(".)")) 
                        tte = tte.next;
                    if (tte === null || tte.isNewlineAfter) {
                        tt = null;
                        break;
                    }
                    if (tte.isValue2("О", "ВНЕСЕНИИ")) {
                        tt = null;
                        break;
                    }
                }
                if (tt.isValue("ПРИЛОЖЕНИЕ", null)) {
                    let pp2 = PartToken.tryAttach(tt, null, false, false);
                    if (pp2 !== null) {
                        if (pp2.isNewlineAfter || ((pp2.endToken.next !== null && pp2.endToken.next.isValue("К", null)))) {
                            let stop = true;
                            let ooo = Utils.as(ch.getSlotValue(DecreeChangeReferent.ATTR_OWNER), Referent);
                            if ((ooo instanceof DecreeReferent) && tt.previous === t0) {
                                stop = false;
                                let mtt = Utils.as(t0.endToken, MetaToken);
                                if (mtt !== null) {
                                    if (BracketHelper.isBracket(mtt.endToken, false) || BracketHelper.isBracket(mtt.endToken.previous, false)) 
                                        stop = true;
                                    else 
                                        isPsevdoApp = true;
                                }
                            }
                            if (stop) {
                                tt = null;
                                break;
                            }
                        }
                    }
                }
                let ttt = tt;
                let num = ComplexNumToken.tryParse(tt, null, false, false);
                if (num !== null) 
                    ttt = num.endToken.next;
                if (ttt === null) 
                    break;
                if (ttt.getReferent() instanceof DecreeChangeReferent) {
                    tt = null;
                    break;
                }
                let dcr = DecreeChangeToken.tryAttach(tt, ch, false, null, false, false, null, false);
                if (dcr !== null) {
                    if (dcr.isNewlineAfter) {
                        if (tt === dcr.endToken) 
                            tt = dcr.endToken.next;
                        else 
                            tt = dcr.endToken;
                        continue;
                    }
                    if (dcr.endToken.next !== null && dcr.endToken.next.isChar(':') && dcr.endToken.isWhitespaceAfter) {
                        tt = dcr.endToken.next;
                        continue;
                    }
                    if (dcr.actKind !== DecreeChangeKind.UNDEFINED) 
                        notAttachVal = true;
                }
                tt = ttt;
                break;
            }
            if (tt === null) 
                continue;
            t = tt;
            let t1 = null;
            let chh = null;
            let toChangeRegime = false;
            let realPart = null;
            for (; tt !== null; tt = tt.next) {
                chh = Utils.as(tt.getReferent(), DecreeChangeReferent);
                if (chh !== null) {
                    if (tt.isNewlineBefore) 
                        t1 = tt.previous;
                    break;
                }
                if (realPart === null && (tt.getReferent() instanceof DecreePartReferent) && !tt.morph._case.isInstrumental) 
                    realPart = Utils.as(tt.getReferent(), DecreePartReferent);
                if (tt.isValue3("ВСТУПАТЬ", "В", "СИЛУ")) 
                    break;
                if (!tt.isNewlineBefore) 
                    continue;
                t1 = tt.previous;
                if (tt.isValue("НАИМЕНОВАНИЕ", null)) 
                    continue;
                let iii = InstrToken1.parse(tt, true, null, 0, null, false, 0, false, false);
                if (iii !== null) {
                    if (iii.typ === InstrToken1Types.EDITIONS) 
                        break;
                    if (iii.isExpired) 
                        break;
                    if (tt.isTableControlChar) {
                        t1 = (tt = iii.endToken);
                        continue;
                    }
                }
                if (tt.isValue("ИЗМЕНЕНИЯ", null)) {
                    if (tt.isNewlineAfter) 
                        break;
                    if (t.next !== null && tt.next.isComma) 
                        break;
                }
                if (tt.isValue("ПРИЛОЖЕНИЕ", null) || tt.isValue("УТВЕРЖДЕНО", null)) {
                    if (tt === t0.next && isPsevdoApp) {
                    }
                    else 
                        break;
                }
                if (tt.isValue("ПЕРЕЧЕНЬ", null) && tt.isNewlineAfter) 
                    break;
                let ttt = tt;
                let num = ComplexNumToken.tryParse(tt, null, false, false);
                if (num !== null) 
                    ttt = num.endToken.next;
                if (ttt === null) 
                    break;
                chh = Utils.as(ttt.getReferent(), DecreeChangeReferent);
                if (chh !== null) 
                    break;
                if (toChangeRegime) 
                    continue;
                let dcr = DecreeChangeToken.tryAttach(tt, null, false, null, false, false, null, false);
                if (dcr !== null) {
                    if (dcr.isNewlineAfter) 
                        break;
                    if (dcr.endToken.next !== null && dcr.endToken.next.isChar(':') && dcr.endToken.isWhitespaceAfter) 
                        break;
                    if (dcr.typ === DecreeChangeTokenTyp.STARTSINGLE) {
                        if (dcr.actKind !== DecreeChangeKind.UNDEFINED) {
                            toChangeRegime = true;
                            continue;
                        }
                        if (dcr.changeVal !== null) {
                            if ((dcr.beginChar + 5) < dcr.changeVal.beginChar) 
                                toChangeRegime = true;
                            tt = dcr.endToken;
                            continue;
                        }
                        if (dcr.realPart === null) 
                            break;
                        realPart = dcr.realPart;
                        if (dcr.endToken.next !== null) {
                            if (dcr.endToken.next.isValue2("УТРАТИТЬ", "СИЛУ")) 
                                break;
                        }
                    }
                }
            }
            if (t1 === null || chh === null) 
                continue;
            if (chh.kind === DecreeChangeKind.CONTAINER) {
                if (chh.children.length === 0) 
                    continue;
            }
            if (t1.isCharOf(".;")) 
                t1 = t1.previous;
            if ((t1.endChar - t.beginChar) < 20) 
                continue;
            let not = false;
            for (let tt2 = t1; tt2 !== null && tt2.beginChar >= t.beginChar; tt2 = tt2.previous) {
                if (tt2.getReferent() instanceof DecreePartReferent) {
                    not = true;
                    break;
                }
                else if ((tt2 instanceof NumberToken) || tt2.lengthChar === 1) {
                }
                else 
                    break;
            }
            if (not) 
                continue;
            let t00 = t;
            for (; t00 !== null; t00 = t00.previous) {
                if (t00.isNewlineBefore) 
                    break;
            }
            let ok = false;
            for (let ttt = t00; ttt !== null && ttt.endChar <= t1.endChar; ttt = ttt.next) {
                let ttt2 = MiscHelper.checkImage(ttt);
                if (ttt2 !== null) {
                    ttt = ttt2;
                    continue;
                }
                if (ttt.isValue("ДОКУМЕНТ", null)) 
                    break;
                if ((ttt.lengthChar < 4) || (ttt instanceof NumberToken)) 
                    continue;
                ok = true;
                break;
            }
            if (!ok) 
                continue;
            if (((!toChangeRegime && !notAttachVal && BracketHelper.isBracket(t1, false)) && ((ch.kind === DecreeChangeKind.APPEND || ch.kind === DecreeChangeKind.NEW)) && (((t0.endChar + 7) >= t00.beginChar || t0.endToken.next === t || t0.endToken.next.next === t))) && (t0.endToken.getReferent() instanceof DecreeChangeValueReferent)) {
                let val = Utils.as(t0.endToken.getReferent(), DecreeChangeValueReferent);
                val.endChar = t1.beginChar - 1;
                if (!BracketHelper.isBracket(t1, true)) 
                    val.endChar = t1.beginChar;
                val.occurrence[0].endChar = t1.endChar;
                val.value = kit.sofa.text.substring(val.beginChar, val.beginChar + (val.endChar + 1) - val.beginChar);
                ch.occurrence[0].endChar = t1.endChar;
                let rt = new ReferentToken(ch, t0, t1);
                t.kit.embedToken(rt);
                t = rt;
            }
            else if (own !== null) {
                let ch1 = new DecreeChangeReferent();
                ch1.kind = DecreeChangeKind.ERROR;
                if (realPart !== null) 
                    ch1.addSlot(DecreeChangeReferent.ATTR_OWNER, realPart, false, 0);
                own.addSlot(DecreeChangeReferent.ATTR_CHILD, ch1, false, 0);
                let rt = new ReferentToken(ad.registerReferent(ch1), t, t1);
                t.kit.embedToken(rt);
                t = rt;
            }
        }
        let lastChangeToken = null;
        let extVals = new Array();
        for (let t = kit.firstToken; t !== null; t = t.next) {
            let ch = Utils.as(t.getReferent(), DecreeChangeReferent);
            if (ch === null) 
                continue;
            lastChangeToken = t;
            for (const s of ch.slots) {
                if (s.value instanceof DecreeChangeValueReferent) {
                    let v = Utils.as(s.value, DecreeChangeValueReferent);
                    if (v.kind === DecreeChangeValueKind.EXTAPPENDIX) 
                        extVals.push(v);
                }
            }
        }
        if (extVals.length > 0) {
            let t = lastChangeToken.next;
            for (; t !== null; t = t.next) {
                if (!t.isNewlineBefore) 
                    continue;
                if (extVals.length === 0) 
                    break;
                if ((t instanceof TextToken) && t.term === "ПРИЛОЖЕНИЕ" && !t.chars.isAllLower) {
                }
                else 
                    continue;
                let val = Utils.notNull(extVals[0].value, "");
                let tt = Utils.notNull(MiscHelper.checkNumberPrefix(t.next), (t !== null ? t.next : null));
                if (tt === null) 
                    break;
                if (tt instanceof NumberToken) {
                    if (tt.value !== val) 
                        continue;
                    tt = tt.next;
                }
                else if (!Utils.isNullOrEmpty(val)) 
                    continue;
                for (; tt !== null; tt = tt.next) {
                    if (BracketHelper.isBracket(tt, true)) 
                        break;
                    if (tt.isValue("ПРИЛОЖЕНИЕ", null)) 
                        break;
                    let line = InstrToken1.parse(tt, true, null, 0, null, false, 0, false, false);
                    if (line === null) 
                        break;
                    if (tt.chars.isAllLower || tt.isValue("К", null) || tt.isValue("ОТ", null)) {
                        tt = line.endToken;
                        continue;
                    }
                    break;
                }
                if (tt === null || !tt.isNewlineBefore) 
                    continue;
                let tt0 = tt;
                let tt1 = tt;
                for (tt = tt.next; tt !== null; tt = tt.next) {
                    if (!tt.isNewlineBefore) {
                        tt1 = tt;
                        continue;
                    }
                    if ((tt instanceof TextToken) && tt.term === "ПРИЛОЖЕНИЕ" && !tt.chars.isAllLower) {
                    }
                    else {
                        tt1 = tt;
                        continue;
                    }
                    tt = Utils.notNull(MiscHelper.checkNumberPrefix(tt.next), (tt !== null ? tt.next : null));
                    if (tt === null) 
                        break;
                    let stop = true;
                    for (const ni of extVals[0].newItems) {
                        if (ni.startsWith("APPENDIX ")) {
                            let val2 = ni.substring(9);
                            if ((tt instanceof NumberToken) && tt.value === val2) 
                                stop = false;
                        }
                    }
                    if (stop) 
                        break;
                }
                if (BracketHelper.isBracket(tt0, true)) {
                    tt0 = tt0.next;
                    if (BracketHelper.isBracket(tt1, true)) 
                        tt1 = tt1.previous;
                    else if (tt1.isCharOf(";.") && BracketHelper.isBracket(tt1.previous, true)) 
                        tt1 = tt1.previous.previous;
                }
                if (tt0.endChar >= tt1.beginChar) 
                    continue;
                extVals[0].kind = DecreeChangeValueKind.TEXT;
                extVals[0].beginChar = tt0.beginChar;
                extVals[0].endChar = tt1.endChar;
                let rt = new ReferentToken(extVals[0], tt0, tt1);
                extVals[0].value = rt.getSourceText();
                extVals[0].occurrence.splice(0, extVals[0].occurrence.length);
                kit.embedToken(rt);
                t = rt;
                extVals.splice(0, 1);
            }
        }
    }
    
    static canBeStartOfAttachApproved(t) {
        const DecreeToken = require("./internal/DecreeToken");
        const PartToken = require("./internal/PartToken");
        if (!(t instanceof TextToken)) 
            return null;
        if (BracketHelper.canBeStartOfSequence(t, true, false)) {
            if (t.next === null) 
                return null;
            if (t.next.chars.isAllLower || !t.next.chars.isLetter) 
                return null;
            return t;
        }
        if (t instanceof NumberToken) 
            return null;
        let tt = DecreeToken.isKeyword(t, false);
        let doubt = false;
        if (tt === null && ((t.isValue("СОСТАВ", null) || t.isValue("СРОК", null)))) {
            if (t.previous !== null && t.previous.isValue("В", null)) {
                tt = t;
                doubt = true;
            }
        }
        let keyTok = tt;
        if (tt !== null) {
            if (t.isValue("НАСТОЯЩИЙ", null)) 
                return null;
            if (t.chars.isAllLower && ((t.isValue("УСЛОВИЕ", null) || t.isValue("ПОЛОЖЕНИЕ", null)))) 
                return null;
            if (t.previous !== null && t.previous.isValue("НАСТОЯЩИЙ", null)) 
                return null;
            let tt0 = DecreeToken.isKeyword(t.previous, false);
            if (tt0 === tt) 
                return null;
            if (t.previous !== null && DecreeToken.isKeyword(t.previous.previous, false) === tt) 
                return null;
            if (t.isValue("ПЕРЕЧЕНЬ", null) && t.isNewlineBefore && t.morph._case.isNominative) 
                return null;
            let mc0 = t.getMorphClassInDictionary();
            if (mc0.isPronoun) 
                return null;
            tt = t;
        }
        let changes = false;
        if (tt === null || tt.next === null) {
            if ((t.isValue("ИЗМЕНЕНИЕ", null) && (((t.previous instanceof NumberToken) || t.isNewlineBefore)) && t.next !== null) && t.next.isComma) {
                let tt1 = t.next.next;
                if (tt1.isValue3("КОТОРЫЙ", "ВНОСИТЬСЯ", "В")) {
                    if (!t.isNewlineBefore || t.chars.isAllLower) 
                        return t;
                    tt = tt1.next.next.next;
                    changes = true;
                }
                else if (tt1.isValue2("ВНОСИМЫЙ", "В")) {
                    tt1 = tt1.next.next;
                    changes = true;
                }
                else 
                    return null;
            }
            else 
                return null;
        }
        else {
            let cou2 = 7;
            if (doubt) 
                cou2 = 2;
            for (let tt2 = t.previous; tt2 !== null && cou2 > 0; tt2 = tt2.previous,cou2--) {
                if ((tt2.isValue("ВНЕСТИ", null) || tt2.isValue("ВНОСИТЬ", null) || tt2.isValue("ИЗМЕНЕНИЕ", null)) || tt2.isValue("ДОПОЛНИТЬ", null) || tt2.isValue("ИЗЛОЖИТЬ", null)) {
                    changes = true;
                    break;
                }
                if ((((tt2 instanceof NumberToken) || tt2.lengthChar === 1)) && tt2 !== t.previous) 
                    cou2++;
                let pp = PartToken.tryAttach(tt2, null, false, false);
                if (pp !== null && pp.endToken.next === t) {
                    changes = true;
                    break;
                }
            }
            for (let tt2 = t.next; tt2 !== null; tt2 = tt2.next) {
                if (DecreeToken.isKeyword(t, false) !== null) 
                    break;
                if ((tt2.isComma && tt2.next !== null && tt2.next.isValue("УТВЕРЖДЕННЫЙ", null)) && keyTok !== null) 
                    return tt;
                if (tt2.isNewlineBefore) 
                    break;
            }
        }
        if (tt === null) 
            return null;
        if (!changes) {
            if (!(t instanceof TextToken) || !t.chars.isCyrillicLetter || keyTok === null) 
                return null;
            if (t.chars.isAllLower) {
                if (t.previous !== null) {
                    if (t.previous.isValue("В", null) || t.previous.isValue("К", null)) {
                        if (keyTok.next !== null && keyTok.next.isComma) 
                            return null;
                        return tt;
                    }
                }
                return null;
            }
        }
        return tt;
    }
    
    static _checkChangesTo(t) {
        const DecreeReferent = require("./DecreeReferent");
        if (t !== null && ((t.isValue("ПЕРЕЧЕНЬ", null) || t.isValue("СПИСОК", null)))) 
            t = t.next;
        if (t === null || !t.isValue("ИЗМЕНЕНИЕ", null)) 
            return null;
        for (t = t.next; t !== null; t = t.next) {
            if ((t.isComma || t.isValue("КОТОРЫЙ", null) || t.isValue("ВНОСИТЬСЯ", null)) || t.isValue("ВНОСИМЫЙ", null) || t.isValue("В", null)) 
                continue;
            if (t.getReferent() instanceof DecreeReferent) 
                return t;
            if (t instanceof ReferentToken) 
                continue;
            let npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.PARSEPREPOSITION, 0, null);
            if (npt !== null) {
                if (npt.endToken.isValue("РЕАЛИЗАЦИЯ", null) || npt.endToken.isValue("АКТ", null) || npt.endToken.isValue("ВОПРОС", null)) {
                    t = npt.endToken;
                    continue;
                }
            }
            if (t.previous.isValue("В", null)) 
                return t;
            break;
        }
        return null;
    }
    
    static tryAttachApproved(t, ad, aliases = null, attachednames = null, partRegime = false) {
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeReferent = require("./DecreeReferent");
        const DecreeChangeToken = require("./internal/DecreeChangeToken");
        const DecreeToken = require("./internal/DecreeToken");
        const PartToken = require("./internal/PartToken");
        if (t === null) 
            return null;
        let br = null;
        if (BracketHelper.canBeStartOfSequence(t, true, false)) 
            br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
        else if ((t.previous instanceof TextToken) && t.previous.lengthChar === 1 && BracketHelper.canBeStartOfSequence(t.previous, true, false)) 
            br = BracketHelper.tryParse(t.previous, BracketParseAttr.NO, 100);
        if (br !== null) {
            if (br.lengthChar < 20) 
                return null;
            let rt0 = DecreeAnalyzer._tryAttachApproved(br.endToken.next, ad, false, true, aliases);
            if (rt0 !== null) {
                let dr = Utils.as(rt0.referent, DecreeReferent);
                rt0.beginToken = br.beginToken;
                let nam = MiscHelper.getTextValueOfMetaToken(br, GetTextAttr.RESTOREREGISTER);
                if (dr.typ === null) {
                    let dt = DecreeToken.tryAttach(br.beginToken.next, null, false);
                    if (dt !== null && dt.typ === DecreeTokenItemType.TYP) {
                        dr.addTyp(dt);
                        if (dt.endToken.next !== null && dt.endToken.next.isValue("О", null)) {
                            nam = MiscHelper.getTextValue(dt.endToken.next, br.endToken, GetTextAttr.RESTOREREGISTER);
                            br.beginToken = dt.endToken.next;
                        }
                    }
                }
                if (nam !== null) 
                    dr.addNameStr(nam, br);
                return rt0;
            }
            if (br.beginToken === t.previous) 
                return null;
        }
        if ((t instanceof TextToken) && t.term === "ПЕРЕЧЕНЬ") {
        }
        let atok = (attachednames === null ? null : attachednames.tryParse(t, TerminParseAttr.NO));
        if (atok !== null) {
            if (t.isNewlineBefore && atok.isNewlineAfter && !t.chars.isAllLower) 
                return null;
            if (t.isNewlineBefore && t.isValue("ИЗМЕНЕНИЕ", null)) 
                return null;
        }
        let t0 = t;
        let tt = DecreeAnalyzer.canBeStartOfAttachApproved(t);
        if (tt === null) {
            if (atok === null) 
                return null;
            tt = t;
        }
        else 
            t = tt;
        let keyTok = DecreeToken.isKeyword(t, false);
        let doubt = false;
        if (keyTok === null && ((t.isValue("СОСТАВ", null) || t.isValue("СРОК", null) || t.isValue("ФОРМА", null)))) {
            keyTok = t;
            doubt = true;
        }
        if (t.isValue("ГОСУДАРСТВЕННЫЙ", null)) {
        }
        if ((t.next instanceof TextToken) && t.next.isPureVerb) 
            return null;
        let chTok = DecreeAnalyzer._checkChangesTo(t);
        if (chTok !== null && t.isValue("ИЗМЕНЕНИЕ", null)) {
            if (t.previous !== null && t.previous.isValue("ПЕРЕЧЕНЬ", null)) 
                return null;
        }
        if (chTok !== null && (chTok.getReferent() instanceof DecreeReferent)) {
            let dr = Utils.as(chTok.getReferent(), DecreeReferent);
            if (dr.owner !== null) 
                chTok.kit.debedToken(chTok);
        }
        let cou = 0;
        let alias = null;
        let aliasT0 = null;
        let hasNl = false;
        let hasOrg = false;
        let hasVerb = false;
        let lastTok = null;
        let keywordAfter = chTok !== null;
        let hasWich = false;
        let hasRegisterAfter = false;
        let accord = false;
        let changeStartTok = null;
        if ((t.previous !== null && t.previous.isValue("В", null) && t.previous.previous !== null) && t.previous.previous.isValue("ВНОСИТЬСЯ", null)) 
            keywordAfter = true;
        else if ((t.previous !== null && t.previous.isValue("ТЕКСТ", null) && t.previous.previous !== null) && t.previous.previous.isValue("В", null)) 
            keywordAfter = true;
        for (tt = tt.next; tt !== null; tt = tt.next) {
            if (atok !== null) {
                if (tt.endChar <= atok.endChar) 
                    continue;
            }
            if (tt.isValue("УСТАНОВЛЕННЫЙ", null)) {
            }
            if ((++cou) > 100) 
                break;
            lastTok = tt;
            if (tt.isCharOf(";.") || BracketHelper.canBeEndOfSequence(tt, false, null, false) || tt.isHiphen) {
                if (keyTok !== null && keyTok === tt.previous && !keyTok.isValue("СОСТАВ", null)) {
                    if (tt.next === null) 
                        return null;
                    let mc0 = tt.next.getMorphClassInDictionary();
                    if (mc0.isAdjective) {
                    }
                    else 
                        return null;
                }
            }
            if (tt.isTableControlChar) 
                break;
            if (tt.isHiphen && tt.previous === keyTok) 
                break;
            if (tt.isComma && tt.previous === keyTok && tt.next !== null) {
                if (tt.next.isValue("КАСАЮЩИЙСЯ", null)) 
                    break;
                if (tt.next.isValue("КОТОРЫЙ", null) || tt.next.getMorphClassInDictionary().isVerb) {
                }
                else {
                    let ok = false;
                    for (let ttt = tt.next; ttt !== null; ttt = ttt.next) {
                        let npt = NounPhraseHelper.tryParse(ttt, NounPhraseParseAttr.NO, 0, null);
                        if (npt === null) 
                            break;
                        if (ttt.previous.isAnd) {
                            ok = true;
                            tt = npt.endToken;
                            break;
                        }
                        ttt = npt.endToken.next;
                        if (ttt === null || !ttt.isCommaAnd) 
                            break;
                    }
                    if (ok) 
                        continue;
                }
            }
            if (tt.isValue3("В", "СООТВЕТСТВИИ", "С")) 
                accord = true;
            if ((tt instanceof TextToken) && !tt.chars.isLetter && tt.lengthChar === 1) {
                if (!BracketHelper.isBracket(tt, false) && !tt.isCharOf(",.:;№\\/") && !tt.isHiphen) 
                    break;
            }
            if ((!partRegime && tt.isComma && tt.next !== null) && tt.next.isAnd && DecreeToken.isKeyword(tt.next.next, false) !== null) {
                let next = DecreeAnalyzer.tryAttachApproved(tt.next.next, ad, aliases, attachednames, false);
                if (next !== null && next.referent.getSlotValue(DecreeReferent.ATTR_OWNER) !== null) {
                    let nam = MiscHelper.getTextValue(t, tt.previous, GetTextAttr.of((GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE.value()) | (GetTextAttr.RESTOREREGISTER.value())));
                    if (nam === null || (nam.length < 20) || nam.length > 1000) 
                        return null;
                    let dt = DecreeToken.tryAttach(t, null, false);
                    let dec0 = new DecreeReferent();
                    if (dt !== null && dt.typ === DecreeTokenItemType.TYP) 
                        dec0.addTyp(dt);
                    dec0.addNameStr(nam, new MetaToken(t, tt.previous));
                    dec0.owner = next.referent.owner;
                    return ReferentToken._new960(dec0, t, tt, alias);
                }
            }
            let appNum = null;
            let appBefore = null;
            let appOwn = null;
            let isBr = false;
            if ((tt.isValue2("ЯВЛЯЮЩИЙСЯ", "ПРИЛОЖЕНИЕМ") || tt.isValue2("ПРЕДУСМОТРЕННЫЙ", "ПРИЛОЖЕНИЕМ") || tt.isValue3("ПРИВЕДЕННЫЙ", "В", "ПРИЛОЖЕНИИ")) || ((tt.isChar('(') && tt.next !== null && tt.next.isValue("ПРИЛОЖЕНИЕ", null)))) {
                appBefore = tt.previous;
                keywordAfter = true;
                if (tt.isValue("ПРИВЕДЕННЫЙ", null)) 
                    tt = tt.next;
                let pp = PartToken.tryAttach(tt.next, null, false, false);
                if (pp === null) 
                    pp = PartToken.tryAttach(tt.next, null, false, true);
                if (pp === null) 
                    break;
                let tt2 = pp.endToken.next;
                if (tt2 !== null && tt2.isValue("К", null)) 
                    tt2 = tt2.next;
                isBr = tt.isChar('(');
                if (tt2 !== null && (tt2.getReferent() instanceof DecreeReferent)) {
                    let pps = PartToken.tryAttachList(t, false, 40);
                    if (pps !== null && pps.length > 0) 
                        break;
                    appNum = pp;
                    tt = tt2;
                }
                else if (tt2 !== null && tt2.isValue("УКАЗАННЫЙ", null)) {
                    let tt3 = DecreeToken.isKeyword(tt2.next, true);
                    if (tt3 === null) 
                        break;
                    let norm = tt3.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false);
                    let cou4 = 500;
                    for (let tt4 = t.previous; tt4 !== null && cou4 > 0; tt4 = tt4.previous,cou4--) {
                        let dd = Utils.as(tt4.getReferent(), DecreeReferent);
                        if (dd === null) 
                            continue;
                        if (dd.checkTypename(norm)) {
                            appOwn = dd;
                            tt = tt3;
                            appNum = pp;
                            break;
                        }
                    }
                    if (appOwn === null) 
                        break;
                }
                else if (partRegime) {
                    appNum = pp;
                    tt = tt2;
                }
                else 
                    break;
            }
            if (tt.isValue("ПРЕДУСМОТРЕННЫЙ", null)) {
                let pps = PartToken.tryAttachList(tt.next, false, 40);
                if (pps !== null && pps.length > 0) {
                    if (pps[pps.length - 1].decree !== null) {
                        tt = pps[pps.length - 1].endToken;
                        continue;
                    }
                    let tt2 = pps[pps.length - 1].endToken.next;
                    if (tt2 !== null && (tt2.getReferent() instanceof DecreeReferent)) {
                        tt = tt2;
                        continue;
                    }
                    if (tt2 !== null) {
                        let dd = DecreeToken.tryAttach(tt2, null, false);
                        if (dd !== null && dd.typ === DecreeTokenItemType.TYP) {
                            tt = dd.endToken;
                            continue;
                        }
                    }
                }
            }
            if (tt.isComma && tt.next !== null && tt.next.isValue("УСТАНОВЛЕННЫЙ", null)) 
                tt = tt.next;
            if (tt.isValue("УСТАНОВЛЕННЫЙ", null) && tt.next !== null) {
                if (DecreeToken.isKeyword(tt.next, false) !== null || (tt.next.getReferent() instanceof DecreeReferent)) {
                    let ttt2 = null;
                    for (ttt2 = tt.next; ttt2 !== null; ttt2 = ttt2.next) {
                        if (ttt2.isCommaAnd) 
                            continue;
                        if (ttt2.getReferent() instanceof DecreeReferent) 
                            continue;
                        let ddd = DecreeToken.tryAttach(ttt2, null, false);
                        if (ddd === null) 
                            break;
                        if (ddd.typ === DecreeTokenItemType.TYP && ttt2 !== tt.next) 
                            break;
                        ttt2 = ddd.endToken;
                    }
                    if (ttt2 !== null && ttt2.isValue("УТВЕРЖДЕННЫЙ", null)) 
                        tt = ttt2;
                }
            }
            if (tt.isValue("СЛЕДУЮЩИЙ", null)) {
                let npt = NounPhraseHelper.tryParse(tt, NounPhraseParseAttr.NO, 0, null);
                if (npt !== null && npt.endToken.next !== null && npt.endToken.next.isCharOf(":;")) {
                    keywordAfter = true;
                    if (keyTok !== null && keyTok.isValue("УСТАВ", null)) 
                        break;
                    if (npt.endToken.isValue("ИЗМЕНЕНИЕ", null)) 
                        break;
                    if (changeStartTok !== null) 
                        break;
                    return null;
                }
            }
            if (tt.isValue("КОТОРЫЙ", null)) 
                hasWich = true;
            if (tt.isNewlineBefore) {
                if (atok !== null) {
                    if ((tt instanceof TextToken) && tt.chars.isAllLower) {
                    }
                    else 
                        break;
                }
                if (tt.newlinesBeforeCount > 2) 
                    break;
                if (MiscHelper.checkImage(tt) !== null) 
                    break;
                if (DecreeChangeToken._canBeChangeToken(tt, 0, false, false)) 
                    break;
                if (tt instanceof NumberToken) 
                    break;
                if (tt.next !== null && tt.next.isCharOf(".)")) 
                    break;
                if (tt.previous !== null && tt.previous.isCharOf(";.")) 
                    break;
                if ((tt instanceof TextToken) && tt.term === "ИСТОЧНИК") 
                    break;
                if (tt.isValue("ГАРАНТ", null) || tt.isValue("КОНСУЛЬТАНТПЛЮС", null)) 
                    break;
                if (tt.isChar('(')) {
                }
                else if (!tt.chars.isAllUpper && tt.previous.chars.isAllUpper) 
                    break;
                hasNl = true;
                let pp = PartToken.tryAttach(tt, null, false, false);
                if (pp !== null && !tt.chars.isAllLower) 
                    return null;
                if (tt.getReferent() instanceof DecreeReferent) 
                    break;
                if (tt.newlinesBeforeCount > 1) {
                    if (!tt.chars.isAllLower) 
                        break;
                }
            }
            if ((((tt instanceof NumberToken) && tt.value === "1")) || tt.isValue("ДРУГОЙ", null) || tt.isValue("ИНОЙ", null)) {
                if (tt.next !== null && tt.next.isValue("СТОРОНА", null)) 
                    return null;
            }
            if (tt.isCharOf(":;")) {
                if (hasNl) 
                    break;
                if (keyTok !== null && tt === keyTok.next) {
                    if (changeStartTok !== null) 
                        break;
                    return null;
                }
                if (tt.isNewlineAfter) {
                    if (t.previous !== null && t.previous.isValue("В", null)) 
                        break;
                }
            }
            if (tt.isValue2("В", "РЕДАКЦИИ")) {
                tt = tt.next;
                continue;
            }
            if (tt.isChar('(') && tt.next !== null) {
                if (tt.previous === keyTok) 
                    break;
                let dr1 = Utils.as(tt.next.getReferent(), DecreeReferent);
                if (dr1 !== null) {
                    if (dr1.kind === DecreeKind.PUBLISHER) {
                        hasRegisterAfter = true;
                        break;
                    }
                }
                let pr1 = Utils.as(tt.next.getReferent(), DecreePartReferent);
                if (pr1 !== null && pr1.owner !== null && pr1.owner.kind === DecreeKind.PUBLISHER) {
                    hasRegisterAfter = true;
                    break;
                }
                let tt0 = tt;
                let mt = (partRegime ? null : DecreeAnalyzer._checkAliasAfter(tt));
                if (mt !== null) {
                    aliasT0 = tt;
                    alias = mt;
                    tt = mt.endToken;
                    if (tt.next !== null && tt.next.isCommaAnd && (t.endChar < tt0.previous.beginChar)) {
                        let next = DecreeAnalyzer.tryAttachApproved(tt.next.next, ad, aliases, null, false);
                        if (next !== null) {
                            let nam = MiscHelper.getTextValue(t, tt0.previous, GetTextAttr.of((GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE.value()) | (GetTextAttr.RESTOREREGISTER.value())));
                            if (nam === null || (nam.length < 20) || nam.length > 1000) 
                                return null;
                            let dt = DecreeToken.tryAttach(t, null, false);
                            let dec0 = new DecreeReferent();
                            if (dt !== null && dt.typ === DecreeTokenItemType.TYP) 
                                dec0.addTyp(dt);
                            dec0.addNameStr(nam, new MetaToken(t, tt0.previous));
                            dec0.owner = next.referent.owner;
                            return ReferentToken._new960(dec0, t, tt, alias);
                        }
                    }
                    if (atok !== null) 
                        break;
                    continue;
                }
            }
            let tok2 = DecreeToken.isKeyword(tt, false);
            if (tok2 !== null) {
                if (t.previous !== null && t.previous.isValue("В", null) && !hasVerb) {
                }
                else if (!hasVerb) {
                }
                else if (!hasWich) 
                    break;
            }
            let r = tt.previous.getReferent();
            if (r !== null && r.typeName === "ORGANIZATION" && tt === t.next) 
                hasOrg = true;
            if ((!partRegime && (tt.getReferent() instanceof DecreeReferent) && tt.getReferent().owner !== null) && keyTok !== null) {
                let dec0 = Utils.as(tt.getReferent(), DecreeReferent);
                let dtt = DecreeToken.tryAttachList(tt.beginToken, null, 10, false);
                if (dtt !== null && dtt.length > 1) {
                    let rt00 = DecreeAnalyzer._tryAttachApproved(dtt[dtt.length - 1].endToken.next, ad, true, false, aliases);
                    if (rt00 !== null && dec0.owner.canBeEquals(rt00.referent.owner, ReferentsEqualType.WITHINONETEXT) && rt00.endChar === tt.endChar) {
                        let tt1 = tt.kit.debedToken(tt);
                        dec0.owner = null;
                        tt = dtt[dtt.length - 1].endToken.next;
                    }
                }
            }
            let rt0 = (partRegime ? null : DecreeAnalyzer._tryAttachApproved(tt, ad, true, false, aliases));
            if (rt0 === null && appNum !== null) {
                rt0 = new ReferentToken(null, tt, tt);
                let own = (appOwn != null ? appOwn : (Utils.as(tt.getReferent(), DecreeReferent)));
                if (own !== null && own.owner !== null && !partRegime) 
                    own = own.owner;
                let ddd = DecreeReferent._new1455(own);
                rt0.referent = ddd;
                ddd.addSlot(DecreeReferent.ATTR_TYPE, "ПРИЛОЖЕНИЕ", false, 0);
                if (appNum !== null && appNum.values.length === 1) 
                    ddd.addSlot(DecreeReferent.ATTR_NUMBER, appNum.values[0].toString(), false, 0);
            }
            if (rt0 !== null) {
                if (tt.isChar('(') && tt.next.isValue("ВВЕСТИ", null)) 
                    return null;
                let t1 = (appBefore === null ? tt.previous : appBefore);
                if (t1.isComma) 
                    t1 = t1.previous;
                if (aliasT0 !== null) 
                    t1 = aliasT0.previous;
                if (t1.isValue("РЕДАКЦИЯ", null)) 
                    t1 = t1.previous;
                if (t1.isValue("В", null)) 
                    t1 = t1.previous;
                if (t1.isComma) 
                    t1 = t1.previous;
                let t00 = t;
                if (t === t1) 
                    return null;
                let nam = MiscHelper.getTextValue(t, t1, GetTextAttr.of((GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE.value()) | (GetTextAttr.RESTOREREGISTER.value())));
                if (nam === null) 
                    return null;
                if (nam.length > 1000) 
                    return null;
                if (t.next === t1 && (nam.length < 20)) 
                    return null;
                let dt = DecreeToken.tryAttach(t, null, false);
                let dec = Utils.as(rt0.referent, DecreeReferent);
                if (dt !== null && dt.typ === DecreeTokenItemType.TYP && rt0.referent.typ === null) {
                    dec.addTyp(dt);
                    if (dt.endToken.next !== null && dt.endToken.next.isValue("О", "ПРО")) {
                        dec.addNameStr(nam, new MetaToken(t00, t1));
                        t00 = dt.endToken.next;
                        nam = MiscHelper.getTextValue(t00, t1, GetTextAttr.RESTOREREGISTER);
                    }
                    else if (t.isValue("КОНСТИТУЦИЯ", null)) 
                        nam = null;
                }
                if (nam !== null) 
                    dec.addNameStr(nam, (t00.beginChar <= t1.beginChar ? new MetaToken(t00, t1) : null));
                if (dec.slots.length < 2) 
                    return null;
                rt0.beginToken = t;
                rt0.tag = alias;
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) === null) {
                    if (t.previous !== null && t.previous.isValue("В", null) && (t.previous.previous instanceof ReferentToken)) {
                        if (t.previous.previous.getReferent() instanceof OrganizationReferent) {
                            let ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, t.previous.previous.getReferent(), false, 0);
                            ss.addAnnotation(Utils.as(t.previous.previous, ReferentToken));
                        }
                    }
                }
                if (isBr && rt0.endToken.next !== null && rt0.endToken.next.isChar(')')) 
                    rt0.endToken = rt0.endToken.next;
                return rt0;
            }
            let br1 = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
            if (br1 !== null) {
                tt = br1.endToken;
                continue;
            }
            if (tt.isCharOf(".;")) 
                break;
            if (tt.isNewlineBefore && tt.previous !== null && tt.previous.isChar('.')) 
                break;
            if (changeStartTok === null && !accord && DecreeChangeToken._canBeChangeToken(tt, 0, true, false)) {
                if (atok !== null) 
                    break;
                changeStartTok = tt;
                if (tt.previous !== null && tt.previous.isValue("В", null)) 
                    changeStartTok = tt.previous;
            }
            let noVerb = false;
            if ((tt instanceof TextToken) && tt.isPureVerb && !hasWich) {
                hasVerb = true;
                if (tt.isValue2("ИЗЛОЖИТЬ", "В")) 
                    break;
                if (tt.previous.isValue("КОТОРЫЙ", null)) 
                    noVerb = true;
                else if (tt.morph.containsAttr("инф.", null)) 
                    noVerb = true;
                else if (tt.isValue("ПРИМЕНЯТЬСЯ", null)) 
                    noVerb = true;
                else 
                    break;
            }
            let mc = tt.getMorphClassInDictionary();
            if (((mc.isVerb && !mc.isAdjective && !mc.isPreposition) && !mc.isNoun && !noVerb) && tt.morph._case.isUndefined) {
                if ((tt instanceof TextToken) && tt.term.endsWith("СЯ")) {
                }
                else 
                    hasVerb = true;
            }
            if (hasOrg) 
                break;
            if (tt.isComma && tt.next !== null && tt.next.isValue("УТВЕРЖДЕННЫЙ", null)) 
                break;
            if (tt.previous.isComma && DecreeChangeToken._canBeChangeToken(tt, 0, true, false)) 
                break;
        }
        if (partRegime) 
            return null;
        if (atok !== null) {
            let dd = new DecreeReferent();
            dd.addNameStr(atok.termin.canonicText, atok);
            let rt = ReferentToken._new960(dd, t0, (alias === null ? atok.endToken : alias.endToken), alias);
            return rt;
        }
        if (changeStartTok !== null) 
            tt = changeStartTok;
        if (((tt !== null || ((lastTok !== null && (cou < 30))))) && ((keyTok !== null || keywordAfter)) && ((!t.chars.isAllLower || ((t.previous !== null && t.previous.isValue("В", null)))))) {
            if (t.previous !== null && t.previous.isValue("ТЕКСТ", null)) {
                if (t.previous.previous !== null && t.previous.previous.isValue("В", null)) {
                }
                else 
                    return null;
            }
            if (t.chars.isAllLower && !keywordAfter && !hasRegisterAfter) 
                return null;
            let pt = PartToken.tryAttach(t, null, false, false);
            if (pt !== null && pt.values.length > 0) 
                return null;
            if (aliases !== null) {
                let tok = aliases.tryParse(t, TerminParseAttr.NO);
                if (tok !== null) 
                    return new ReferentToken(Utils.as(tok.termin.tag, Referent), t, tok.endToken);
            }
            cou = 500;
            if (atok !== null) 
                cou = 50000;
            if (tt === null) 
                tt = lastTok.previous;
            if (t.previous === null || t.beginChar >= tt.previous.beginChar) 
                return null;
            if (((t.isNewlineBefore || ((t.previous !== null && t.previous.isChar('.'))))) && tt.isNewlineBefore) 
                return null;
            let ty = DecreeToken.tryAttach(t, null, false);
            if (ty !== null && ty.typ === DecreeTokenItemType.TYP) {
                if (t.morph.number === MorphNumber.PLURAL) 
                    return null;
            }
            let typ = (keyTok === null ? null : keyTok.getNormalCaseText(MorphClass.NOUN, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false));
            if (tt.previous.isCharOf(".;:,")) 
                tt = tt.previous;
            if (t.isNewlineBefore) {
                if (t.isValue("ОСНОВЫ", null)) {
                }
                if (tt.isNewlineBefore) 
                    return null;
            }
            let nam = null;
            let nam2 = null;
            nam = MiscHelper.getTextValue(t, tt.previous, GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
            let ignore = false;
            for (let ttt = t.previous; ttt !== null && cou > 0; ttt = ttt.previous,cou--) {
                if (typ === null) 
                    break;
                if (ttt instanceof TextToken) {
                    if (ttt.term === "ПРИКАЗЫВАЮ") 
                        ignore = true;
                }
                if (ttt.isValue2("В", "СООТВЕТСТВИИ")) 
                    ignore = false;
                if (ignore) 
                    continue;
                let dr = Utils.as(ttt.getReferent(), DecreeReferent);
                if (dr === null) 
                    continue;
                if (dr.kind === DecreeKind.PUBLISHER) 
                    continue;
                if (dr.kind === DecreeKind.KODEX || dr.typ === "КОНСТИТУЦИЯ") 
                    continue;
                if (!dr.checkTypename(typ)) {
                    let ok = hasRegisterAfter;
                    if ((lastTok !== null && lastTok.isChar(':') && lastTok.isNewlineAfter) && !doubt) 
                        ok = true;
                    if (ttt.next.isValue("УТВЕРДИТЬ", null) && ((t.beginChar - ttt.next.endChar) < 30)) 
                        ok = true;
                    if (ok) {
                        let dd = new DecreeReferent();
                        dd.addNameStr((nam2 != null ? nam2 : nam), new MetaToken(t, tt.previous));
                        if (dr.owner !== null) 
                            dd.owner = dr.owner;
                        else if (dr.typ !== null) 
                            dd.owner = dr;
                        return new ReferentToken(dd, t, tt.previous);
                    }
                    continue;
                }
                if (dr.findSlot(DecreeReferent.ATTR_NAME, nam, true) !== null) 
                    return new ReferentToken(dr, t, tt.previous);
                if (nam2 !== null && dr.findSlot(DecreeReferent.ATTR_NAME, nam2, true) !== null) 
                    return new ReferentToken(dr, t, tt.previous);
                let nnn = nam;
                for (let k = 1; k < 5; k++) {
                    let ii = nnn.lastIndexOf(',');
                    if (ii < 0) 
                        break;
                    nnn = nnn.substring(0, 0 + ii).trim();
                    if (dr.findSlot(DecreeReferent.ATTR_NAME, nnn, true) === null) 
                        continue;
                    for (let tte = tt.previous; tte !== null; tte = tte.previous) {
                        if (tte.isComma) {
                            if ((--k) === 0) {
                                if (t.beginChar <= tte.previous.beginChar) 
                                    return new ReferentToken(dr, t, tte.previous);
                            }
                        }
                    }
                    break;
                }
                if (dr.name !== null) {
                    let term = new Termin(dr.name);
                    let tok = term.tryParse(t, TerminParseAttr.NO);
                    if (tok !== null) 
                        return new ReferentToken(dr, t, tok.endToken);
                    let nam0 = dr.name;
                    for (let i = 0; (i < nam0.length) && (i < nam.length); i++) {
                        if (nam0[i] !== nam[i]) {
                            if (i >= 50) 
                                return new ReferentToken(dr, t, tt.previous);
                            break;
                        }
                    }
                }
                if (ty === null) {
                    let dd = new DecreeReferent();
                    dd.addNameStr((nam2 != null ? nam2 : nam), new MetaToken(t, tt.previous));
                    if (dr.owner !== null) 
                        dd.owner = dr.owner;
                    else if (dr.typ !== null) 
                        dd.owner = dr;
                    return new ReferentToken(dd, t, tt.previous);
                }
            }
            if (keyTok !== null && keyTok.isValue("УСТАВ", null) && keyTok.next === tt.previous) {
                if ((tt.previous.getReferent() instanceof GeoReferent) || (tt.previous.getReferent() instanceof OrganizationReferent)) {
                    let dr = new DecreeReferent();
                    dr.addSlot(DecreeReferent.ATTR_TYPE, "УСТАВ", false, 0);
                    dr.addSlot(DecreeReferent.ATTR_NAME, nam, false, 0);
                    return new ReferentToken(dr, t, tt.previous);
                }
            }
            let ok1 = false;
            if ((((t0 instanceof TextToken) && t0.term === "ИЗМЕНЕНИЯ" && !t0.chars.isAllLower) && t0.isNewlineBefore && keywordAfter) && tt.isNewlineBefore) 
                ok1 = true;
            else if (keyTok !== null) {
                let ttt2 = t0.previous;
                for (; ttt2 !== null; ttt2 = ttt2.previous) {
                    if ((ttt2.isValue("ТЕКСТ", null) || ttt2.isValue("В", null) || ttt2.isCharOf(".)")) || (ttt2 instanceof NumberToken)) {
                    }
                    else {
                        if (ttt2.isNewlineAfter) 
                            ok1 = true;
                        break;
                    }
                }
            }
            if (ok1 && DecreeChangeToken._canBeChangeToken(tt, 0, false, false)) {
                if (keyTok !== null) {
                    if (keyTok.isValue("АКТ", null) && keyTok.morph.number === MorphNumber.PLURAL) 
                        return null;
                }
                if (DecreeChangeToken._tryParseSpecialPart0(t, false) !== null) 
                    return null;
                let dr = new DecreeReferent();
                dr.addSlot(DecreeReferent.ATTR_NAME, nam, false, 0);
                return new ReferentToken(dr, t, tt.previous);
            }
        }
        return null;
    }
    
    static _tryAttachApproved(t, ad, mustBeComma = true, nameInBrackets = false, aliases = null) {
        const DecreeReferent = require("./DecreeReferent");
        const DecreeToken = require("./internal/DecreeToken");
        if (t === null) 
            return null;
        if (t.getReferent() instanceof DecreeReferent) {
            let rt0 = DecreeAnalyzer._tryAttachApproved(t.beginToken, ad, true, false, null);
            if (rt0 !== null && rt0.endChar === t.endChar) {
                if (rt0.referent.slots.length <= 1) 
                    return new ReferentToken(rt0.referent, t, t);
                let dr0 = new DecreeReferent();
                dr0.owner = Utils.as((ad === null ? rt0.referent : ad.registerReferent(rt0.referent)), DecreeReferent);
                return new ReferentToken(dr0, t, t);
            }
        }
        if (t.next === null) 
            return null;
        let t0 = t;
        if (!t.isCharOf("(,") && !t.isHiphen) {
            if (t.previous !== null && t.previous.isComma) {
            }
            else if (mustBeComma) 
                return null;
        }
        else 
            t = t.next;
        let ok = false;
        for (; t !== null; t = t.next) {
            if (t.isCommaAnd || t.morph._class.isPreposition) 
                continue;
            if ((t.getReferent() instanceof GeoReferent) && t.getReferent().isCity) 
                continue;
            if ((((((((t.isValue("УТВ", null) || t.isValue("УТВЕРЖДАТЬ", "СТВЕРДЖУВАТИ") || t.isValue("УТВЕРДИТЬ", "ЗАТВЕРДИТИ")) || t.isValue("УТВЕРЖДЕННЫЙ", "ЗАТВЕРДЖЕНИЙ") || t.isValue("РАТИФИЦИРОВАННЫЙ", null)) || t.isValue("ЗАТВЕРДЖУВАТИ", null) || t.isValue("СТВЕРДИТИ", null)) || t.isValue("ЗАТВЕРДИТИ", null) || t.isValue("ПРИНЯТЬ", "ПРИЙНЯТИ")) || t.isValue("ПРИНЯТЫЙ", "ПРИЙНЯТИЙ") || t.isValue("ВВОДИТЬ", "ВВОДИТИ")) || t.isValue("ВВЕСТИ", null) || t.isValue("ВВЕДЕННЫЙ", "ВВЕДЕНИЙ")) || t.isValue("ПОДПИСАТЬ", "ПІДПИСАТИ") || t.isValue("ПОДПИСЫВАТЬ", "ПІДПИСУВАТИ")) || t.isValue("ЗАКЛЮЧИТЬ", "УКЛАСТИ") || t.isValue("ЗАКЛЮЧАТЬ", "УКЛАДАТИ")) {
                ok = true;
                if (t.next !== null && t.next.isChar('.')) 
                    t = t.next;
            }
            else if (t.isValue("УСТАНОВЛЕННЫЙ", null)) {
                let tt = t.previous;
                if (tt !== null && tt.isComma) 
                    tt = tt.previous;
                if (tt !== null) {
                    if (tt.isValue("ПОРЯДОК", null)) 
                        break;
                }
                ok = true;
            }
            else if (t.isValue("ДЕЙСТВИЕ", null) || t.isValue("ДІЯ", null)) {
            }
            else if (t.isValue("ОПРЕДЕЛЕННЫЙ", null) && t.next !== null && (t.next.getReferent() instanceof DecreeReferent)) {
                ok = true;
                t = t.next;
                break;
            }
            else if (nameInBrackets && t0.isHiphen) {
                ok = true;
                break;
            }
            else if (t.isValue2("ПРИЛАГАЕМЫЙ", "К")) {
                ok = true;
                t = t.next;
            }
            else 
                break;
        }
        if (!ok) 
            return null;
        if (t === null) 
            return null;
        if (t.getReferent() instanceof DecreeReferent) {
            let dr = new DecreeReferent();
            dr.owner = Utils.as(t.getReferent(), DecreeReferent);
            if (dr.owner === null) 
                return null;
            let res0 = new ReferentToken(dr, t, t);
            if (t0.isChar('(') && t.next !== null && t.next.isChar(')')) 
                res0.endToken = t.next;
            return res0;
        }
        let kit = t.kit;
        let olev = null;
        let lev = 0;
        let wrapolev1457 = new RefOutArgWrapper();
        let inoutres1458 = kit.miscData.tryGetValue("dovr", wrapolev1457);
        olev = wrapolev1457.value;
        if (!inoutres1458) 
            kit.miscData.put("dovr", (lev = 1));
        else {
            lev = olev;
            if (lev > 2) 
                return null;
            lev++;
            kit.miscData.put("dovr", lev);
        }
        try {
            let dts = DecreeToken.tryAttachList(t, null, 10, false);
            if (dts === null) 
                return null;
            let rt = DecreeAnalyzer.tryAttach(dts, null, ad);
            if (rt === null) {
                let hasDate = 0;
                let hasNum = 0;
                let hasOwn = 0;
                let hasTyp = 0;
                let ii = 0;
                for (ii = 0; ii < dts.length; ii++) {
                    if (dts[ii].typ === DecreeTokenItemType.NUMBER) 
                        hasNum++;
                    else if ((dts[ii].typ === DecreeTokenItemType.DATE && dts[ii].ref !== null && (dts[ii].ref.referent instanceof DateReferent)) && dts[ii].ref.referent.dt !== null) 
                        hasDate++;
                    else if (dts[ii].typ === DecreeTokenItemType.OWNER || dts[ii].typ === DecreeTokenItemType.ORG) 
                        hasOwn++;
                    else if (dts[ii].typ === DecreeTokenItemType.TYP) 
                        hasTyp++;
                    else 
                        break;
                }
                if (ii >= dts.length && hasOwn > 0 && ((hasDate === 1 || hasNum === 1))) {
                    let dr = new DecreeReferent();
                    for (const dt of dts) {
                        if (dt.typ === DecreeTokenItemType.DATE) 
                            dr.addDate(dt);
                        else if (dt.typ === DecreeTokenItemType.NUMBER) 
                            dr.addNumber(dt);
                        else if (dt.typ === DecreeTokenItemType.TYP) 
                            dr.addSlot(DecreeReferent.ATTR_TYPE, dt.value, false, 0);
                        else {
                            let val = dt.value;
                            if (dt.ref !== null && dt.ref.referent !== null) 
                                val = dt.ref.referent;
                            let s = dr.addSlot(DecreeReferent.ATTR_SOURCE, val, false, 0);
                            s.tag = dt.getSourceText();
                            s.addAnnotation(dt);
                            if (dt.ref !== null && (dt.ref.referent instanceof PersonPropertyReferent)) 
                                dr.addExtReferent(dt.ref);
                        }
                    }
                    rt = new Array();
                    rt.push(new ReferentToken(dr, dts[0].beginToken, dts[dts.length - 1].endToken));
                }
            }
            if (((rt === null && dts.length === 1 && dts[0].typ === DecreeTokenItemType.DATE) && dts[0].ref !== null && (dts[0].ref.referent instanceof DateReferent)) && dts[0].ref.referent.dt !== null) {
                let dr = new DecreeReferent();
                dr.addDate(dts[0]);
                rt = new Array();
                rt.push(new ReferentToken(dr, dts[0].beginToken, dts[dts.length - 1].endToken));
            }
            if ((rt === null && dts.length === 1 && dts[0].typ === DecreeTokenItemType.TYP) && aliases !== null) {
                let tok = aliases.tryParse(t, TerminParseAttr.NO);
                if (tok !== null) {
                    let dr = new DecreeReferent();
                    dr.owner = Utils.as(tok.termin.tag, DecreeReferent);
                    rt = new Array();
                    rt.push(new ReferentToken(dr, dts[0].beginToken, tok.endToken));
                }
            }
            if (rt === null && dts.length === 1 && dts[0].typ === DecreeTokenItemType.TYP) {
                let tt2 = dts[0].endToken.next;
                if (tt2 !== null && tt2.isCharOf(";:,")) 
                    tt2 = tt2.next;
                if (tt2 === null || tt2.isNewlineBefore) {
                    for (tt2 = tt2.previous; tt2 !== null; tt2 = tt2.previous) {
                        let dr1 = Utils.as(tt2.getReferent(), DecreeReferent);
                        if (dr1 === null) 
                            continue;
                        if (dr1.owner !== null) 
                            dr1 = dr1.owner;
                        if (dr1.typ !== dts[0].value) 
                            continue;
                        let dr = new DecreeReferent();
                        dr.owner = dr1;
                        rt = new Array();
                        rt.push(new ReferentToken(dr, dts[0].beginToken, dts[0].endToken));
                        break;
                    }
                }
            }
            if (rt === null) 
                return null;
            if (t0.isChar('(') && rt[0].endToken.next !== null && rt[0].endToken.next.isChar(')')) 
                rt[0].endToken = rt[0].endToken.next;
            rt[0].beginToken = t0;
            return rt[0];
        } finally {
            lev--;
            if (lev < 0) 
                lev = 0;
            kit.miscData.put("dovr", lev);
        }
    }
    
    tryAttachPulishers(dts) {
        const DecreeReferent = require("./DecreeReferent");
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeToken = require("./internal/DecreeToken");
        const PartToken = require("./internal/PartToken");
        let i = 0;
        let t1 = null;
        let typ = null;
        let geo = null;
        let org = null;
        let _date = null;
        for (i = 0; i < dts.length; i++) {
            if (dts[i].typ === DecreeTokenItemType.TYP && DecreeToken.getKind(dts[i].value, null) === DecreeKind.PUBLISHER) {
                if (typ !== null) 
                    break;
                typ = dts[i];
                if (dts[i].ref !== null && (dts[i].ref.getReferent() instanceof GeoReferent)) 
                    geo = dts[i].ref;
            }
            else if (dts[i].typ === DecreeTokenItemType.TERR) {
                geo = dts[i].ref;
                t1 = dts[i].endToken;
            }
            else if (dts[i].typ === DecreeTokenItemType.DATE) {
                _date = dts[i];
                t1 = dts[i].endToken;
            }
            else if (dts[i].typ === DecreeTokenItemType.ORG) {
                org = dts[i].ref;
                t1 = dts[i].endToken;
            }
            else 
                break;
        }
        if (typ === null) 
            return null;
        let t = dts[i - 1].endToken.next;
        let res = new Array();
        let num = null;
        let t0 = dts[0].beginToken;
        if (BracketHelper.canBeEndOfSequence(t, true, null, false)) {
            t = t.next;
            if (BracketHelper.canBeStartOfSequence(t0.previous, true, false)) 
                t0 = t0.previous;
        }
        let pub0 = null;
        let pubPart0 = null;
        for (; t !== null; t = t.next) {
            if (t.isCharOf(",;.") || t.isAnd) 
                continue;
            let dt = DecreeToken.tryAttach(t, dts[0], false);
            if ((dt === null && (t instanceof NumberToken) && !t.isNewlineBefore) && res.length === 0) 
                dt = DecreeToken._new1121(t, t, DecreeTokenItemType.NUMBER, t.value);
            if (dt !== null) {
                if (dt.typ === DecreeTokenItemType.NUMBER) {
                    num = dt;
                    pub0 = null;
                    pubPart0 = null;
                    if (t0 === null) 
                        t0 = t;
                    t1 = (t = dt.endToken);
                    continue;
                }
                if (dt.typ === DecreeTokenItemType.DATE) {
                    if (t0 === null) 
                        t0 = t;
                    _date = dt;
                    pub0 = null;
                    pubPart0 = null;
                    t1 = (t = dt.endToken);
                    continue;
                }
                if (dt.typ !== DecreeTokenItemType.MISC && t.lengthChar > 2) 
                    break;
            }
            let pt = PartToken.tryAttach(t, null, false, false);
            if (pt === null && t.isChar('(')) {
                pt = PartToken.tryAttach(t.next, null, false, false);
                if (pt !== null) {
                    if (pt.endToken.next !== null && pt.endToken.next.isChar(')')) 
                        pt.endToken = pt.endToken.next;
                    else 
                        pt = null;
                }
            }
            if (pt !== null) {
                if (pt.typ === PartTokenItemType.PAGE) {
                    t = pt.endToken;
                    continue;
                }
                if (pt.typ !== PartTokenItemType.CLAUSE && pt.typ !== PartTokenItemType.PART && pt.typ !== PartTokenItemType.PAGE) 
                    break;
                if (num === null) 
                    break;
                if (pubPart0 !== null) {
                    if (pt.typ === PartTokenItemType.PART && pubPart0.part === null) {
                    }
                    else if (pt.typ === PartTokenItemType.CLAUSE && pubPart0.clause === null) {
                    }
                    else 
                        pubPart0 = null;
                }
                let pub = pub0;
                let pubPart = pubPart0;
                if (pub === null) {
                    pub = new DecreeReferent();
                    pub.addTyp(typ);
                    if (geo !== null) {
                        let ss = pub.addSlot(DecreeReferent.ATTR_GEO, geo.referent, false, 0);
                        ss.addAnnotation(geo);
                    }
                    if (org !== null) {
                        let ss = pub.addSlot(DecreeReferent.ATTR_SOURCE, org.referent, false, 0);
                        ss.tag = org.getSourceText();
                        ss.addAnnotation(org);
                    }
                    if (_date !== null) 
                        pub.addDate(_date);
                    pub.addNumber(num);
                    res.push(new ReferentToken(pub, (t0 != null ? t0 : t), pt.beginToken.previous));
                }
                if (pubPart === null) {
                    pubPart = DecreePartReferent._new1460(pub);
                    res.push(new ReferentToken(pubPart, pt.beginToken, pt.endToken));
                }
                pub0 = pub;
                if (pt.values.length === 1) {
                    if (pt.typ === PartTokenItemType.CLAUSE) 
                        pubPart.addSlot(DecreePartReferent.ATTR_CLAUSE, pt.values[0].value, false, 0).tag = pt.values[0].sourceValue;
                    else if (pt.typ === PartTokenItemType.PART) 
                        pubPart.addSlot(DecreePartReferent.ATTR_PART, pt.values[0].value, false, 0).tag = pt.values[0].sourceValue;
                }
                else if (pt.values.length > 1) {
                    for (let ii = 0; ii < pt.values.length; ii++) {
                        if (ii > 0) {
                            pubPart = DecreePartReferent._new1460(pub);
                            res.push(new ReferentToken(pubPart, pt.values[ii].beginToken, pt.values[ii].endToken));
                        }
                        else 
                            res[res.length - 1].endToken = pt.values[ii].endToken;
                        if (pt.typ === PartTokenItemType.CLAUSE) 
                            pubPart.addSlot(DecreePartReferent.ATTR_CLAUSE, pt.values[ii].value, false, 0).tag = pt.values[ii].sourceValue;
                        else if (pt.typ === PartTokenItemType.PART) 
                            pubPart.addSlot(DecreePartReferent.ATTR_PART, pt.values[ii].value, false, 0).tag = pt.values[ii].sourceValue;
                    }
                }
                if (pubPart.clause === "6878") {
                }
                pubPart0 = pubPart;
                res[res.length - 1].endToken = pt.endToken;
                t0 = null;
                t = pt.endToken;
                continue;
            }
            if (t instanceof NumberToken) {
                let rt = t.kit.processReferent("DATE", t, "YEAR");
                if (rt !== null) {
                    _date = DecreeToken._new1122(rt.beginToken, rt.endToken, DecreeTokenItemType.DATE);
                    _date.ref = rt;
                    pub0 = null;
                    pubPart0 = null;
                    if (t0 === null) 
                        t0 = t;
                    t1 = (t = rt.endToken);
                    continue;
                }
                if (t.next !== null && t.next.isChar(';')) {
                    if (pubPart0 !== null && pubPart0.clause !== null && pub0 !== null) {
                        let pubPart = new DecreePartReferent();
                        for (const s of pubPart0.slots) {
                            pubPart.addSlot(s.typeName, s.value, false, 0);
                        }
                        pubPart0 = pubPart;
                        pubPart0.clause = t.value.toString();
                        res.push(new ReferentToken(pubPart0, t, t));
                        continue;
                    }
                }
            }
            if (((t instanceof TextToken) && t.chars.isLetter && (t.lengthChar < 3)) && (t.next instanceof NumberToken)) {
                t = t.next;
                continue;
            }
            if ((t.isChar('(') && t.next !== null && t.next.next !== null) && t.next.next.isChar(')')) {
                t = t.next.next;
                continue;
            }
            break;
        }
        if ((res.length === 0 && _date !== null && ((num !== null || typ.value.endsWith("ГАЗЕТА")))) && t1 !== null) {
            let pub = new DecreeReferent();
            pub.addTyp(typ);
            if (geo !== null) 
                pub.addSlot(DecreeReferent.ATTR_GEO, geo.referent, false, 0);
            if (org !== null) 
                pub.addSlot(DecreeReferent.ATTR_SOURCE, org.referent, false, 0).tag = org.getSourceText();
            if (_date !== null) 
                pub.addDate(_date);
            pub.addNumber(num);
            res.push(new ReferentToken(pub, t0, t1));
        }
        return res;
    }
    
    static tryAttachParts(parts, baseTyp, _defOwner, inChanges = false) {
        const DecreeReferent = require("./DecreeReferent");
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeToken = require("./internal/DecreeToken");
        const PartToken = require("./internal/PartToken");
        const InstrToken = require("./../instrument/internal/InstrToken");
        const InstrToken1 = require("./../instrument/internal/InstrToken1");
        if (parts === null || parts.length === 0) 
            return null;
        let i = 0;
        let j = 0;
        if (baseTyp !== null) {
            if (baseTyp.value === "ПОЛОЖЕНИЕ" || baseTyp.value === "ОПРЕДЕЛЕНИЕ") 
                baseTyp = null;
        }
        if (parts.length === 1 && parts[0].morph.number === MorphNumber.PLURAL) {
            if (parts[0].values.length === 0 && parts[0].name === null) 
                return null;
        }
        if ((parts.length === 1 && parts[0].beginToken.previous !== null && parts[0].beginToken.previous.isChar('(')) && parts[0].beginToken.previous.isNewlineBefore) {
            let tt2 = parts[0].endToken.next;
            if (tt2 !== null) {
                if (tt2.isValue("В", null) || tt2.isValue("ВВЕДЕН", null)) 
                    return null;
            }
        }
        for (let jj = 0; jj < (parts.length - 1); jj++) {
            if (parts[jj].decree === null) 
                continue;
            let br = false;
            if (parts[jj].delimAfter) 
                br = true;
            else 
                for (let kk = jj + 1; kk < parts.length; kk++) {
                    if (parts[kk].decree !== null && parts[kk].decree !== parts[jj].decree) 
                        br = true;
                }
            if (!br) 
                continue;
            let parts1 = Array.from(parts);
            parts1.splice(jj + 1, parts.length - jj - 1);
            let res11 = DecreeAnalyzer.tryAttachParts(parts1, baseTyp, _defOwner, inChanges);
            if (res11 === null) 
                break;
            let parts2 = Array.from(parts);
            parts2.splice(0, jj + 1);
            let res22 = DecreeAnalyzer.tryAttachParts(parts2, baseTyp, _defOwner, inChanges);
            if (res22 !== null) 
                res11.splice(res11.length, 0, ...res22);
            return res11;
        }
        for (let jj = 0; jj < (parts.length - 1); jj++) {
            if (parts[jj].typ === PartTokenItemType.NAME && parts[jj].delimAfter && ((jj === 0 || parts[jj - 1].delimAfter))) {
                let parts0 = Array.from(parts);
                if (jj > 0) 
                    parts0.splice(0, jj);
                parts0.splice(0, 1);
                let res11 = DecreeAnalyzer.tryAttachParts(parts0, baseTyp, _defOwner, inChanges);
                if (res11 !== null) {
                    let named = new Array();
                    let snamed = new Array();
                    for (const rr of res11) {
                        let pli = Utils.as(rr.tag, Array);
                        if (pli !== null) {
                            for (const ppp of pli) {
                                let pp2 = new DecreePartReferent();
                                pp2.nameAsItem = "0";
                                pp2.addNamedLevelInfo(ppp);
                                if (!snamed.includes(pp2.toString())) {
                                    named.push(pp2);
                                    snamed.push(pp2.toString());
                                }
                            }
                        }
                    }
                    res11.splice(0, 0, new MetaToken(parts[0].beginToken, parts[0].endToken));
                    res11[0].tag = named;
                    if (jj > 0) {
                        parts0.splice(0, parts0.length);
                        parts0.splice(parts0.length, 0, ...parts);
                        parts0.splice(jj, parts.length - jj);
                        let res00 = DecreeAnalyzer.tryAttachParts(parts0, baseTyp, _defOwner, false);
                        if (res00 !== null) 
                            res11.splice(0, 0, ...res00);
                    }
                    return res11;
                }
            }
        }
        if ((parts[0].typ === PartTokenItemType.NAME && parts[0].morph.number === MorphNumber.PLURAL && parts.length > 2) && parts[1].delimAfter) {
            let res0 = new Array();
            for (i = 1; i < parts.length; i++) {
                let parts0 = new Array();
                for (j = i; j < parts.length; j++) {
                    parts0.push(parts[j]);
                    if (parts[j].delimAfter) 
                        break;
                }
                i = j;
                let res11 = DecreeAnalyzer.tryAttachParts(parts0, baseTyp, _defOwner, inChanges);
                if (res11 !== null) {
                    for (const rr of res11) {
                        let pli = Utils.as(rr.tag, Array);
                        if (pli !== null) {
                            for (const ppp of pli) {
                                ppp.nameAsItem = "0";
                            }
                        }
                        if (rr.beginToken === parts[1].beginToken) 
                            rr.beginToken = parts[0].beginToken;
                        res0.push(rr);
                    }
                }
            }
            return res0;
        }
        if (parts.length === 1 && parts[0].typ === PartTokenItemType.NAME && !inChanges) 
            return null;
        if ((parts.length === 1 && parts[0].decree === null && parts[0].isNewlineBefore) && ((parts[0].isNewlineAfter || ((parts[0].endToken.isValue("К", null) && parts[0].endToken.isNewlineBefore))))) {
            if ((parts[0].typ === PartTokenItemType.APPENDIX || parts[0].typ === PartTokenItemType.CLAUSE || parts[0].typ === PartTokenItemType.SECTION) || parts[0].typ === PartTokenItemType.CHAPTER) 
                return null;
        }
        let tt = parts[parts.length - 1].endToken.next;
        if (_defOwner === null) 
            _defOwner = parts[parts.length - 1].decree;
        if (_defOwner !== null && tt !== null) {
            if (BracketHelper.isBracket(tt, false)) {
                let br = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                if (br !== null && br.endToken.next !== null) 
                    tt = br.endToken.next;
            }
            if (tt.getReferent() instanceof DecreeReferent) 
                _defOwner = null;
            else if (tt.isValue("К", null) && tt.next !== null) {
                if (tt.next.getReferent() instanceof DecreeReferent) 
                    _defOwner = null;
            }
        }
        if ((parts.length === 1 && parts[0].decree === null && ((parts[0].isNewlineBefore || parts[0].beginToken.previous.isTableControlChar))) && parts[0].beginToken.chars.isLetter && !parts[0].beginToken.chars.isAllLower) {
            let t1 = parts[0].endToken.next;
            let br = BracketHelper.tryParse(t1, BracketParseAttr.NO, 100);
            if (br !== null) 
                t1 = br.endToken.next;
            if (t1 !== null && (t1.getReferent() instanceof DecreeReferent) && !parts[0].isNewlineAfter) {
            }
            else if ((t1 !== null && t1.isValue("К", null) && t1.next !== null) && (t1.next.getReferent() instanceof DecreeReferent) && !parts[0].isNewlineAfter) {
            }
            else {
                let li = InstrToken1.parse(parts[0].beginToken, true, null, 0, null, false, 0, false, false);
                if (li !== null && (li.hasVerb)) {
                    if ((parts.length === 1 && parts[0].typ === PartTokenItemType.PART && parts[0].toString().includes("резолют")) && parts[0].isNewlineBefore) 
                        return null;
                }
                else 
                    return null;
            }
        }
        let thisDec = null;
        let isProgram = false;
        let isAddAgree = false;
        if (parts[parts.length - 1].typ !== PartTokenItemType.SUBPROGRAM && parts[parts.length - 1].typ !== PartTokenItemType.ADDAGREE) {
            thisDec = DecreeAnalyzer.ThisDecree.tryAttach(parts[parts.length - 1], baseTyp);
            if (thisDec !== null) {
                if (thisDec.checkDecree(Utils.as(_defOwner, DecreeReferent))) {
                }
                else if ((_defOwner instanceof DecreeReferent) && ((parts[0].typ === PartTokenItemType.APPENDIX || parts[parts.length - 1].typ === PartTokenItemType.APPENDIX))) {
                }
                else 
                    _defOwner = null;
            }
            if (thisDec === null && _defOwner === null) {
                if (parts.length === 1 && parts[0].typ === PartTokenItemType.APPENDIX && parts[0].beginToken === parts[0].endToken) 
                    return null;
                thisDec = DecreeAnalyzer.ThisDecree.tryAttachBack(parts[0].beginToken, baseTyp);
            }
            if (thisDec === null && parts[0].typ === PartTokenItemType.NAME && !inChanges) 
                return null;
            if (thisDec === null) {
                for (const p of parts) {
                    if (p.typ === PartTokenItemType.PART) {
                        let hasClause = false;
                        for (const pp of parts) {
                            if (pp !== p) {
                                if (PartToken._getRank(pp.typ) >= PartToken._getRank(PartTokenItemType.CLAUSE)) 
                                    hasClause = true;
                            }
                        }
                        if (_defOwner instanceof DecreePartReferent) {
                            if (_defOwner.clause !== null) 
                                hasClause = true;
                        }
                        if (!hasClause) 
                            p.typ = PartTokenItemType.DOCPART;
                        else if ((((p === parts[parts.length - 1] && p.endToken.next !== null && p.values.length === 1) && (p.endToken.next.getReferent() instanceof DecreeReferent) && (p.beginToken instanceof TextToken)) && p.beginToken.term === "ЧАСТИ" && (p.endToken instanceof NumberToken)) && p.beginToken.next === p.endToken) 
                            p.typ = PartTokenItemType.DOCPART;
                    }
                }
            }
        }
        else if (parts[parts.length - 1].typ === PartTokenItemType.ADDAGREE) 
            isAddAgree = true;
        else {
            if (parts.length > 1) {
            }
            isProgram = true;
        }
        let defOwner = Utils.as(_defOwner, DecreeReferent);
        if (defOwner === null && thisDec !== null && thisDec.real !== null) 
            defOwner = thisDec.real;
        let docPart = null;
        if (_defOwner instanceof DecreePartReferent) {
            defOwner = _defOwner.owner;
            docPart = _defOwner.docPart;
        }
        let curTyp = null;
        let curTypToken = null;
        if (parts[parts.length - 1].endToken.next !== null && parts[parts.length - 1].endToken.next.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ")) {
            let npt = NounPhraseHelper.tryParse(parts[parts.length - 1].endToken.next.next, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null) {
                curTyp = npt.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false);
                curTypToken = npt.endToken;
                thisDec = null;
            }
        }
        let res = new Array();
        let hasPrefix = false;
        if (parts[0].typ === PartTokenItemType.PREFIX) {
            parts.splice(0, 1);
            hasPrefix = true;
            if (parts.length === 0) 
                return null;
        }
        if ((parts.length === 1 && thisDec === null && parts[0].typ !== PartTokenItemType.SUBPROGRAM) && parts[0].typ !== PartTokenItemType.ADDAGREE) {
            if (parts[0].isDoubt) 
                return null;
            if (parts[0].isNewlineBefore && ((parts[0].values.length <= 1 || ((parts[0].values.length === 2 && parts[0].values[0].endToken.next.isHiphen))))) {
                let tt1 = parts[0].endToken;
                if (tt1.next === null) 
                    return null;
                tt1 = tt1.next;
                if (BracketHelper.canBeStartOfSequence(tt1, false, false)) {
                    let br = BracketHelper.tryParse(tt1, BracketParseAttr.NO, 100);
                    if (br !== null && br.endToken.next !== null) 
                        tt1 = br.endToken.next;
                }
                if (tt1.isChar(',')) {
                }
                else if (tt1.getReferent() instanceof DecreeReferent) {
                }
                else if (tt1.isValue("К", null) && tt1.next !== null && (tt1.next.getReferent() instanceof DecreeReferent)) {
                }
                else if (DecreeAnalyzer._checkOtherTyp(tt1, true) !== null) {
                }
                else if (_defOwner === null) 
                    return null;
                else if (MiscHelper.canBeStartOfSentence(tt1)) 
                    return null;
                else if (tt1.isChar('.')) 
                    return null;
            }
        }
        let asc = new Array();
        let desc = new Array();
        let typs = new Array();
        for (i = 1; i < (parts.length - 1); i++) {
            if (parts[i].typ === PartTokenItemType.SENTENCE || parts[i].typ === PartTokenItemType.FOOTNOTE) {
                parts.push(parts[i]);
                parts.splice(i, 1);
            }
        }
        for (i = 0; i < (parts.length - 2); i++) {
            if ((parts[i].typ === PartTokenItemType.ITEM && parts[i + 1].typ === PartTokenItemType.INDENTION && parts[i + 2].typ === PartTokenItemType.SUBITEM) && !parts[i + 1].delimAfter && !parts[i].delimAfter) {
                let pp = parts[i + 1];
                parts[i + 1] = parts[i + 2];
                parts[i + 2] = pp;
                if (parts[i + 1].delimAfter) {
                    parts[i + 1].delimAfter = false;
                    pp.delimAfter = true;
                }
            }
        }
        let ascCount = 0;
        let descCount = 0;
        let terminators = 0;
        for (i = 0; i < (parts.length - 1); i++) {
            if (!parts[i].hasTerminator) {
                if (parts[i].canBeNextNarrow(parts[i + 1], parts)) {
                    ascCount++;
                    if (parts[i].typ === PartTokenItemType.TABLE && parts[i + 1].typ === PartTokenItemType.ITEM) {
                        for (const p of parts) {
                            if (p.typ === PartTokenItemType.TABLEROW) {
                                ascCount--;
                                descCount++;
                                break;
                            }
                        }
                    }
                }
                if (parts[i + 1].canBeNextNarrow(parts[i], parts)) 
                    descCount++;
            }
            else if ((ascCount > 0 && parts[i].values.length === 1 && parts[i + 1].values.length === 1) && parts[i].canBeNextNarrow(parts[i + 1], parts)) 
                ascCount++;
            else if ((descCount > 0 && parts[i].values.length === 1 && parts[i + 1].values.length === 1) && parts[i + 1].canBeNextNarrow(parts[i], parts)) 
                descCount++;
            else 
                terminators++;
        }
        if (terminators === 0 && ((((descCount > 0 && ascCount === 0)) || ((descCount === 0 && ascCount > 0))))) {
            for (i = 0; i < (parts.length - 1); i++) {
                parts[i].hasTerminator = false;
            }
        }
        for (i = 0; i < parts.length; i++) {
            if (parts[i].typ === PartTokenItemType.PREFIX) 
                continue;
            asc.splice(0, asc.length);
            asc.push(parts[i]);
            typs.splice(0, typs.length);
            typs.push(parts[i].typ);
            for (j = i + 1; j < parts.length; j++) {
                if (((parts[j].values.length === 0 && parts[j].typ !== PartTokenItemType.APPENDIX && parts[j].typ !== PartTokenItemType.PREAMBLE) && parts[j].typ !== PartTokenItemType.NOTICE && parts[j].typ !== PartTokenItemType.TABLE) && parts[j].typ !== PartTokenItemType.FOOTNOTE && parts[j].typ !== PartTokenItemType.FORM) 
                    break;
                else if (!typs.includes(parts[j].typ) && parts[j - 1].canBeNextNarrow(parts[j], parts)) {
                    if (parts[j - 1].delimAfter && terminators === 0) {
                        if (descCount > ascCount) 
                            break;
                        if (((j + 1) < parts.length) && !parts[j].delimAfter && !parts[j].hasTerminator) 
                            break;
                        if (parts[j - 1].typ === PartTokenItemType.ITEM && parts[j].typ === PartTokenItemType.SUBITEM) {
                            if (parts[j].values.length > 0 && parts[j].values[0].toString().includes(".")) 
                                break;
                        }
                    }
                    asc.push(parts[j]);
                    typs.push(parts[j].typ);
                    if (parts[j].hasTerminator) 
                        break;
                }
                else 
                    break;
            }
            desc.splice(0, desc.length);
            desc.push(parts[i]);
            typs.splice(0, typs.length);
            typs.push(parts[i].typ);
            for (j = i + 1; j < parts.length; j++) {
                if ((((parts[j].values.length === 0 && parts[j].name === null && parts[j].typ !== PartTokenItemType.APPENDIX) && parts[j].typ !== PartTokenItemType.PREAMBLE && parts[j].typ !== PartTokenItemType.NOTICE) && parts[j].typ !== PartTokenItemType.FOOTNOTE && parts[j].typ !== PartTokenItemType.TABLE) && parts[j].typ !== PartTokenItemType.FORM) 
                    break;
                else if (((!typs.includes(parts[j].typ) || parts[j].typ === PartTokenItemType.SUBITEM)) && parts[j].canBeNextNarrow(parts[j - 1], parts)) {
                    if (parts[j - 1].delimAfter && terminators === 0) {
                        if (descCount <= ascCount) 
                            break;
                    }
                    desc.push(parts[j]);
                    typs.push(parts[j].typ);
                    if (parts[j].hasTerminator) 
                        break;
                }
                else if (((!typs.includes(parts[j].typ) && parts[j - 1].canBeNextNarrow(parts[j], parts) && (j + 1) === (parts.length - 1)) && parts[j + 1].canBeNextNarrow(parts[j], parts) && parts[j + 1].canBeNextNarrow(parts[j - 1], parts)) && !parts[j].hasTerminator) {
                    desc.splice(desc.length - 1, 0, parts[j]);
                    typs.push(parts[j].typ);
                }
                else if (!typs.includes(parts[j].typ) && parts[j].typ === PartTokenItemType.SENTENCE) {
                    desc.splice(0, 0, parts[j]);
                    typs.push(parts[j].typ);
                    break;
                }
                else if ((!typs.includes(parts[j].typ) && j === (parts.length - 1) && parts[0].canBeNextNarrow(parts[j], parts)) && j === 2) {
                    desc.splice(0, 0, parts[j]);
                    typs.push(parts[j].typ);
                    break;
                }
                else if ((parts[j].typ === PartTokenItemType.ITEM && desc.length > 1 && desc[desc.length - 1].typ === PartTokenItemType.TABLE) && desc[desc.length - 2].typ === PartTokenItemType.TABLEROW) {
                    desc.push(parts[j]);
                    typs.push(parts[j].typ);
                    break;
                }
                else 
                    break;
            }
            desc.reverse();
            let li = (asc.length < desc.length ? desc : asc);
            for (j = 0; j < li.length; j++) {
                li[j].ind = 0;
            }
            while (true) {
                let dr = new DecreePartReferent();
                let tt00 = parts[i].beginToken;
                let tt11 = parts[(i + li.length) - 1].endToken;
                for (let jj = i; jj < (i + li.length); jj++) {
                    if (parts[jj].beginChar < tt00.beginChar) 
                        tt00 = parts[jj].beginToken;
                    if (parts[jj].endChar > tt11.endChar) 
                        tt11 = parts[jj].endToken;
                }
                let rt = new ReferentToken(dr, tt00, tt11);
                if (parts[i].name !== null) 
                    dr.addName(parts[i], null);
                rt.morph = parts[i].morph;
                res.push(rt);
                let slList = new Array();
                for (const p of li) {
                    if (p.name !== null) 
                        dr.addName(p, null);
                    let nam = PartToken._getAttrNameByTyp(p.typ);
                    if (nam !== null) {
                        let sl = Slot._new1463(nam, p, 1);
                        slList.push(sl);
                        if (p.ind < p.values.length) {
                            sl.value = p.values[p.ind];
                            if (Utils.isNullOrEmpty(p.values[p.ind].value)) 
                                sl.value = "0";
                        }
                        else 
                            sl.value = "0";
                    }
                    if (p.ind > 0) 
                        rt.beginToken = p.values[p.ind].beginToken;
                    if ((p.ind + 1) < p.values.length) 
                        rt.endToken = p.values[p.ind].endToken;
                }
                for (const p of parts) {
                    for (const s of slList) {
                        if (s.tag === p) {
                            dr.addSlot(s.typeName, s.value, false, 0);
                            break;
                        }
                    }
                }
                for (j = li.length - 1; j >= 0; j--) {
                    if ((++li[j].ind) >= li[j].values.length) 
                        li[j].ind = 0;
                    else 
                        break;
                }
                if (j < 0) 
                    break;
            }
            if (res.length === 1) {
                for (let ii = i; ii < li.length; ii++) {
                    if (res[0].beginChar > li[ii].beginChar) 
                        res[0].beginToken = li[ii].beginToken;
                    if (res[0].endChar < li[ii].endChar) 
                        res[0].endToken = li[ii].endToken;
                }
            }
            i += (li.length - 1);
        }
        if (res.length === 0) 
            return null;
        for (j = res.length - 1; j > 0; j--) {
            let d0 = Utils.as(res[j].referent, DecreePartReferent);
            let d = Utils.as(res[j - 1].referent, DecreePartReferent);
            if (d0.appendix !== null && d.appendix === null) {
                d.appendix = d0.appendix;
                d.appendixName = d0.appendixName;
            }
            if (d0.appendix2 !== null && d.appendix2 === null) {
                d.appendix2 = d0.appendix2;
                d.appendix2Name = d0.appendix2Name;
            }
            if (d0.docPart !== null && d.docPart === null) 
                d.docPart = d0.docPart;
            else if (docPart !== null && d.docPart === null) 
                d.docPart = docPart;
            if (d0.chapter !== null && d.chapter === null) {
                d.chapter = d0.chapter;
                d.chapterName = d0.chapterName;
            }
            if (d0.section !== null && d.section === null) {
                d.section = d0.section;
                d.sectionName = d0.sectionName;
            }
            if (d0.subSection !== null && d.subSection === null) {
                d.subSection = d0.subSection;
                d.subSectionName = d0.subSectionName;
            }
            if (d0.clause !== null && d.clause === null) {
                d.clause = d0.clause;
                d.clauseName = d0.clauseName;
            }
            if (d0.item !== null && d.item === null && ((d.subItem !== null || d.indention !== null))) {
                if (d0.clause !== null && d0.clause !== d.clause) {
                }
                else 
                    d.item = d0.item;
            }
            if (d0.form !== null && d.form === null) {
                d.form = d0.form;
                d.formName = d0.formName;
            }
            if (d0.table !== null && d.table === null) {
                d.table = d0.table;
                d.tableName = d0.tableName;
            }
            if ((d0.subItem !== null && d.subItem === null && d.indention !== null) && d.item === d0.item) 
                d.subItem = d0.subItem;
        }
        if (res.length === 1 && docPart !== null && res[0].referent.docPart === null) 
            res[0].referent.docPart = docPart;
        if (((parts.length > 2 && res.length === 2 && parts[parts.length - 2].delimAfter) && parts[parts.length - 2].typ === parts[parts.length - 1].typ && res[1].referent.slots.length === 1) && res[1].morph._case.isGenitive && parts[parts.length - 2].endToken.next.isAnd) {
            let pp = Utils.as(res[0].referent.clone(), DecreePartReferent);
            let nam = PartToken._getAttrNameByTyp(parts[parts.length - 1].typ);
            let sl = res[1].referent.findSlot(nam, null, true);
            if (sl !== null) {
                let sl1 = pp.findSlot(nam, null, true);
                if (sl1 !== null) {
                    sl1.value = sl.value;
                    sl1.tag = sl.tag;
                    sl1.count = sl.count;
                    res[1].referent = pp;
                }
            }
        }
        tt = parts[i - 1].endToken;
        let owner = defOwner;
        if (owner !== null && !inChanges && parts[0].anaforRef !== null) {
            for (let tt3 = parts[0].beginToken.previous; tt3 !== null; tt3 = tt3.previous) {
                if (tt3.isComma) 
                    continue;
                if (tt3.getReferent() instanceof DecreeReferent) 
                    owner = Utils.as(tt3.getReferent(), DecreeReferent);
                break;
            }
        }
        let te = tt.next;
        if ((te !== null && owner === null && te.isChar('(')) && parts[0].typ !== PartTokenItemType.SUBPROGRAM && parts[0].typ !== PartTokenItemType.ADDAGREE) {
            let br = BracketHelper.tryParse(te, BracketParseAttr.NO, 100);
            if (br !== null) {
                if (te.next.morph._class.isAdverb) {
                }
                else if (te.next.getReferent() instanceof DecreeReferent) {
                    if (owner === null && te.next.next === br.endToken) {
                        owner = Utils.as(te.next.getReferent(), DecreeReferent);
                        te = br.endToken;
                    }
                }
                else {
                    let s = MiscHelper.getTextValueOfMetaToken(br, GetTextAttr.KEEPREGISTER);
                    if (s !== null) {
                        let rt = res[res.length - 1];
                        rt.endToken = br.endToken;
                        te = br.endToken.next;
                    }
                }
            }
        }
        if (te !== null && te.isCharOf(",;")) 
            te = te.next;
        if (owner === null && (te instanceof ReferentToken)) {
            if ((((owner = Utils.as(te.getReferent(), DecreeReferent)))) !== null) 
                res[res.length - 1].endToken = te;
        }
        if (owner === null) {
            for (j = 0; j < i; j++) {
                if ((((owner = parts[j].decree))) !== null) 
                    break;
            }
        }
        if (te !== null && te.isValue("К", null) && te.next !== null) {
            if (te.next.getReferent() instanceof DecreeReferent) {
                te = te.next;
                if (te.endChar > res[res.length - 1].endChar) 
                    res[res.length - 1].endToken = te;
                owner = Utils.as(te.getReferent(), DecreeReferent);
            }
            else if ((owner !== null && thisDec !== null && thisDec.endChar > te.endChar) && (res[res.length - 1].endChar < thisDec.endChar)) {
                if (thisDec.typ !== "ТИПОВОЙ ДОГОВОР") 
                    res[res.length - 1].endToken = thisDec.endToken;
            }
        }
        if (owner === null && thisDec !== null) {
            let tt0 = res[0].beginToken;
            if (tt0.previous !== null && tt0.previous.isChar('(')) 
                tt0 = tt0.previous;
            if (tt0.previous !== null) {
                if ((((owner = Utils.as(tt0.previous.getReferent(), DecreeReferent)))) !== null) {
                    if (thisDec.typ === owner.typ0) 
                        thisDec = null;
                    else 
                        owner = null;
                }
            }
        }
        if (owner === null && thisDec !== null && thisDec.real !== null) 
            owner = thisDec.real;
        if (owner !== null && parts[0].typ === PartTokenItemType.SUBPROGRAM && owner.kind !== DecreeKind.PROGRAM) 
            owner = null;
        if (owner !== null && parts[0].typ === PartTokenItemType.ADDAGREE && owner.kind !== DecreeKind.CONTRACT) 
            owner = null;
        let ownerPaer = null;
        let locTyp = curTyp;
        if ((((thisDec === null || !thisDec.hasThisRef)) && !inChanges && locTyp === null) && owner === null) {
            let anaforRef = null;
            for (const p of parts) {
                if ((((anaforRef = p.anaforRef))) !== null) 
                    break;
            }
            let isChangeWordAfter = false;
            let tt2 = res[res.length - 1].endToken.next;
            if (tt2 !== null) {
                if (((tt2.isChar(':') || tt2.isValue("ДОПОЛНИТЬ", null) || tt2.isValue("СЛОВО", null)) || tt2.isValue("ИСКЛЮЧИТЬ", null) || tt2.isValue("ИЗЛОЖИТЬ", null)) || tt2.isValue("СЧИТАТЬ", null) || tt2.isValue("ПРИЗНАТЬ", null)) 
                    isChangeWordAfter = true;
            }
            tt2 = parts[0].beginToken.previous;
            if (tt2 !== null) {
                if (((tt2.isValue("ДОПОЛНИТЬ", null) || tt2.isValue("ИСКЛЮЧИТЬ", null) || tt2.isValue("ИЗЛОЖИТЬ", null)) || tt2.isValue("СЧИТАТЬ", null) || tt2.isValue("УСТАНОВЛЕННЫЙ", null)) || tt2.isValue("ОПРЕДЕЛЕННЫЙ", null)) 
                    isChangeWordAfter = true;
            }
            let cou = 0;
            let ugolDelo = false;
            let brackLevel = 0;
            let bt = null;
            let coefBefore = 0;
            let isOverBrr = false;
            if (parts[0].beginToken.previous !== null && parts[0].beginToken.previous.isChar('(')) {
                if (parts[parts.length - 1].endToken.next !== null && parts[parts.length - 1].endToken.next.isChar(')')) {
                    if (parts.length === 1 && parts[0].typ === PartTokenItemType.APPENDIX) {
                    }
                    else {
                        isOverBrr = true;
                        if (owner !== null && DecreeAnalyzer._getDecree(parts[0].beginToken.previous.previous) !== null) 
                            owner = null;
                    }
                }
            }
            for (tt = parts[0].beginToken.previous; tt !== null; tt = tt.previous,coefBefore++) {
                if (tt.isNewlineAfter) {
                    coefBefore += 2;
                    if (((anaforRef === null && !isOverBrr && !ugolDelo) && !isChangeWordAfter && !isProgram) && !isAddAgree) {
                        if (thisDec === null) {
                            if (!tt.isTableControlChar) {
                                if (BracketHelper.canBeStartOfSequence(tt.next, false, false)) 
                                    break;
                                if (ComplexNumToken.tryParse(tt.next, null, false, false) !== null) 
                                    break;
                                if (tt.isCharOf(".;")) 
                                    break;
                            }
                        }
                    }
                }
                if (thisDec !== null && thisDec.hasThisRef) 
                    break;
                if (tt.isTableControlChar) 
                    break;
                if (tt.morph._class.isPreposition) {
                    coefBefore--;
                    continue;
                }
                if (tt instanceof TextToken) {
                    if (BracketHelper.canBeEndOfSequence(tt, false, null, false)) {
                        brackLevel++;
                        continue;
                    }
                    if (BracketHelper.canBeStartOfSequence(tt, false, false)) {
                        if (tt.isChar('(') && tt === parts[0].beginToken.previous) {
                        }
                        else {
                            brackLevel--;
                            coefBefore--;
                        }
                        continue;
                    }
                }
                if (tt.isNewlineBefore) 
                    brackLevel = 0;
                if ((++cou) > 100) {
                    if (((ugolDelo || isProgram || isAddAgree) || anaforRef !== null || thisDec !== null) || isOverBrr) {
                        if (cou > 1000) 
                            break;
                    }
                    else if (isChangeWordAfter) {
                        if (cou > 250) 
                            break;
                    }
                    else 
                        break;
                }
                if (cou < 4) {
                    if (tt.isValue("УГОЛОВНЫЙ", "КРИМІНАЛЬНИЙ") && tt.next !== null && tt.next.isValue("ДЕЛО", "СПРАВА")) 
                        ugolDelo = true;
                }
                if (tt.isCharOf(".")) {
                    coefBefore += 50;
                    if (tt.isNewlineAfter) 
                        coefBefore += 100;
                    continue;
                }
                if (brackLevel > 0) 
                    continue;
                let dr = DecreeAnalyzer._getDecree(tt);
                if (dr !== null) {
                    if (dr.kind === DecreeKind.PUBLISHER) {
                        if ((tt.endChar + 3) < parts[0].beginChar) 
                            continue;
                    }
                    if (ugolDelo && ((dr.name === "УГОЛОВНЫЙ КОДЕКС" || dr.name === "КРИМІНАЛЬНИЙ КОДЕКС"))) 
                        coefBefore = 0;
                    if (dr.kind === DecreeKind.PROGRAM) {
                        if (isProgram) {
                            bt = tt;
                            break;
                        }
                        else 
                            continue;
                    }
                    if (dr.kind === DecreeKind.CONTRACT) {
                        if (isAddAgree) {
                            bt = tt;
                            break;
                        }
                        else if (thisDec !== null && ((dr.typ === thisDec.typ || dr.typ0 === thisDec.typ))) {
                            bt = tt;
                            break;
                        }
                        else 
                            continue;
                    }
                    if (thisDec !== null) {
                        let dpr = Utils.as(tt.getReferent(), DecreePartReferent);
                        if (thisDec.typ === dr.typ || thisDec.typ === dr.typ0) 
                            thisDec.real = dr;
                        else if (dr.name !== null && thisDec.typ !== null && dr.name.startsWith(thisDec.typ.substring(0, 0 + thisDec.typ.length - 1))) {
                            thisDec.real = dr;
                            let words = Utils.splitString(dr.name, ' ', false);
                            for (let ii = 1; ii < words.length; ii++) {
                                if (thisDec.endToken.next !== null && thisDec.endToken.next.isValue(words[ii], null)) 
                                    thisDec.endToken = thisDec.endToken.next;
                                else 
                                    break;
                            }
                        }
                        else if ((thisDec.hasOtherRef && dpr !== null && dpr.clause !== null) && ((thisDec.typ === "СТАТЬЯ" || thisDec.typ === "СТАТТЯ"))) {
                            for (const r of res) {
                                let dpr0 = Utils.as(r.referent, DecreePartReferent);
                                if (dpr0.clause === null) {
                                    dpr0.clause = dpr.clause;
                                    owner = dpr0.owner = dpr.owner;
                                }
                            }
                        }
                        else 
                            continue;
                    }
                    else if (isChangeWordAfter) {
                        if (owner === null) 
                            coefBefore = 0;
                        else if (owner === DecreeAnalyzer._getDecree(tt)) 
                            coefBefore = 0;
                    }
                    bt = tt;
                    break;
                }
                if (dr !== null) 
                    continue;
                if (tt.getReferent() instanceof DecreeChangeReferent) 
                    break;
                let dpr2 = Utils.as(tt.getReferent(), DecreePartReferent);
                if (dpr2 !== null) {
                    if (thisDec !== null) {
                        if (thisDec.typ !== dpr2.localTyp) 
                            continue;
                    }
                    bt = tt;
                    break;
                }
                let dit = DecreeToken.tryAttach(tt, null, false);
                if (dit !== null && dit.typ === DecreeTokenItemType.TYP) {
                    if (thisDec !== null) 
                        continue;
                    if (dit.chars.isCapitalUpper || anaforRef !== null) {
                        bt = tt;
                        break;
                    }
                }
            }
            cou = 0;
            let at = null;
            let coefAfter = 0;
            let alocTyp = null;
            let tt0 = parts[parts.length - 1].endToken.next;
            let hasNewline = false;
            for (let ttt = parts[parts.length - 1].beginToken; ttt.endChar < parts[parts.length - 1].endChar; ttt = ttt.next) {
                if (ttt.isNewlineAfter) 
                    hasNewline = true;
            }
            for (tt = tt0; tt !== null; tt = tt.next,coefAfter++) {
                if (owner !== null && coefAfter > 0) 
                    break;
                if (tt.isNewlineBefore) 
                    break;
                if (tt.isTableControlChar) 
                    break;
                if (tt.isValue("СМ", null)) 
                    break;
                if (anaforRef !== null) 
                    break;
                if (thisDec !== null) {
                    if (tt !== tt0) 
                        break;
                    if (thisDec.real !== null) 
                        break;
                }
                if (InstrToken._checkEntered(tt) !== null) 
                    break;
                if ((tt instanceof TextToken) && tt.isPureVerb) 
                    break;
                if (tt.morph._class.isPreposition || tt.isCommaAnd) {
                    coefAfter--;
                    continue;
                }
                if (tt.morph._class.equals(MorphClass.VERB)) 
                    break;
                if (BracketHelper.canBeEndOfSequence(tt, false, null, false)) 
                    break;
                let pts = PartToken.tryAttachList(tt, false, 40);
                if (pts !== null) {
                    tt = pts[pts.length - 1].endToken;
                    coefAfter--;
                    let ttnn = tt.next;
                    if (ttnn !== null && ttnn.isChar('.')) 
                        ttnn = ttnn.next;
                    let dit = DecreeToken.tryAttach(ttnn, null, false);
                    if (dit !== null && dit.typ === DecreeTokenItemType.TYP) {
                        locTyp = dit.value;
                        break;
                    }
                    continue;
                }
                if (BracketHelper.canBeStartOfSequence(tt, false, false)) {
                    let br = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                    if (br !== null) {
                        coefAfter--;
                        tt = br.endToken;
                        continue;
                    }
                }
                if ((++cou) > 100) 
                    break;
                if (cou > 1 && hasNewline) 
                    break;
                if (tt.isCharOf(".")) {
                    coefAfter += 50;
                    if (tt.isNewlineAfter) 
                        coefAfter += 100;
                    continue;
                }
                if (tt.getReferent() instanceof DecreeChangeReferent) 
                    break;
                let dr = Utils.as(tt.getReferent(), DecreeReferent);
                if (dr !== null && dr.kind !== DecreeKind.PUBLISHER) {
                    if (dr.kind === DecreeKind.PROGRAM) {
                        if (isProgram) {
                            at = tt;
                            break;
                        }
                        else 
                            continue;
                    }
                    if (dr.kind === DecreeKind.CONTRACT) {
                        if (isAddAgree) {
                            at = tt;
                            break;
                        }
                        else 
                            continue;
                    }
                    at = tt;
                    break;
                }
                if (isProgram || isAddAgree) 
                    break;
                if (dr !== null) 
                    continue;
                let tte2 = DecreeAnalyzer._checkOtherTyp(tt, tt === tt0);
                if (tte2 !== null) {
                    at = tte2;
                    if (tt === tt0 && thisDec !== null && thisDec.real === null) {
                        if (thisDec.typ === (Utils.asString(at.tag))) 
                            at = null;
                        else 
                            thisDec = null;
                    }
                    break;
                }
            }
            if (bt !== null && at !== null) {
                if (coefBefore < coefAfter) 
                    at = null;
                else if ((bt instanceof ReferentToken) && (at instanceof TextToken)) 
                    at = null;
                else 
                    bt = null;
            }
            if (owner === null) {
                if (at !== null) {
                    owner = DecreeAnalyzer._getDecree(at);
                    if (at instanceof TextToken) {
                        if ((typeof at.tag === 'string' || at.tag instanceof String)) 
                            locTyp = Utils.asString(at.tag);
                        else 
                            locTyp = at.lemma;
                    }
                }
                else if (bt !== null) {
                    owner = DecreeAnalyzer._getDecree(bt);
                    ownerPaer = Utils.as(bt.getReferent(), DecreePartReferent);
                    if (ownerPaer !== null && locTyp === null) 
                        locTyp = ownerPaer.localTyp;
                }
            }
            else if (coefAfter === 0 && at !== null) {
                let owner1 = DecreeAnalyzer._getDecree(at);
                if (owner1 !== null) 
                    owner = owner1;
            }
            else if (coefBefore === 0 && bt !== null) {
                owner = DecreeAnalyzer._getDecree(bt);
                ownerPaer = Utils.as(bt.getReferent(), DecreePartReferent);
                if (ownerPaer !== null && locTyp === null) 
                    locTyp = ownerPaer.localTyp;
            }
            if (((bt !== null && parts.length === 1 && parts[0].typ === PartTokenItemType.DOCPART) && (bt.getReferent() instanceof DecreePartReferent) && bt.getReferent().clause !== null) && res.length === 1 && owner === bt.getReferent().owner) {
                for (const s of res[0].referent.slots) {
                    if (s.typeName === DecreePartReferent.ATTR_DOCPART) 
                        s.typeName = DecreePartReferent.ATTR_PART;
                }
                res[0].referent.addHighLevelInfo(Utils.as(bt.getReferent(), DecreePartReferent));
            }
        }
        if (owner === null) {
            if (thisDec === null && locTyp === null) {
                if ((parts.length === 1 && parts[0].values.length === 1 && parts[0].typ === PartTokenItemType.APPENDIX) && parts[0].beginToken.chars.isCapitalUpper) {
                }
                else if ((parts[0].beginToken.previous !== null && parts[0].beginToken.previous.isChar('(') && parts[parts.length - 1].endToken.next !== null) && parts[parts.length - 1].endToken.next.isChar(')')) {
                    if (parts[0].typ === PartTokenItemType.PAGE) 
                        return null;
                }
                else if (inChanges) {
                }
                else if (parts.length > 1 && ((parts[0].values.length > 0 || parts[1].values.length > 0))) {
                }
                else if (((parts[0].typ === PartTokenItemType.CLAUSE || parts[0].typ === PartTokenItemType.ITEM || parts[0].typ === PartTokenItemType.APPENDIX)) && parts[0].values.length > 0) {
                    if (parts[0].typ === PartTokenItemType.ITEM && parts[0].beginToken.isValue("П", null)) {
                        if (!(parts[0].values[0].beginToken instanceof NumberToken)) 
                            return null;
                        if (!parts[0].isWhitespaceBefore) {
                            if (!parts[0].beginToken.previous.isCharOf("(,")) 
                                return null;
                        }
                    }
                }
                else 
                    return null;
            }
            for (const r of res) {
                let dr = Utils.as(r.referent, DecreePartReferent);
                if (thisDec !== null) {
                    dr.localTyp = thisDec.typ;
                    if (thisDec.beginChar > r.endChar && r === res[res.length - 1]) 
                        r.endToken = thisDec.endToken;
                }
                else if (locTyp !== null) {
                    if (locTyp === "СТАТЬЯ" && dr.clause !== null) {
                    }
                    else if (locTyp === "ГЛАВА" && dr.chapter !== null) {
                    }
                    else if (locTyp === "ПАРАГРАФ" && dr.paragraph !== null) {
                    }
                    else if (locTyp === "ЧАСТЬ" && dr.part !== null) {
                    }
                    else {
                        dr.localTyp = locTyp;
                        if (r === res[res.length - 1] && !r.isNewlineAfter) {
                            let ttt1 = r.endToken.next;
                            if (ttt1 !== null && ttt1.isComma) 
                                ttt1 = ttt1.next;
                            let at = DecreeAnalyzer._checkOtherTyp(ttt1, true);
                            if (at !== null && (Utils.asString(at.tag)) === locTyp) 
                                r.endToken = at;
                        }
                    }
                }
            }
        }
        else 
            for (const r of res) {
                let dr = Utils.as(r.referent, DecreePartReferent);
                dr.owner = owner;
                if (thisDec !== null && thisDec.real === owner) {
                    if (thisDec.beginChar > r.endChar && r === res[res.length - 1]) 
                        r.endToken = thisDec.endToken;
                }
            }
        if (res.length > 0) {
            let rt = res[res.length - 1];
            if (curTypToken !== null && curTypToken.endChar > rt.endChar) 
                rt.endToken = curTypToken;
            tt = rt.endToken.next;
            if (owner !== null && tt !== null && tt.getReferent() === owner) {
                rt.endToken = tt;
                tt = tt.next;
            }
            if (tt !== null && ((tt.isHiphen || tt.isChar(':')))) 
                tt = tt.next;
            let br = BracketHelper.tryParse(tt, (isProgram ? BracketParseAttr.CANBEMANYLINES : BracketParseAttr.NO), 100);
            if (br !== null && ((tt.isNewlineBefore || br.openChar === '('))) 
                br = null;
            if (br !== null) {
                let ok = true;
                if (br.openChar === '(') {
                    if (parts[0].typ === PartTokenItemType.SUBPROGRAM) 
                        ok = false;
                    else if (PartToken.tryAttach(tt.next, null, false, false) !== null) 
                        ok = false;
                    else 
                        for (let ttt = tt.next; ttt !== null && (ttt.endChar < br.endChar); ttt = ttt.next) {
                            if (ttt === tt.next && tt.next.morph._class.isAdverb) 
                                ok = false;
                            if ((ttt.getReferent() instanceof DecreeReferent) || (ttt.getReferent() instanceof DecreePartReferent)) 
                                ok = false;
                            if (ttt.isValue("РЕДАКЦИЯ", null) && ttt === br.endToken.previous) 
                                ok = false;
                        }
                }
                if (br.endToken.next !== null) {
                    if (br.endToken.next.isValue("ЗАМЕНИТЬ", null) || br.endToken.next.isValue("ИСКЛЮЧИТЬ", null)) 
                        ok = false;
                }
                if (ok && (tt.next.getReferent() instanceof DecreeReferent)) 
                    ok = false;
                if (ok && (tt.next instanceof ReferentToken) && tt.isChar('<')) 
                    ok = false;
                if (ok) {
                    let s = MiscHelper.getTextValueOfMetaToken(br, GetTextAttr.KEEPREGISTER);
                    if (s !== null) {
                        if (br.openChar === '(') 
                            rt.referent.description = s;
                        else 
                            rt.referent.addName(parts[parts.length - 1], br);
                        rt.endToken = br.endToken;
                        if ((rt.endToken.next instanceof ReferentToken) && rt.endToken.next.getReferent() === owner) 
                            rt.endToken = rt.endToken.next;
                    }
                }
            }
            else if ((isProgram && parts[0].values.length > 0 && tt !== null) && tt.isTableControlChar && MiscHelper.canBeStartOfSentence(tt.next)) {
                for (let tt1 = tt.next; tt1 !== null; tt1 = tt1.next) {
                    if (tt1.isTableControlChar) {
                        let s = MiscHelper.getTextValue(tt.next, tt1.previous, GetTextAttr.KEEPREGISTER);
                        if (s !== null) {
                            rt.referent.description = s;
                            rt.endToken = tt1;
                        }
                        break;
                    }
                    else if (tt1.isNewlineBefore) 
                        break;
                }
            }
            if (thisDec !== null) {
                if (thisDec.endChar > res[res.length - 1].endChar) {
                    if (thisDec.typ !== "ТИПОВОЙ ДОГОВОР") 
                        res[res.length - 1].endToken = thisDec.endToken;
                }
            }
        }
        if (ownerPaer !== null && thisDec === null) {
            for (let ii = 0; ii < res.length; ii++) {
                res[ii].referent.addHighLevelInfo((ii === 0 ? ownerPaer : Utils.as(res[ii - 1].referent, DecreePartReferent)));
            }
        }
        if (res.length === 1 && res[0].referent.description === null) {
            if ((res[0].beginToken.previous !== null && res[0].beginToken.previous.isChar('(') && res[0].endToken.next !== null) && res[0].endToken.next.isChar(')')) {
                if (BracketHelper.canBeEndOfSequence(res[0].beginToken.previous.previous, false, null, false)) {
                    let beg = null;
                    for (tt = res[0].beginToken.previous.previous.previous; tt !== null; tt = tt.previous) {
                        if (tt.isNewlineAfter) 
                            break;
                        if (BracketHelper.canBeStartOfSequence(tt, false, false)) {
                            let br = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                            if (br !== null && ((br.endChar + 10) < res[0].beginChar)) 
                                break;
                            if (tt.next.chars.isLetter && !tt.next.chars.isAllLower) 
                                beg = tt;
                        }
                    }
                    if (beg !== null) {
                        if (BracketHelper.isBracket(res[0].beginToken.previous.previous, true) && parts.length === 1) 
                            res[0].referent.addName(parts[0], new MetaToken(beg, res[0].beginToken.previous.previous));
                        else 
                            res[0].referent.description = MiscHelper.getTextValue(beg, res[0].beginToken.previous.previous, GetTextAttr.KEEPREGISTER);
                        res[0].beginToken = beg;
                        res[0].endToken = res[0].endToken.next;
                    }
                }
            }
        }
        if (isProgram) {
            for (i = res.length - 1; i >= 0; i--) {
                let pa = Utils.as(res[i].referent, DecreePartReferent);
                if (pa.subprogram === null) 
                    continue;
                if (pa.owner === null || pa.owner.kind !== DecreeKind.PROGRAM) 
                    res.splice(i, 1);
            }
        }
        if (isAddAgree) {
            for (i = res.length - 1; i >= 0; i--) {
                let pa = Utils.as(res[i].referent, DecreePartReferent);
                if (pa.addagree === null) 
                    continue;
                if (pa.owner === null || pa.owner.kind !== DecreeKind.CONTRACT) 
                    res.splice(i, 1);
            }
        }
        if (!inChanges) {
            for (i = res.length - 1; i >= 0; i--) {
                let pa = Utils.as(res[i].referent, DecreePartReferent);
                if (pa.nameAsItem === null && pa.formula === null) 
                    continue;
                if (pa.slots.length === 2 && pa.owner === null) 
                    res.splice(i, 1);
            }
        }
        if (res.length === 1 && parts.length === 1 && parts[0].addNames !== null) {
            res[0].endToken = parts[0].addNames[0].beginToken.previous;
            for (const br of parts[0].addNames) {
                let dp = Utils.as(res[0].referent.clone(), DecreePartReferent);
                dp.addName(parts[0], br);
                res.push(new ReferentToken(dp, br.beginToken, br.endToken));
            }
        }
        for (const r of res) {
            let p = Utils.as(r.referent, DecreePartReferent);
            if (((p.tableItem !== null || p.tableSubItem !== null)) && p.item !== null && p.tableRow === null) {
                p.tableRow = p.item;
                p.item = null;
            }
        }
        let res1 = new Array();
        for (i = 0; i < res.length; i++) {
            let li = new Array();
            for (j = i; j < res.length; j++) {
                if (res[j].beginToken !== res[i].beginToken) 
                    break;
                else 
                    li.push(Utils.as(res[j].referent, DecreePartReferent));
            }
            let et = null;
            if (j < res.length) 
                et = res[j].beginToken.previous;
            else 
                et = res[res.length - 1].endToken;
            while (et !== null && et.beginChar > res[i].beginChar) {
                if ((et.isChar(',') || et.morph._class.isConjunction || et.isHiphen) || et.isValue("ПО", null)) 
                    et = et.previous;
                else if (MiscHelper.checkNumberPrefix(et) !== null) 
                    et = et.previous;
                else 
                    break;
            }
            res1.push(MetaToken._new1464(res[i].beginToken, (et !== null && et.beginChar >= res[i].beginChar ? et : res[i].beginToken), li, res[i].morph));
            i = j - 1;
        }
        return res1;
    }
    
    get name() {
        return DecreeAnalyzer.ANALYZER_NAME;
    }
    
    get caption() {
        return "Законы и указы";
    }
    
    get description() {
        return "Законы, указы, постановления, распоряжения и т.п.";
    }
    
    clone() {
        return new DecreeAnalyzer();
    }
    
    get typeSystem() {
        const MetaDecreePart = require("./internal/MetaDecreePart");
        return [MetaDecree.GLOBAL_META, MetaDecreePart.GLOBAL_META, MetaDecreeChange.GLOBAL_META, MetaDecreeChangeValue.GLOBAL_META];
    }
    
    get images() {
        const MetaDecreePart = require("./internal/MetaDecreePart");
        let res = new Hashtable();
        res.put(MetaDecree.DECREE_IMAGE_ID, PullentiNerCoreInternalResourceHelper.getBytes("decree.png"));
        res.put(MetaDecree.STANDADR_IMAGE_ID, PullentiNerCoreInternalResourceHelper.getBytes("decreestd.png"));
        res.put(MetaDecreePart.PART_IMAGE_ID, PullentiNerCoreInternalResourceHelper.getBytes("part.png"));
        res.put(MetaDecreePart.PART_LOC_IMAGE_ID, PullentiNerCoreInternalResourceHelper.getBytes("document_into.png"));
        res.put(MetaDecree.PUBLISH_IMAGE_ID, PullentiNerCoreInternalResourceHelper.getBytes("publish.png"));
        res.put(MetaDecreeChange.IMAGE_ID, PullentiNerCoreInternalResourceHelper.getBytes("decreechange.png"));
        res.put(MetaDecreeChangeValue.IMAGE_ID, PullentiNerCoreInternalResourceHelper.getBytes("decreechangevalue.png"));
        return res;
    }
    
    get usedExternObjectTypes() {
        return [DateReferent.OBJ_TYPENAME, GeoReferent.OBJ_TYPENAME, OrganizationReferent.OBJ_TYPENAME, PersonReferent.OBJ_TYPENAME];
    }
    
    createReferent(type) {
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeChangeValueReferent = require("./DecreeChangeValueReferent");
        const DecreeReferent = require("./DecreeReferent");
        if (type === DecreeReferent.OBJ_TYPENAME) 
            return new DecreeReferent();
        if (type === DecreePartReferent.OBJ_TYPENAME) 
            return new DecreePartReferent();
        if (type === DecreeChangeReferent.OBJ_TYPENAME) 
            return new DecreeChangeReferent();
        if (type === DecreeChangeValueReferent.OBJ_TYPENAME) 
            return new DecreeChangeValueReferent();
        return null;
    }
    
    get progressWeight() {
        return 10;
    }
    
    static getData(t) {
        if (t === null) 
            return null;
        return t.kit.getAnalyzerDataByAnalyzerName(DecreeAnalyzer.ANALYZER_NAME);
    }
    
    process(kit) {
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeReferent = require("./DecreeReferent");
        const DecreeToken = require("./internal/DecreeToken");
        const DecreeChangeToken = require("./internal/DecreeChangeToken");
        const PartToken = require("./internal/PartToken");
        let ad = kit.getAnalyzerData(this);
        let baseTyp = null;
        let ref0 = null;
        for (let t = kit.firstToken; t !== null; t = t.next) {
            let r = t.getReferent();
            if (r === null) 
                continue;
            if (!(r instanceof OrganizationReferent)) 
                continue;
            let rt = Utils.as(t, ReferentToken);
            if (t !== null && BracketHelper.canBeStartOfSequence(rt.beginToken, true, false) && BracketHelper.canBeEndOfSequence(rt.endToken, true, null, false)) {
                t = kit.debedToken(rt);
                let rt1 = new ReferentToken(rt.referent, rt.beginToken.next, rt.endToken.previous);
                if (rt.referent.occurrence.length === 0) 
                    rt1.referent = ad.registerReferent(rt.referent);
                kit.embedToken(rt1);
                t = rt1;
                continue;
            }
            if (!rt.beginToken.chars.isAllUpper || rt.beginToken.lengthChar > 4) 
                continue;
            let dtr = DecreeToken.tryAttach(rt.beginToken, null, false);
            if (dtr === null || dtr.typKind !== DecreeKind.KODEX) 
                continue;
            if (rt.beginToken === rt.endToken) {
            }
            else if (rt.beginToken.next === rt.endToken && (rt.endToken.getReferent() instanceof GeoReferent)) {
            }
            else 
                continue;
            let cou = 0;
            for (let tt = t.previous; tt !== null; tt = tt.previous) {
                let pt = PartToken.tryAttach(tt, null, false, false);
                if (pt !== null && pt.values.length > 0) {
                    t = kit.debedToken(rt);
                    break;
                }
                if ((++cou) > 10) 
                    break;
            }
        }
        let keywords = Array.from(["ИЗЛОЖИТЬ", "ВВЕСТИ", "ДОПОЛНИТЬ", "УДАЛИТЬ", "РЕДАКЦИИ"]);
        for (let t = kit.firstToken; t !== null; t = t.next) {
            let tt = Utils.as(t, TextToken);
            if (tt === null) 
                continue;
            if (tt.term === "СТАТЮ" || tt.term === "СТАТИ" || tt.term === "СТАТЯ") {
                if (tt.next instanceof NumberToken) {
                    tt.correctWord(tt.term.substring(0, 0 + 4) + "Ь" + tt.term.substring(tt.term.length - 1));
                    continue;
                }
            }
            if (tt.term === "СТАТЬЮ") {
                tt.morph.removeItems(MorphCase.ACCUSATIVE, false);
                continue;
            }
            if (tt.term === "СРОКИ" && tt.previous !== null && tt.previous.isValue("ПОСЛЕ", null)) {
                tt.correctWord("СТРОКИ");
                continue;
            }
            if (tt.lengthChar < 6) 
                continue;
            let mc = tt.getMorphClassInDictionary();
            if (!mc.isUndefined) 
                continue;
            if (tt.term.startsWith("РЕД") && t.previous !== null && t.previous.isValue("СЛЕДУЮЩИЙ", null)) {
                tt.correctWord("РЕДАКЦИИ");
                continue;
            }
            let vars = MorphologyService.correctWordEx(tt.term, null);
            if (vars === null || vars.length === 0) 
                continue;
            for (const v of vars) {
                if (keywords.includes(v)) {
                    tt.correctWord(v);
                    break;
                }
            }
        }
        let prevClause = null;
        for (let t = kit.firstToken; t !== null; t = t.next) {
            t.tag = null;
            let tt = Utils.as(t, TextToken);
            if (tt === null) 
                continue;
            if (tt.term === "СТАТЬЯ" && !tt.chars.isAllLower && (tt.next instanceof NumberToken)) {
            }
            else 
                continue;
            let num = Utils.as(tt.next, NumberToken);
            if (num.intValue === null) 
                continue;
            let t1 = tt.next;
            if (t1.next !== null && t1.next.isChar('.')) 
                t1 = t1.next;
            if (tt.isNewlineBefore || ((tt.previous !== null && tt.previous.isTableControlChar))) {
                if (t1.isNewlineAfter || ((t1.next !== null && t1.next.isTableControlChar))) {
                    if (prevClause === null) 
                        prevClause = num;
                    else if ((prevClause.intValue + 1) === num.intValue) {
                        tt.tag = prevClause;
                        prevClause = num;
                    }
                    else 
                        prevClause = null;
                }
            }
        }
        let lastDecDist = 0;
        let ignoreMaxPos = 0;
        for (let t = kit.firstToken; t !== null; t = t.next,lastDecDist++) {
            if (t.isNewlineBefore && (t instanceof NumberToken) && t.value === "88") {
            }
            if (t.isIgnored) 
                continue;
            if (t.isValue2("СЛЕДУЮЩЕГО", "СОДЕРЖАНИЯ") || t.isValue2("СЛЕДУЮЩЕЙ", "РЕДАКЦИИ") || ((t.isValue2("НОВОЙ", "РЕДАКЦИИ") && t.next.next !== null && t.next.next.isChar(':')))) {
                let tt = t.next.next;
                if (tt !== null && tt.isChar(':')) 
                    tt = tt.next;
                if (BracketHelper.canBeStartOfSequence(tt, true, false)) {
                    let txt = DecreeChangeToken._tryParseText(tt, false, false, null);
                    if (txt !== null) {
                        t = txt.endToken;
                        continue;
                    }
                }
            }
            if (t.isValue("СЛОВО", null) && BracketHelper.canBeStartOfSequence(t.next, true, false)) {
                let txt = DecreeChangeToken._tryParseText(t.next, false, false, null);
                if (txt !== null) {
                    if (txt.lengthChar > 500) {
                    }
                    else 
                        ignoreMaxPos = txt.endChar;
                }
            }
            if (t.isValue("УТВЕРЖДЕННЫЙ", null)) {
            }
            let dts = DecreeToken.tryAttachList(t, null, 10, lastDecDist > 1000);
            if (dts === null || dts.length === 0) 
                continue;
            if (dts[0].isNewlineAfter && dts[0].isNewlineBefore) {
                let ignore = false;
                if (t === kit.firstToken) 
                    ignore = true;
                else if ((dts[0].typ === DecreeTokenItemType.ORG && dts.length > 1 && dts[1].typ === DecreeTokenItemType.TYP) && dts[1].isWhitespaceAfter) 
                    ignore = true;
                if (ignore) {
                    t = dts[dts.length - 1].endToken;
                    continue;
                }
            }
            if (dts[0].typ === DecreeTokenItemType.TYP && DecreeToken.getKind(dts[0].value, null) === DecreeKind.PUBLISHER) {
                let rts = this.tryAttachPulishers(dts);
                if (rts !== null) {
                    for (let i = 0; i < rts.length; i++) {
                        let rtt = rts[i];
                        if (rtt.referent instanceof DecreePartReferent) 
                            rtt.referent.owner = Utils.as(ad.registerReferent(rtt.referent.owner), DecreeReferent);
                        rtt.referent = ad.registerReferent(rtt.referent);
                        if (rtt.beginChar < ignoreMaxPos) 
                            rtt.tag = "ignored";
                        kit.embedToken(rtt);
                        t = rtt;
                        if ((rtt.referent instanceof DecreeReferent) && ((i + 1) < rts.length) && (rts[i + 1].referent instanceof DecreePartReferent)) 
                            rts[i + 1].beginToken = t;
                        lastDecDist = 0;
                    }
                    let tt1 = t.next;
                    if (tt1 !== null && tt1.isChar(')')) 
                        tt1 = tt1.next;
                }
                continue;
            }
            if (baseTyp === null) {
                for (const dd of dts) {
                    if (dd.typ === DecreeTokenItemType.TYP) {
                        baseTyp = dd;
                        break;
                    }
                }
            }
            if ((dts.length === 1 && dts[0].typ === DecreeTokenItemType.TYP && dts[0].value !== "КОНСТИТУЦИЯ") && !dts[0].typRefBack) 
                continue;
            if (dts[0].value === "РЕГЛАМЕНТ") {
                if (dts.length < 3) 
                    continue;
                if (dts[1].typ === DecreeTokenItemType.TYP) 
                    continue;
            }
            let rtli = DecreeAnalyzer.tryAttach(dts, baseTyp, ad);
            let multi = false;
            if ((rtli === null && dts.length === 2 && dts[0].typ === DecreeTokenItemType.TYP) && ((dts[1].typ === DecreeTokenItemType.ORG || dts[1].typ === DecreeTokenItemType.OWNER))) {
                for (let tt2 = dts[1].endToken.next; tt2 !== null; tt2 = tt2.next) {
                    if (tt2.isCharOf(";:-")) 
                        continue;
                    if (tt2.isNewlineBefore) {
                        let cn = ComplexNumToken.tryParse(tt2, null, false, false);
                        if (cn !== null) 
                            tt2 = cn.endToken.next;
                        if (tt2 === null) 
                            break;
                    }
                    let dts2 = DecreeToken.tryAttachList(tt2, null, 4, false);
                    if (dts2 === null || dts2.length !== 3) 
                        break;
                    if (dts2[2].typ !== DecreeTokenItemType.NAME) 
                        break;
                    if (dts2[0].typ === DecreeTokenItemType.NUMBER && dts2[1].typ === DecreeTokenItemType.DATE) {
                    }
                    else if (dts2[1].typ === DecreeTokenItemType.NUMBER && dts2[0].typ === DecreeTokenItemType.DATE) {
                    }
                    else 
                        break;
                    let ddd = new Array();
                    ddd.splice(ddd.length, 0, ...dts);
                    ddd.splice(ddd.length, 0, ...dts2);
                    let rtli2 = DecreeAnalyzer.tryAttach(ddd, baseTyp, ad);
                    if (rtli2 === null || rtli2.length !== 1) 
                        break;
                    rtli2[0].beginToken = tt2;
                    if (rtli === null) 
                        rtli = new Array();
                    rtli.push(rtli2[0]);
                    tt2 = rtli2[0].endToken;
                    multi = true;
                }
            }
            if (rtli !== null) {
                for (let ii = 0; ii < rtli.length; ii++) {
                    let rt = rtli[ii];
                    lastDecDist = 0;
                    let dec0 = rt.referent;
                    rt.referent = ad.registerReferent(rt.referent);
                    if (!multi) {
                        for (let jj = ii + 1; jj < rtli.length; jj++) {
                            for (const s of rtli[jj].referent.slots) {
                                if (s.value === dec0) 
                                    s.value = rt.referent;
                            }
                        }
                    }
                    ref0 = rt.referent;
                    kit.embedToken(rt);
                    t = rt;
                    if (rt.beginChar < ignoreMaxPos) 
                        rt.tag = "ignored";
                    if ((ii + 1) < rtli.length) {
                        if (rt.endToken.next === rtli[ii + 1].beginToken) 
                            rtli[ii + 1].beginToken = rt;
                    }
                }
            }
            else if (dts.length === 1 && dts[0].typ === DecreeTokenItemType.TYP) {
                if (dts[0].chars.isCapitalUpper && !dts[0].isDoubtful) {
                    lastDecDist = 0;
                    if (baseTyp !== null && dts[0].ref !== null) {
                        let drr = Utils.as(dts[0].ref.getReferent(), DecreeReferent);
                        if (drr !== null) {
                            if (baseTyp.value === drr.typ0 || baseTyp.value === drr.typ) 
                                continue;
                        }
                    }
                    let rt0 = DecreeToken._findBackTyp(dts[0].beginToken.previous, dts[0].value);
                    if (rt0 !== null) {
                        let rt = new ReferentToken(rt0.referent, dts[0].beginToken, dts[0].endToken);
                        kit.embedToken(rt);
                        t = rt;
                        rt.tag = rt0.referent;
                    }
                }
            }
        }
        if (ad.referents.length > 0) {
            for (let t = kit.firstToken; t !== null; t = t.next) {
                if (t.isIgnored) 
                    continue;
                let dr = Utils.as(t.getReferent(), DecreeReferent);
                if (dr === null) 
                    continue;
                let li = null;
                for (let tt = t.next; tt !== null; tt = tt.next) {
                    if (!tt.isCommaAnd) 
                        break;
                    if (tt.next === null || !(tt.next.getReferent() instanceof DecreeReferent)) 
                        break;
                    if (li === null) {
                        li = new Array();
                        li.push(dr);
                    }
                    dr = Utils.as(tt.next.getReferent(), DecreeReferent);
                    li.push(dr);
                    dr.tag = null;
                    tt = tt.next;
                    if (dr.date !== null) {
                        let dts = DecreeToken.tryAttachList(tt.beginToken, null, 10, false);
                        if (dts !== null) {
                            for (const dt of dts) {
                                if (dt.typ === DecreeTokenItemType.DATE) 
                                    dr.tag = dr;
                            }
                        }
                    }
                }
                if (li === null) 
                    continue;
                let i = 0;
                for (i = li.length - 1; i > 0; i--) {
                    if (li[i].typ === li[i - 1].typ) {
                        if (li[i].date !== null && li[i].tag !== null && li[i - 1].date === null) 
                            li[i - 1].addSlot(DecreeReferent.ATTR_DATE, li[i].getSlotValue(DecreeReferent.ATTR_DATE), false, 0);
                    }
                }
                for (i = 0; i < (li.length - 1); i++) {
                    if (li[i].typ === li[i + 1].typ) {
                        let sl = li[i].findSlot(DecreeReferent.ATTR_SOURCE, null, true);
                        if (sl !== null && li[i + 1].findSlot(DecreeReferent.ATTR_SOURCE, null, true) === null) 
                            li[i + 1].addSlot(sl.typeName, sl.value, false, 0);
                    }
                }
                for (i = 0; i < li.length; i++) {
                    if (li[i].name !== null) 
                        break;
                }
                if (i === (li.length - 1)) {
                    for (i = li.length - 1; i > 0; i--) {
                        if (li[i - 1].typ === li[i].typ) 
                            li[i - 1].addName(li[i]);
                    }
                }
            }
        }
        let aliases = new TerminCollection();
        let attachednames = new TerminCollection();
        for (let t = kit.firstToken; t !== null; t = t.next,lastDecDist++) {
            if (t.isIgnored) 
                continue;
            if (t.isValue2("СЛЕДУЮЩЕГО", "СОДЕРЖАНИЯ") || t.isValue2("СЛЕДУЮЩЕЙ", "РЕДАКЦИИ") || ((t.isValue2("НОВОЙ", "РЕДАКЦИИ") && t.next.next !== null && t.next.next.isChar(':')))) {
                let tt = t.next.next;
                if (tt !== null && tt.isChar(':')) 
                    tt = tt.next;
                if (BracketHelper.canBeStartOfSequence(tt, true, false)) {
                    let txt = DecreeChangeToken._tryParseText(tt, false, false, null);
                    if (txt !== null) {
                        t = txt.endToken;
                        continue;
                    }
                }
            }
            if (t.isValue("СЛОВО", null) && BracketHelper.canBeStartOfSequence(t.next, true, false)) {
                let txt = DecreeChangeToken._tryParseText(t.next, false, false, null);
                if (txt !== null) {
                    if (txt.lengthChar > 500) {
                    }
                    else {
                        t = txt.endToken;
                        continue;
                    }
                }
            }
            let checkAliasToken = null;
            let rt = DecreeAnalyzer.tryAttachApproved(t, ad, aliases, attachednames, false);
            if (t.isValue("ВНЕСТИ", null)) {
            }
            if (rt !== null) {
                if (t.isNewlineBefore && (t instanceof TextToken) && t.term === "ПРАВИЛА") {
                }
                rt.referent = ad.registerReferent(rt.referent);
                kit.embedToken(rt);
                t = rt;
                if (rt.tag instanceof MetaToken) {
                    let term = new Termin();
                    term.initBy(rt.tag.beginToken, rt.tag.endToken.previous, rt.referent, false);
                    aliases.add(term);
                }
                for (const nam of rt.referent.getStringValues(DecreeReferent.ATTR_NAME)) {
                    attachednames.add(Termin._new1469(nam, nam));
                }
            }
            if (t.getReferent() instanceof DecreeReferent) {
                rt = Utils.as(t, ReferentToken);
                if (rt.referent.kind === DecreeKind.PUBLISHER) 
                    continue;
                if ((t.next !== null && t.next.isCharOf("(,") && (t.next.next instanceof ReferentToken)) && (t.next.next.getReferent() instanceof DecreeReferent) && t.next.next.getReferent().kind === DecreeKind.PUBLISHER) {
                    checkAliasToken = t.next.next.next;
                    if (checkAliasToken !== null && checkAliasToken.isChar(')')) 
                        checkAliasToken = checkAliasToken.next;
                }
            }
            else if (t instanceof TextToken) {
                let tok = aliases.tryParse(t, TerminParseAttr.NO);
                if (tok !== null) {
                    let dec0 = Utils.as(tok.termin.tag, DecreeReferent);
                    let rt0 = new ReferentToken(Utils.as(tok.termin.tag, Referent), tok.beginToken, tok.endToken);
                    if (dec0 !== null && (rt0.endToken.next instanceof ReferentToken) && (rt0.endToken.next.getReferent() instanceof GeoReferent)) {
                        let geo0 = Utils.as(dec0.getSlotValue(DecreeReferent.ATTR_GEO), GeoReferent);
                        let geo1 = Utils.as(rt0.endToken.next.getReferent(), GeoReferent);
                        if (geo0 === null) {
                            dec0.addSlot(DecreeReferent.ATTR_GEO, geo1, false, 0);
                            rt0.endToken = rt0.endToken.next;
                        }
                        else if (geo0 === geo1) 
                            rt0.endToken = rt0.endToken.next;
                        else 
                            continue;
                    }
                    if (rt0.isNewlineBefore && rt0.isNewlineAfter) 
                        continue;
                    kit.embedToken(rt0);
                    t = rt0;
                    rt0.miscAttrs = 1;
                    lastDecDist = 0;
                    continue;
                }
                let dts = DecreeToken.tryAttachList(t, null, 2, false);
                if (dts !== null && dts[0].typ === DecreeTokenItemType.TYP) {
                    let rtli = DecreeAnalyzer.tryAttach(dts, null, ad);
                    if (rtli !== null && rtli.length === 1) {
                        rt = rtli[0];
                        rt.referent = ad.registerReferent(rt.referent);
                        kit.embedToken(rt);
                        t = rt;
                    }
                }
            }
            if (rt !== null) {
                let mt = DecreeAnalyzer._checkAliasAfter((checkAliasToken != null ? checkAliasToken : t.next));
                if (mt !== null) {
                    if (mt.tag instanceof DecreeReferent) {
                        let dr0 = Utils.as(mt.tag, DecreeReferent);
                        let dr1 = Utils.as(rt.referent, DecreeReferent);
                        if (dr1 !== dr0 && dr1.owner !== dr0) {
                            if (dr0.number !== null) {
                                if (dr1.number !== null && ((dr1.number === dr0.number || dr0.number.startsWith(dr1.number + "/")))) {
                                }
                                else if (dr1.owner !== null && dr1.owner.number === dr0.number) {
                                }
                                else 
                                    continue;
                            }
                            kit.replaceReferent(Utils.as(mt.tag, DecreeReferent), rt.referent);
                        }
                        if (checkAliasToken === null) {
                            rt = new ReferentToken(t.getReferent(), t, mt.endToken);
                            kit.embedToken(rt);
                            t = rt;
                        }
                    }
                    else {
                        let eTok = mt.endToken.previous;
                        if ((mt.beginToken.next !== null && mt.beginToken.next.isCommaAnd && mt.beginToken.next.next === mt.endToken.previous.previous) && mt.endToken.previous.isValue("СООТВЕТСТВЕННО", null)) {
                            let tt = Utils.as(mt.beginToken.next.next, TextToken);
                            let nam = Utils.notNull(rt.referent.getStringValue("NAME"), "");
                            if (nam.startsWith("ОБ УТВЕРЖДЕНИИ ") && tt !== null) {
                                let ar0 = ProcessorService.getEmptyProcessor().process(new SourceOfAnalysis(nam), null, null);
                                nam = MiscHelper.getTextValue(ar0.firstToken.next.next, ar0.findTokenByPos(nam.length - 1, null), GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
                                if (nam.startsWith(tt.term)) {
                                    let r1 = new DecreeReferent();
                                    r1.owner = Utils.as(rt.referent, DecreeReferent);
                                    r1.addSlot(DecreeReferent.ATTR_NAME, nam, false, 0);
                                    r1 = Utils.as(ad.registerReferent(r1), DecreeReferent);
                                    let rt1 = new ReferentToken(r1, tt, tt);
                                    kit.embedToken(rt1);
                                    let term1 = new Termin();
                                    term1.initBy(tt, tt, r1, false);
                                    aliases.add(term1);
                                    eTok = mt.beginToken.next;
                                }
                            }
                        }
                        let term = new Termin();
                        term.initBy(mt.beginToken, eTok, rt.referent, false);
                        aliases.add(term);
                        if (checkAliasToken === null) {
                            rt = new ReferentToken(t.getReferent(), t, mt.endToken);
                            kit.embedToken(rt);
                            t = rt;
                        }
                    }
                }
                else {
                    let aa = aliases.tryParse(t, TerminParseAttr.NO);
                    if (aa !== null) 
                        aa.termin.tag = rt.referent;
                }
            }
        }
        this._processPartsAndChanges(kit, baseTyp);
        for (let t = kit.firstToken; t !== null; t = t.next) {
            if (t.tag !== null && (t instanceof ReferentToken) && (t.tag instanceof DecreeReferent)) {
                t = kit.debedToken(t);
                if (t === null) 
                    break;
            }
        }
    }
    
    static _checkAliasAfter(t) {
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeReferent = require("./DecreeReferent");
        if ((t !== null && t.isChar('<') && t.next !== null) && t.next.next !== null && t.next.next.isChar('>')) 
            t = t.next.next.next;
        if (t === null || t.next === null || !t.isChar('(')) 
            return null;
        if (t.next.getReferent() !== null) {
            let dr = Utils.as(t.next.getReferent(), DecreeReferent);
            if (dr === null && (t.next.getReferent() instanceof DecreePartReferent)) 
                dr = t.next.getReferent().owner;
            if (dr !== null && dr.kind === DecreeKind.PUBLISHER) {
                let br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                if (br !== null && br.endToken.next !== null && br.endToken.next.isChar('(')) {
                    t = br.endToken.next;
                    if (t.next === null) 
                        return null;
                }
            }
        }
        t = t.next;
        if (t.isValue("ДАЛЕЕ", "ДАЛІ")) {
        }
        else 
            return null;
        t = t.next;
        if (t !== null && !t.chars.isLetter) 
            t = t.next;
        if (t === null) 
            return null;
        if ((t.getReferent() instanceof DecreeReferent) && t.next !== null && t.next.isChar(')')) 
            return MetaToken._new663(t, t.next, t.getReferent());
        let t1 = null;
        let lev = 0;
        for (let tt = t; tt !== null; tt = tt.next) {
            if (tt.isNewlineBefore) 
                break;
            else if (tt.isChar('(')) 
                lev++;
            else if (tt.isChar(')')) {
                lev--;
                if (lev < 0) {
                    t1 = tt.previous;
                    break;
                }
            }
        }
        if (t1 === null) 
            return null;
        return new MetaToken(t, t1.next);
    }
    
    static _getDecree(t) {
        const DecreePartReferent = require("./DecreePartReferent");
        const DecreeReferent = require("./DecreeReferent");
        if (!(t instanceof ReferentToken)) 
            return null;
        let r = t.getReferent();
        if (r instanceof DecreeReferent) 
            return Utils.as(r, DecreeReferent);
        if (r instanceof DecreePartReferent) 
            return r.owner;
        return null;
    }
    
    static _checkOtherTyp(t, first) {
        const DecreeToken = require("./internal/DecreeToken");
        if (t === null) 
            return null;
        let dit = DecreeToken.tryAttach(t, null, false);
        let npt = null;
        if (dit === null) {
            npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null && npt.beginToken !== npt.endToken) 
                dit = DecreeToken.tryAttach(npt.endToken, null, false);
        }
        if (dit !== null && dit.typ === DecreeTokenItemType.TYP) {
            if (dit.chars.isCapitalUpper || first) {
                dit.endToken.tag = dit.value;
                return dit.endToken;
            }
            else 
                return null;
        }
        if (npt !== null) 
            t = npt.endToken;
        if (t.chars.isCapitalUpper || first) {
            if (t.previous !== null && t.previous.isChar('.') && !first) 
                return null;
            let tt = DecreeToken.isKeyword(t, false);
            if (tt !== null) 
                return tt;
        }
        return null;
    }
    
    processReferent(begin, param) {
        const DecreeToken = require("./internal/DecreeToken");
        let rt = DecreeAnalyzer.tryAttachApproved(begin, null, null, null, false);
        if (rt !== null) 
            return rt;
        let dpli = DecreeToken.tryAttachList(begin, null, 10, true);
        if (dpli !== null) {
            let lii = DecreeAnalyzer.tryAttach(dpli, null, null);
            if (lii !== null && lii.length > 0) 
                return lii[0];
        }
        let dp = DecreeToken.tryAttach(begin, null, false);
        if (dp !== null && dp.typ === DecreeTokenItemType.TYP) 
            return new ReferentToken(null, dp.beginToken, dp.endToken);
        return null;
    }
    
    static initialize() {
        const DecreeToken = require("./internal/DecreeToken");
        const DecreeChangeToken = require("./internal/DecreeChangeToken");
        const MetaDecreePart = require("./internal/MetaDecreePart");
        if (DecreeAnalyzer.m_Inited) 
            return;
        DecreeAnalyzer.m_Inited = true;
        MetaDecree.initialize();
        MetaDecreePart.initialize();
        MetaDecreeChange.initialize();
        MetaDecreeChangeValue.initialize();
        try {
            Termin.ASSIGN_ALL_TEXTS_AS_NORMAL = false;
            DecreeChangeToken.initialize();
            DecreeToken.initialize();
            Termin.ASSIGN_ALL_TEXTS_AS_NORMAL = false;
        } catch (ex) {
            throw new Error(ex.message);
        }
        ProcessorService.registerAnalyzer(new DecreeAnalyzer());
    }
    
    static static_constructor() {
        DecreeAnalyzer.ANALYZER_NAME = "DECREE";
        DecreeAnalyzer.m_Inited = false;
    }
}


DecreeAnalyzer.ThisDecree = class  extends MetaToken {
    
    constructor(b, e) {
        super(b, e, null);
        this.typ = null;
        this.hasThisRef = false;
        this.hasOtherRef = false;
        this.real = null;
    }
    
    toString() {
        return (((this.typ != null ? this.typ : "?")) + " (" + (this.hasThisRef ? "This" : (this.hasOtherRef ? "Other" : "?")) + ")");
    }
    
    checkDecree(r) {
        const SourceOfAnalysis = require("./../SourceOfAnalysis");
        const DecreeKind = require("./DecreeKind");
        const ProcessorService = require("./../ProcessorService");
        const DecreeReferent = require("./DecreeReferent");
        if (r === null) 
            return false;
        if (this.real === r) 
            return true;
        if (this.typ !== null) {
            if (r.typ === this.typ || r.typ0 === this.typ) 
                return true;
            if (r.kind === DecreeKind.KODEX && this.typ === "КОДЕКС") 
                return true;
            for (const s of r.slots) {
                if (s.typeName === DecreeReferent.ATTR_NAME) {
                    let n = Utils.asString(s.value);
                    if (Utils.startsWithString(n, this.typ, true)) 
                        return true;
                    let arr = ProcessorService.getEmptyProcessor().process(new SourceOfAnalysis(n), null, null);
                    if (arr !== null && arr.firstToken !== null) {
                        if (arr.firstToken.isValue(this.typ, null)) 
                            return true;
                        if (arr.firstToken.next !== null) {
                            if (arr.firstToken.next.isValue(this.typ, null)) 
                                return true;
                        }
                    }
                }
            }
        }
        return false;
    }
    
    static tryAttachBack(t, baseTyp) {
        const TextToken = require("./../TextToken");
        const DecreeToken = require("./internal/DecreeToken");
        const PartToken = require("./internal/PartToken");
        if (t === null) 
            return null;
        let ukaz = null;
        for (let tt = t; tt !== null; tt = tt.previous) {
            if (tt.isCharOf(",") || tt.morph._class.isPreposition || tt.morph._class.isConjunction) 
                continue;
            if ((((((tt.isValue("ОПРЕДЕЛЕННЫЙ", "ПЕВНИЙ") || tt.isValue("ЗАДАННЫЙ", "ЗАДАНИЙ") || tt.isValue("ПРЕДУСМОТРЕННЫЙ", "ПЕРЕДБАЧЕНИЙ")) || tt.isValue("УКАЗАННЫЙ", "ЗАЗНАЧЕНИЙ") || tt.isValue("ПЕРЕЧИСЛЕННЫЙ", "ПЕРЕРАХОВАНИЙ")) || tt.isValue("ОПРЕДЕЛИТЬ", "ВИЗНАЧИТИ") || tt.isValue("ОПРЕДЕЛЯТЬ", null)) || tt.isValue("ЗАДАВАТЬ", "ЗАДАВАТИ") || tt.isValue("ПРЕДУСМАТРИВАТЬ", "ПЕРЕДБАЧАТИ")) || tt.isValue("УКАЗЫВАТЬ", "ВКАЗУВАТИ") || tt.isValue("УКАЗАТЬ", "ВКАЗАТИ")) || tt.isValue("СИЛА", "ЧИННІСТЬ")) {
                ukaz = tt;
                continue;
            }
            if (tt === t) 
                continue;
            let ttt = DecreeToken.isKeyword(tt, false);
            if (tt !== ttt || !(tt instanceof TextToken)) 
                break;
            if (ttt.isValue("УСЛОВИЕ", null) || ttt.isValue("ПОЛОЖЕНИЕ", null) || ttt.isValue("ОПРЕДЕЛЕНИЕ", null)) 
                continue;
            if (PartToken.tryAttach(tt, null, false, true) !== null) 
                break;
            if (ttt.isValue("ПОРЯДОК", null) && ukaz !== null) 
                return null;
            let res = new DecreeAnalyzer.ThisDecree(tt, tt);
            res.typ = tt.lemma;
            t = tt.previous;
            if (t !== null && ((t.morph._class.isAdjective || t.morph._class.isPronoun))) {
                if (t.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ") || t.isValue("ТЕКУЩИЙ", "ПОТОЧНИЙ") || t.isValue("ДАННЫЙ", "ДАНИЙ")) {
                    res.hasThisRef = true;
                    res.beginToken = t;
                }
                else if ((t.isValue("ЭТОТ", "ЦЕЙ") || t.isValue("ВЫШЕУКАЗАННЫЙ", "ВИЩЕВКАЗАНИЙ") || t.isValue("УКАЗАННЫЙ", "ЗАЗНАЧЕНИЙ")) || t.isValue("НАЗВАННЫЙ", "НАЗВАНИЙ")) {
                    res.hasOtherRef = true;
                    res.beginToken = t;
                }
            }
            if (!res.hasThisRef && tt.isNewlineAfter) 
                return null;
            if (baseTyp !== null && baseTyp.value === res.typ) 
                res.hasThisRef = true;
            return res;
        }
        if (ukaz !== null) {
            if (baseTyp !== null && baseTyp.value !== null && ((baseTyp.value.includes("ДОГОВОР") || baseTyp.value.includes("ДОГОВІР")))) 
                return DecreeAnalyzer.ThisDecree._new1465(ukaz, ukaz, true, baseTyp.value);
        }
        return null;
    }
    
    static tryAttach(dtok, baseTyp) {
        const NounPhraseParseAttr = require("./../core/NounPhraseParseAttr");
        const NounPhraseHelper = require("./../core/NounPhraseHelper");
        const MorphNumber = require("./../../morph/MorphNumber");
        const DecreeReferent = require("./DecreeReferent");
        const MorphGender = require("./../../morph/MorphGender");
        const TextToken = require("./../TextToken");
        const DecreeTokenItemType = require("./internal/DecreeTokenItemType");
        const BracketHelper = require("./../core/BracketHelper");
        const ReferentToken = require("./../ReferentToken");
        const DecreeToken = require("./internal/DecreeToken");
        if (dtok.decree !== null) 
            return DecreeAnalyzer.ThisDecree._new1466(dtok.endToken, dtok.endToken, dtok.decree);
        let t = dtok.endToken.next;
        if (t === null) 
            return null;
        if (t.isNewlineBefore) {
            if (t.chars.isCyrillicLetter && t.chars.isAllLower) {
            }
            else 
                return null;
        }
        let t0 = t;
        if (t.isChar('.') && t.next !== null && !t.isNewlineAfter) {
            if (dtok.isNewlineBefore) 
                return null;
            t = t.next;
        }
        if (t.isValue("К", null) && t.next !== null) {
            t = t.next;
            if (t.getReferent() instanceof DecreeReferent) 
                return DecreeAnalyzer.ThisDecree._new1466(t, t, Utils.as(t.getReferent(), DecreeReferent));
        }
        if (t !== null && (t.getReferent() instanceof DecreeReferent)) 
            return null;
        if (t.isValue("НОВЫЙ", null)) 
            return null;
        let tt = DecreeToken.isKeyword(t, false);
        let br = false;
        if (tt === null && BracketHelper.canBeStartOfSequence(t, true, false)) {
            tt = DecreeToken.isKeyword(t.next, false);
            if ((tt instanceof TextToken) && BracketHelper.canBeEndOfSequence(tt.next, false, null, false)) 
                br = true;
            else 
                tt = null;
        }
        if (!(tt instanceof TextToken)) {
            if ((tt instanceof ReferentToken) && (tt.getReferent() instanceof DecreeReferent)) 
                return DecreeAnalyzer.ThisDecree._new1466(t, tt, Utils.as(tt.getReferent(), DecreeReferent));
            return null;
        }
        if (tt.chars.isAllLower) {
            if (DecreeToken.isKeyword(tt, true) !== null) {
                if (tt !== t && t.chars.isCapitalUpper) {
                }
                else 
                    return null;
            }
        }
        if (!(t instanceof TextToken)) 
            return null;
        let res = new DecreeAnalyzer.ThisDecree(t0, (br ? tt.next : tt));
        res.typ = tt.lemma;
        if (tt.previous instanceof TextToken) {
            let tt1 = tt.previous;
            let mc = tt1.getMorphClassInDictionary();
            if (mc.isAdjective && !mc.isVerb && !tt1.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ")) {
                let nnn = NounPhraseHelper.tryParse(tt1, NounPhraseParseAttr.NO, 0, null);
                if (nnn !== null) 
                    res.typ = nnn.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false);
                if (tt1.previous instanceof TextToken) {
                    tt1 = tt1.previous;
                    mc = tt1.getMorphClassInDictionary();
                    if (mc.isAdjective && !mc.isVerb && !tt1.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ")) {
                        nnn = NounPhraseHelper.tryParse(tt1, NounPhraseParseAttr.NO, 0, null);
                        if (nnn !== null) 
                            res.typ = nnn.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false);
                    }
                }
            }
        }
        if (tt.isChar('.') && (tt.previous instanceof TextToken)) 
            res.typ = tt.previous.lemma;
        if (t.morph._class.isAdjective || t.morph._class.isPronoun) {
            if (t.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ") || t.isValue("ТЕКУЩИЙ", "ПОТОЧНИЙ") || t.isValue("ДАННЫЙ", "ДАНИЙ")) 
                res.hasThisRef = true;
            else if ((t.isValue("ЭТОТ", "ЦЕЙ") || t.isValue("ВЫШЕУКАЗАННЫЙ", "ВИЩЕВКАЗАНИЙ") || t.isValue("УКАЗАННЫЙ", "ЗАЗНАЧЕНИЙ")) || t.isValue("НАЗВАННЫЙ", "НАЗВАНИЙ")) 
                res.hasOtherRef = true;
        }
        if (!tt.isNewlineAfter && !res.hasThisRef) {
            let dt = DecreeToken.tryAttach(tt.next, null, false);
            if (dt !== null && dt.typ !== DecreeTokenItemType.MISC) {
                if (dt.typ !== DecreeTokenItemType.NAME && dt.typ !== DecreeTokenItemType.ORG && dt.typ !== DecreeTokenItemType.TERR) 
                    return null;
            }
        }
        if (baseTyp !== null && baseTyp.value === res.typ) 
            res.hasThisRef = true;
        return res;
    }
    
    static _new1465(_arg1, _arg2, _arg3, _arg4) {
        let res = new DecreeAnalyzer.ThisDecree(_arg1, _arg2);
        res.hasThisRef = _arg3;
        res.typ = _arg4;
        return res;
    }
    
    static _new1466(_arg1, _arg2, _arg3) {
        let res = new DecreeAnalyzer.ThisDecree(_arg1, _arg2);
        res.real = _arg3;
        return res;
    }
}


DecreeAnalyzer.static_constructor();

module.exports = DecreeAnalyzer