/*
 * 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 RefOutArgWrapper = require("./../../../unisharp/RefOutArgWrapper");
const StringBuilder = require("./../../../unisharp/StringBuilder");

const MorphGender = require("./../../../morph/MorphGender");
const NumberSpellingType = require("./../../NumberSpellingType");
const DecreeTokenItemType = require("./DecreeTokenItemType");
const MorphClass = require("./../../../morph/MorphClass");
const ReferentToken = require("./../../ReferentToken");
const MorphNumber = require("./../../../morph/MorphNumber");
const BracketParseAttr = require("./../../core/BracketParseAttr");
const MorphCase = require("./../../../morph/MorphCase");
const InstrumentKind = require("./../../instrument/InstrumentKind");
const DecreeKind = require("./../DecreeKind");
const ComplexNumToken = require("./../../core/ComplexNumToken");
const GetTextAttr = require("./../../core/GetTextAttr");
const MetaToken = require("./../../MetaToken");
const DecreeReferent = require("./../DecreeReferent");
const NumberToken = require("./../../NumberToken");
const Token = require("./../../Token");
const MiscHelper = require("./../../core/MiscHelper");
const TextToken = require("./../../TextToken");
const BracketHelper = require("./../../core/BracketHelper");
const DecreePartReferent = require("./../DecreePartReferent");
const DecreeChangeKind = require("./../DecreeChangeKind");
const TerminParseAttr = require("./../../core/TerminParseAttr");
const PartTokenItemType = require("./PartTokenItemType");
const TerminCollection = require("./../../core/TerminCollection");
const DecreeAnalyzer = require("./../DecreeAnalyzer");
const NumberHelper = require("./../../core/NumberHelper");
const DecreeToken = require("./DecreeToken");
const LanguageHelper = require("./../../../morph/LanguageHelper");
const DecreeChangeToken = require("./DecreeChangeToken");

// Примитив, из которых состоит часть декрета (статья, пункт и часть)
class PartToken extends MetaToken {
    
    constructor(begin, end) {
        super(begin, end, null);
        this.typ = PartTokenItemType.UNDEFINED;
        this.altTyp = PartTokenItemType.UNDEFINED;
        this.values = new Array();
        this.name = null;
        this.addNames = null;
        this.ind = 0;
        this.decree = null;
        this.isDoubt = false;
        this.isConfidential = false;
        this.delimAfter = false;
        this.hasTerminator = false;
        this.anaforRef = null;
    }
    
    toString() {
        let res = new StringBuilder(this.typ.toString());
        if (this.altTyp !== PartTokenItemType.UNDEFINED) 
            res.append("/").append(this.altTyp.toString());
        for (const v of this.values) {
            res.append(" ").append(v);
        }
        if (this.name !== null) 
            res.append(" \"").append(this.name.getSourceText()).append("\"");
        if (this.delimAfter) 
            res.append(", DelimAfter");
        if (this.isDoubt) 
            res.append(", Doubt");
        if (this.hasTerminator) 
            res.append(", Terminator");
        if (this.isConfidential) 
            res.append(", Confidential");
        if (this.anaforRef !== null) 
            res.append(", Ref='").append(this.anaforRef.term).append("'");
        if (this.decree !== null) 
            res.append(", Decree=").append(this.decree.toString());
        return res.toString();
    }
    
    addValue(add) {
        if (this.values.length !== 1) 
            return false;
        let n = 0;
        let wrapn1349 = new RefOutArgWrapper();
        let inoutres1350 = Utils.tryParseInt((this.values[0].value != null ? this.values[0].value : ""), wrapn1349);
        n = wrapn1349.value;
        if (!inoutres1350) 
            return false;
        n += add;
        this.values[0].value = n.toString();
        return true;
    }
    
    static tryAttach(t, prev = null, inBracket = false, ignoreNumber = false) {
        if (t === null) 
            return null;
        if (t.isValue("ПРОТОКОЛ", null)) {
        }
        let res = null;
        if (t.morph._class.isPersonalPronoun && (t.whitespacesAfterCount < 2)) {
            res = PartToken.tryAttach(t.next, prev, false, false);
            if (res !== null) {
                res.anaforRef = Utils.as(t, TextToken);
                res.beginToken = t;
                return res;
            }
        }
        if (t.kit.miscData.containsKey("partAliases")) {
            let partAliases = Utils.as(t.kit.miscData.get("partAliases"), TerminCollection);
            let atok = partAliases.tryParse(t, TerminParseAttr.NO);
            if (atok !== null) {
                let dapp = Utils.as(atok.termin.tag, DecreePartReferent);
                let app = PartToken._new1060(t, atok.endToken, PartTokenItemType.APPENDIX, t.morph.clone());
                if (dapp.appendix !== "0" && dapp.appendix !== null) 
                    app.values.push(PartToken.PartValue._new1347(t, t, dapp.appendix));
                return app;
            }
        }
        let tt = Utils.as(t, TextToken);
        if ((t instanceof NumberToken) && t.next !== null && (t.whitespacesAfterCount < 3)) {
            let nums = new Array();
            nums.push(Utils.as(t, NumberToken));
            let tt2 = t.next;
            for (; tt2 !== null; tt2 = tt2.next) {
                if (tt2.isCommaAnd && (tt2.next instanceof NumberToken)) {
                    tt2 = tt2.next;
                    nums.push(Utils.as(tt2, NumberToken));
                    if (tt2.previous.isAnd) {
                        tt2 = tt2.next;
                        break;
                    }
                }
                else 
                    break;
            }
            let re = PartToken._createPartTyp0(tt2, prev);
            if (re !== null) {
                let t11 = re.endToken.next;
                let ok1 = false;
                if (t11 !== null && (t11.getReferent() instanceof DecreeReferent)) 
                    ok1 = true;
                else if (prev !== null && t11 !== null && !(t11 instanceof NumberToken)) 
                    ok1 = true;
                else if (t.previous !== null && t.previous.isValue("В", null)) 
                    ok1 = true;
                else if (t11 !== null) {
                    let dcc = DecreeChangeToken.tryAttach(t11, null, false, null, false, false, null, false);
                    if (dcc !== null) {
                        if (dcc.changeVal !== null || dcc.actKind !== DecreeChangeKind.UNDEFINED) 
                            ok1 = true;
                    }
                }
                if (!ok1) {
                    let res1 = PartToken.tryAttach(t11, null, false, false);
                    if (res1 !== null) 
                        ok1 = true;
                }
                if (ok1 || inBracket) {
                    re.beginToken = t;
                    let pref = "";
                    if (re.typ === PartTokenItemType.TABLEROW && re.endToken.next !== null) {
                        if (re.endToken.next.isValue("СВЕРХУ", null)) 
                            re.endToken = re.endToken.next;
                        else if (re.endToken.next.isValue("СНИЗУ", null)) {
                            pref = "-";
                            re.endToken = re.endToken.next;
                        }
                    }
                    for (const n of nums) {
                        re.values.push(PartToken.PartValue._new1347(n, n, pref + n.value));
                    }
                    return re;
                }
            }
        }
        if (t.isValue("ПОСЛЕДНИЙ", null)) {
            let re = PartToken._createPartTyp0(t.next, null);
            if (re !== null) {
                re.beginToken = t;
                re.values.push(PartToken.PartValue._new1347(t, t, t.getNormalCaseText(MorphClass.ADJECTIVE, MorphNumber.SINGULAR, MorphGender.UNDEFINED, false)));
                return re;
            }
        }
        if (((t instanceof NumberToken) && t.typ === NumberSpellingType.DIGIT && prev === null) && t.previous !== null) {
            let t0 = t.previous;
            let delim = false;
            if (t0.isChar(',') || t0.morph._class.isConjunction) {
                delim = true;
                t0 = t0.previous;
            }
            if (t0 === null) 
                return null;
            let dr = Utils.as(t0.getReferent(), DecreePartReferent);
            if (dr === null) {
                if (t0.isChar('(') && t.next !== null) {
                    if (t.next.isValue("ЧАСТЬ", null) || t.next.isValue("Ч", null)) {
                        let te = t.next;
                        if (te.next !== null && te.next.isChar('.')) 
                            te = te.next;
                        res = PartToken._new1058(t, te, PartTokenItemType.PART);
                        res.values.push(PartToken.PartValue._new1347(t, t, t.value.toString()));
                        return res;
                    }
                }
                return null;
            }
            if (dr.clause === null) 
                return null;
            res = PartToken._new1357(t, t, PartTokenItemType.CLAUSE, !delim);
            let pv = PartToken.PartValue._new1347(t, t, t.value.toString());
            res.values.push(pv);
            for (t = t.next; t !== null; t = t.next) {
                if (t.isWhitespaceBefore) 
                    break;
                else if (t.isCharOf("._") && (t.next instanceof NumberToken)) {
                    t = t.next;
                    pv.endToken = res.endToken = t;
                    pv.value = (pv.value + "." + t.value);
                }
                else 
                    break;
            }
            return res;
        }
        if (((t instanceof NumberToken) && t.typ === NumberSpellingType.DIGIT && prev !== null) && prev.typ === PartTokenItemType.PREFIX && (t.whitespacesBeforeCount < 3)) {
            let pv = PartToken.PartValue._new1347(t, t, t.value.toString());
            pv.correctValue();
            let ttt1 = pv.endToken.next;
            let ne = DecreeToken.tryAttach(ttt1, null, false);
            let ok = false;
            if (ne !== null && ne.typ === DecreeTokenItemType.TYP) 
                ok = true;
            else if (DecreeAnalyzer._checkOtherTyp(ttt1, true) !== null) 
                ok = true;
            else if (DecreeAnalyzer._getDecree(ttt1) !== null) 
                ok = true;
            if (ok) {
                res = PartToken._new1058(t, pv.endToken, PartTokenItemType.ITEM);
                res.values.push(pv);
                return res;
            }
        }
        if (tt === null) 
            return null;
        if (tt.lengthChar === 1 && !tt.chars.isAllLower) {
            if (!MiscHelper.canBeStartOfSentence(tt)) {
                if (tt.previous !== null && tt.previous.isValue("ДОГОВОР", null)) {
                }
                else 
                    return null;
            }
        }
        let t1 = tt;
        res = PartToken._createPartTyp0(t1, prev);
        if (res !== null) 
            t1 = res.endToken;
        else if ((t1.isValue("СИЛУ", null) || t1.isValue("СОГЛАСНО", null) || t1.isValue("СООТВЕТСТВИЕ", null)) || ((t1.isValue("ПОЛОЖЕНИЕ", null) && t1.chars.isAllLower))) {
            if (t1.isValue("СИЛУ", null) && t1.previous !== null && t1.previous.morph._class.isVerb) 
                return null;
            if (t1.isValue("ПОЛОЖЕНИЕ", null) && prev !== null && !t1.chars.isAllLower) 
                return null;
            res = PartToken._new1058(t1, t1, PartTokenItemType.PREFIX);
            if (t1.next !== null && t1.next.isValue("С", null)) 
                res.endToken = t1.next;
            return res;
        }
        else if (((t1.isValue("УГОЛОВНОЕ", null) || t1.isValue("КРИМІНАЛЬНА", null))) && t1.next !== null && ((t1.next.isValue("ДЕЛО", null) || t1.next.isValue("СПРАВА", null)))) {
            t1 = t1.next;
            if (t1.next !== null && t1.next.isValue("ПО", null)) 
                t1 = t1.next;
            return PartToken._new1058(t, t1, PartTokenItemType.PREFIX);
        }
        else if ((((t1.isValue("МОТИВИРОВОЧНЫЙ", null) || t1.isValue("МОТИВУВАЛЬНИЙ", null) || t1.isValue("РЕЗОЛЮТИВНЫЙ", null)) || t1.isValue("РЕЗОЛЮТИВНИЙ", null))) && t1.next !== null && ((t1.next.isValue("ЧАСТЬ", null) || t1.next.isValue("ЧАСТИНА", null)))) {
            let rr = PartToken._new1058(t1, t1.next, PartTokenItemType.PART);
            rr.values.push(PartToken.PartValue._new1347(t1, t1, (t1.isValue("МОТИВИРОВОЧНЫЙ", null) || t1.isValue("МОТИВУВАЛЬНИЙ", null) ? "мотивировочная" : "резолютивная")));
            return rr;
        }
        if (res === null) {
            let oo = !t.kit.miscData.containsKey("APP_PART") && ((DecreeToken.isKeyword(tt, true) !== null || tt.isValue("ПРОТОКОЛ", null) || tt.isValue("ВЕДОМОСТЬ", null)));
            if (oo) {
                t.kit.miscData.put("APP_PART", true);
                let rt1 = DecreeAnalyzer.tryAttachApproved(t1, null, null, null, true);
                t.kit.miscData.remove("APP_PART");
                if (rt1 !== null && rt1.referent.findSlot("TYPE", "ПРИЛОЖЕНИЕ", true) !== null) {
                    let dr = Utils.as(rt1.referent, DecreeReferent);
                    let p0 = PartToken._new1058(tt, rt1.endToken, PartTokenItemType.APPENDIX);
                    if (dr.number !== null) 
                        p0.values.push(PartToken.PartValue._new1347(tt, tt, dr.number));
                    let sl = dr.findSlot(DecreeReferent.ATTR_NAME, null, true);
                    if (sl !== null && sl.occurrence.length > 0) 
                        p0.name = Utils.as(sl.occurrence[0].tag, MetaToken);
                    p0.decree = dr.owner;
                    return p0;
                }
            }
            if ((t instanceof TextToken) && !t.chars.isAllLower) {
                let ok = false;
                if (t.isNewlineBefore) 
                    ok = true;
                else if (t.previous.isCharOf(")") || t.previous.isValue("В", null)) 
                    ok = true;
                else if (prev !== null && prev.endToken.next === t) 
                    ok = true;
                if (ok && DecreeToken.isKeyword(t, false) !== null) {
                    let cou = 100;
                    for (let ttt = t.next; ttt !== null && cou > 0; ttt = ttt.next,cou--) {
                        if (ttt.isNewlineBefore) 
                            break;
                        if (ttt.isValue("УТВЕРЖДЕННЫЙ", null)) 
                            break;
                        let r = ttt.getReferent();
                        if (r !== null && r.typeName === "ORGANIZATION") 
                            break;
                        if (ttt.isChar('(')) {
                            let res1 = PartToken.tryAttach(ttt.next, null, false, false);
                            if (res1 !== null && res1.endToken.next !== null && res1.endToken.next.isChar(')')) {
                                res1.name = new MetaToken(t, ttt.previous);
                                res1.beginToken = t;
                                res1.endToken = res1.endToken.next;
                                res1.morph = t.morph;
                                return res1;
                            }
                        }
                        let br = BracketHelper.tryParse(ttt, BracketParseAttr.NO, 100);
                        if (br !== null) {
                            ttt = br.endToken;
                            continue;
                        }
                        if (ttt.isComma && ttt.next !== null && ttt.next.isValue("ЯВЛЯЮЩИЙСЯ", null)) {
                            let res1 = PartToken.tryAttach(ttt.next.next, null, false, false);
                            if (res1 !== null && res1.typ === PartTokenItemType.APPENDIX) {
                                res1.name = new MetaToken(t, ttt.previous);
                                res1.beginToken = t;
                                res1.morph = t.morph;
                                return res1;
                            }
                        }
                        if ((ttt instanceof TextToken) && ttt.term === "ПРИЛОЖЕНИЯ") {
                            let res1 = PartToken.tryAttach(ttt, null, false, false);
                            if (res1 !== null && res1.typ === PartTokenItemType.APPENDIX) {
                                res1.name = new MetaToken(t, ttt.previous);
                                res1.beginToken = t;
                                res1.morph = t.morph;
                                return res1;
                            }
                        }
                        if (ttt instanceof TextToken) {
                            if (ttt.isPureVerb) 
                                break;
                        }
                    }
                }
            }
            return null;
        }
        if (ignoreNumber || res.typ === PartTokenItemType.NAME || res.typ === PartTokenItemType.PREAMBLE) 
            return res;
        if (res.isNewlineAfter) {
            if (res.chars.isAllUpper) 
                return null;
        }
        if (t1.next !== null && t1.next.isChar('.')) {
            if (!t1.next.isNewlineAfter || (t1.lengthChar < 3)) {
                t1 = t1.next;
                if (t1.next !== null && MiscHelper.canBeStartOfSentence(t1.next)) {
                    if (t1.next instanceof TextToken) 
                        return null;
                    if ((t1.next instanceof NumberToken) && t1.next.typ === NumberSpellingType.WORDS) 
                        return null;
                }
            }
        }
        t1 = t1.next;
        if (t1 === null) 
            return null;
        if (res.typ === PartTokenItemType.CLAUSE) {
            if (((t1 instanceof NumberToken) && t1.value === "3" && !t1.isWhitespaceAfter) && t1.next !== null && t1.next.lengthChar === 2) 
                return null;
        }
        if (res.typ === PartTokenItemType.CLAUSE && t1.isValue("СТ", null)) {
            t1 = t1.next;
            if (t1 !== null && t1.isChar('.')) 
                t1 = t1.next;
        }
        else if (res.typ === PartTokenItemType.PART && t1.isValue("Ч", null)) {
            t1 = t1.next;
            if (t1 !== null && t1.isChar('.')) 
                t1 = t1.next;
        }
        else if (res.typ === PartTokenItemType.ITEM && t1.isValue("П", null)) {
            t1 = t1.next;
            if (t1 !== null && t1.isChar('.')) 
                t1 = t1.next;
            res.altTyp = PartTokenItemType.SUBITEM;
        }
        else if ((res.typ === PartTokenItemType.ITEM && t1.isCharOf("\\/") && t1.next !== null) && t1.next.isValue("П", null)) {
            t1 = t1.next.next;
            if (t1 !== null && t1.isChar('.')) 
                t1 = t1.next;
            res.altTyp = PartTokenItemType.SUBITEM;
        }
        if (t1 === null) 
            return null;
        if (res.typ === PartTokenItemType.CLAUSE && (t1.getReferent() instanceof DecreeReferent) && t1.next !== null) {
            res.decree = Utils.as(t1.getReferent(), DecreeReferent);
            t1 = t1.next;
        }
        let ttn = MiscHelper.checkNumberPrefix(t1);
        let firstNumPrefix = null;
        if (ttn !== null) {
            firstNumPrefix = Utils.as(t1, TextToken);
            t1 = ttn;
        }
        if (t1 === null) 
            return null;
        let and = false;
        let ntyp = NumberSpellingType.DIGIT;
        let tt1 = t1;
        while (t1 !== null) {
            if (t1.whitespacesBeforeCount > 20) 
                break;
            if (t1 !== tt1 && t1.isNewlineBefore) {
                if (!t1.isCommaAnd) 
                    break;
            }
            if (t1.isNewlineBefore) {
                if (t1.previous.isCharOf(";.")) {
                    if ((t1 instanceof NumberToken) && t1.next !== null && t1.next.isCharOf(",;")) {
                    }
                    else 
                        break;
                }
                else {
                    let nnn = ComplexNumToken.tryParse(t1, null, false, false);
                    if (nnn !== null && nnn.suffix !== null) {
                        if (nnn.suffix === ")" && t.previous !== null && t.previous.isChar('(')) {
                        }
                        else 
                            break;
                    }
                }
            }
            if (ttn !== null) {
                ttn = MiscHelper.checkNumberPrefix(t1);
                if (ttn !== null) 
                    t1 = ttn;
            }
            if (BracketHelper.canBeStartOfSequence(t1, false, false)) {
                if (res.typ === PartTokenItemType.SENTENCE) 
                    break;
                let br = BracketHelper.tryParse(t1, BracketParseAttr.NO, 100);
                if (br === null) 
                    break;
                let ook = false;
                if (((res.typ === PartTokenItemType.TABLEITEM || res.typ === PartTokenItemType.TABLESUBITEM || ((res.typ === PartTokenItemType.TABLEROW && !res.beginToken.isValue("СТРОКА", null))))) && !(t1.next instanceof NumberToken)) 
                    ook = true;
                else if (res.typ === PartTokenItemType.TABLEROW && res.beginToken.isValue("СТРОКА", null)) {
                    if (br.endToken.next !== null && br.endToken.next.isValue("ТАБЛИЦА", null)) 
                        ook = true;
                }
                if (ook) {
                    let pv0 = new PartToken.PartValue(t1.next, (br.endToken instanceof TextToken ? br.endToken.previous : br.endToken));
                    pv0.value = MiscHelper.getTextValueOfMetaToken(pv0, GetTextAttr.KEEPREGISTER);
                    res.values.push(pv0);
                    res.endToken = br.endToken;
                    for (t = res.endToken.next; t !== null; t = t.next) {
                        if (!t.isCommaAnd) 
                            break;
                        br = BracketHelper.tryParse(t.next, BracketParseAttr.NO, 100);
                        if (br === null) 
                            break;
                        pv0 = new PartToken.PartValue(br.beginToken.next, br.endToken.previous);
                        pv0.value = MiscHelper.getTextValueOfMetaToken(pv0, GetTextAttr.KEEPREGISTER);
                        res.values.push(pv0);
                        res.endToken = br.endToken;
                        if (t.isAnd) 
                            break;
                        t = br.endToken;
                    }
                    return res;
                }
                let ok = true;
                let newP = null;
                for (let ttt = t1.next; ttt !== null; ttt = ttt.next) {
                    if (ttt.endChar > br.endToken.previous.endChar) 
                        break;
                    if (ttt.isChar(',')) 
                        continue;
                    if (ttt.isChar('<') && (ttt.next instanceof NumberToken)) 
                        ttt = ttt.next;
                    if (ttt instanceof NumberToken) {
                        if (ttt.value === "0") {
                            ok = false;
                            break;
                        }
                        if (newP === null) 
                            newP = new Array();
                        let pv0 = PartToken.PartValue._new1347(ttt, ttt, ttt.value.toString());
                        pv0.correctValue();
                        ttt = pv0.endToken;
                        newP.push(pv0);
                        if (ttt.next !== null && ttt.next.isCharOf(".>")) 
                            ttt = ttt.next;
                        if (ttt.next !== null && !ttt.next.isCommaAnd && (br.endChar - ttt.next.beginChar) > 20) {
                            res.name = new MetaToken(ttt.next, br.endToken.previous);
                            break;
                        }
                        continue;
                    }
                    let to = Utils.as(ttt, TextToken);
                    if (to === null) {
                        ok = false;
                        break;
                    }
                    if ((res.typ !== PartTokenItemType.ITEM && res.typ !== PartTokenItemType.SUBITEM && res.typ !== PartTokenItemType.LIST) && res.typ !== PartTokenItemType.INDENTION && res.typ !== PartTokenItemType.SUBINDENTION) {
                        ok = false;
                        break;
                    }
                    if (!to.chars.isLetter || to.lengthChar !== 1) {
                        ok = false;
                        break;
                    }
                    if (newP === null) 
                        newP = new Array();
                    let pv = PartToken.PartValue._new1347(ttt, ttt, to.term);
                    if (BracketHelper.canBeStartOfSequence(ttt.previous, false, false)) 
                        pv.beginToken = ttt.previous;
                    pv.correctValue();
                    ttt = pv.endToken;
                    if ((ttt.next !== null && ttt.next.isHiphen && (ttt.next.next instanceof TextToken)) && ttt.next.next.lengthChar === 1 && ttt.next.next.next === br.endToken) {
                        newP.push(pv);
                        ttt = ttt.next.next;
                        pv = PartToken.PartValue._new1347(ttt, ttt, ttt.term);
                    }
                    if (BracketHelper.canBeEndOfSequence(ttt.next, false, null, false)) 
                        pv.endToken = (ttt = ttt.next);
                    if (pv.endToken.next === br.endToken) 
                        pv.endToken = (ttt = br.endToken);
                    newP.push(pv);
                }
                if (newP === null || !ok) 
                    break;
                res.values.splice(res.values.length, 0, ...newP);
                res.endToken = br.endToken;
                t1 = br.endToken.next;
                if (and) 
                    break;
                if (t1 !== null && t1.isHiphen && BracketHelper.canBeStartOfSequence(t1.next, false, false)) {
                    let br1 = BracketHelper.tryParse(t1.next, BracketParseAttr.NO, 100);
                    if (br1 !== null && (t1.next.next instanceof TextToken) && t1.next.next.lengthChar === 1) {
                        let pv = PartToken.PartValue._new1347(br1.beginToken, t1.next.next, t1.next.next.term);
                        pv.correctValue();
                        if (pv.endToken === br1.endToken.previous) {
                            res.values.push(pv);
                            res.endToken = br1.endToken;
                            t1 = br1.endToken.next;
                        }
                    }
                }
                continue;
            }
            if (res.typ === PartTokenItemType.FORM) {
                if ((t1 instanceof TextToken) && !t1.chars.isAllUpper) {
                }
                else if (PartToken._createPartTyp0(t1, null) !== null) {
                }
                else {
                    let t2 = t1;
                    for (let tt2 = t1.next; tt2 !== null; tt2 = tt2.next) {
                        if (tt2.isCharOf(",;") || BracketHelper.isBracket(tt2, false)) 
                            break;
                        if (tt2.whitespacesBeforeCount < 3) {
                            if ((tt2 instanceof TextToken) && tt2.lengthChar >= 2 && tt2.lengthChar <= 3) {
                                if (tt2.chars.isAllUpper || tt2.isValue("ГПК", null) || tt2.isValue("КАС", null)) {
                                    t2 = tt2;
                                    continue;
                                }
                            }
                        }
                        if (tt2.isWhitespaceBefore) 
                            break;
                        if (tt2.isChar('.') && tt2.isWhitespaceAfter) 
                            break;
                        t2 = tt2;
                    }
                    res.values.push(PartToken.PartValue._new1347(t1, t2, MiscHelper.getTextValue(t1, t2, GetTextAttr.NO)));
                    res.endToken = t2;
                    t1 = t2.next;
                    continue;
                }
            }
            if (t1.isChar('|') && res.values.length === 0 && (t1.whitespacesBeforeCount < 2)) {
                res.values.push(PartToken.PartValue._new1347(t1, t1, "1"));
                res.endToken = t1;
                return res;
            }
            if ((t1.isCharOf("ˡ¹²³")) && res.values.length === 0 && (t1.whitespacesBeforeCount < 2)) {
                res.values.push(PartToken.PartValue._new1347(t1, t1, (t1.isCharOf("ˡ¹") ? "1" : (t1.isChar('²') ? "2" : "3"))));
                res.endToken = t1;
                return res;
            }
            if ((t1.isCharOf("<(") && (t1.next instanceof NumberToken) && t1.next.next !== null) && t1.next.next.isCharOf(">)")) {
                let pp = PartToken.PartValue._new1347(t1, t1.next.next, t1.next.value);
                pp.correctValue();
                res.values.push(pp);
                t1 = res.endToken = pp.endToken;
                continue;
            }
            if ((t1.isChar('<') && res.typ === PartTokenItemType.FOOTNOTE && t1.next !== null) && t1.next.isChar('*')) {
                let cou = 0;
                let t2 = t1.next;
                for (; t2 !== null; t2 = t2.next) {
                    if (t2.isChar('*')) 
                        cou++;
                    else {
                        if (!t2.isChar('>')) 
                            t2 = t2.previous;
                        break;
                    }
                }
                let pp = PartToken.PartValue._new1347(t1, t2, cou.toString());
                res.values.push(pp);
                t1 = res.endToken = pp.endToken;
                continue;
            }
            if ((((t1.isValue("С", null) || t1.isValue("C", null))) && (t1.next instanceof NumberToken) && t1.next.next !== null) && t1.next.next.isValue("ПО", null) && (t1.next.next.next instanceof NumberToken)) {
                res.values.push(PartToken.PartValue._new1347(t1.next, t1.next, t1.next.value));
                res.values.push(PartToken.PartValue._new1347(t1.next.next.next, t1.next.next.next, t1.next.next.next.value));
                res.endToken = t1.next.next.next;
                break;
            }
            if (((t1 instanceof TextToken) && t1.lengthChar === 1 && t1.chars.isLetter) && res.values.length === 0) {
                if (t1.chars.isAllUpper && ((res.typ === PartTokenItemType.SUBPROGRAM || res.typ === PartTokenItemType.LIST))) {
                    res.values.push(PartToken.PartValue._new1347(t1, t1, t1.term));
                    res.endToken = t1;
                    return res;
                }
                let ok = true;
                let lev = 0;
                for (let ttt = t1.previous; ttt !== null; ttt = ttt.previous) {
                    if (ttt.isNewlineAfter) 
                        break;
                    if (ttt.isChar('(')) {
                        lev--;
                        if (lev < 0) {
                            ok = false;
                            break;
                        }
                    }
                    else if (ttt.isChar(')')) 
                        lev++;
                }
                if (ok && t1.next !== null && t1.next.isChar(')')) {
                    res.values.push(PartToken.PartValue._new1347(t1, t1.next, t1.term));
                    res.endToken = t1.next;
                    t1 = t1.next.next;
                    continue;
                }
                if (ok && (t1.next instanceof NumberToken) && !t1.isWhitespaceAfter) {
                    res.values.push(PartToken.PartValue._new1347(t1, t1.next, (t1.term + "." + t1.next.value)));
                    res.endToken = t1.next;
                    t1 = res.endToken.next;
                    if (t1 !== null && t1.isChar(')')) {
                        res.endToken = t1;
                        t1 = t1.next;
                    }
                    continue;
                }
                if (((ok && t1.next !== null && t1.next.isCharOf("(.[")) && !t1.next.isWhitespaceAfter && (t1.next.next instanceof NumberToken)) && t1.next.next.next !== null && t1.next.next.next.isCharOf(")]")) {
                    res.values.push(PartToken.PartValue._new1347(t1, t1.next.next.next, (t1.term + "." + t1.next.next.value)));
                    res.endToken = t1.next.next.next;
                    t1 = res.endToken.next;
                    continue;
                }
                if (ok && PartToken.tryAttach(t1.next, null, false, false) !== null) {
                    if (((t1.isAnd || t1.isValue("К", null) || t1.isValue("В", null))) && t1.chars.isAllLower) {
                    }
                    else {
                        res.values.push(PartToken.PartValue._new1347(t1, t1, t1.term));
                        res.endToken = t1;
                        t1 = t1.next;
                        continue;
                    }
                }
                if (t1.isValue("З", null) && t1.chars.isAllUpper) {
                    let val = PartToken.PartValue._new1347(t1, t1, "3");
                    val.correctValue();
                    res.values.push(val);
                    res.endToken = val.endToken;
                    t1 = val.endToken.next;
                    continue;
                }
                if (res.values.length === 0 && ((res.typ === PartTokenItemType.ITEM || res.typ === PartTokenItemType.SUBITEM))) {
                    ok = false;
                    if (t1.next !== null && t1.next.isCharOf(".,")) 
                        ok = true;
                    else if (DecreeChangeToken.M_TERMS.tryParse(t1.next, TerminParseAttr.NO) !== null) 
                        ok = true;
                    if (ok) {
                        res.values.push(PartToken.PartValue._new1347(t1, t1, t1.term));
                        res.endToken = t1;
                        return res;
                    }
                }
            }
            let prefTo = null;
            if (res.values.length > 0 && !(t1 instanceof NumberToken) && firstNumPrefix !== null) {
                ttn = MiscHelper.checkNumberPrefix(t1);
                if (ttn !== null) {
                    prefTo = t1;
                    t1 = ttn;
                }
            }
            if (t1 instanceof NumberToken) {
                let tt0 = (prefTo != null ? prefTo : t1);
                if (res.values.length > 0) {
                    if (res.values[0].intValue === 0 && !Utils.isDigit(res.values[0].value[0])) 
                        break;
                    if (t1.typ !== ntyp) 
                        break;
                    let pp = PartToken.tryAttach(t1, null, false, false);
                    if (pp !== null) 
                        break;
                }
                ntyp = t1.typ;
                let val = PartToken.PartValue._new1347(tt0, t1, t1.value.toString());
                val.correctValue();
                res.values.push(val);
                res.endToken = val.endToken;
                t1 = res.endToken.next;
                if ((res.typ === PartTokenItemType.FORM && (t1 instanceof TextToken) && t1.chars.isAllUpper) && (t1.lengthChar < 5) && (t1.whitespacesBeforeCount < 2)) {
                    val.endToken = res.endToken = t1;
                    t1 = t1.next;
                }
                if (and) 
                    break;
                if (res.typ === PartTokenItemType.ITEM && (t1 instanceof TextToken) && t1.isValue("ПРИМЕЧАНИЕ", null)) {
                    if (t1.next === null || t1.next.isValue("К", null) || t1.next.isComma) {
                        res.typ = PartTokenItemType.NOTICE;
                        res.endToken = t1;
                        return res;
                    }
                }
                continue;
            }
            let nt = NumberHelper.tryParseRoman(t1);
            if (nt !== null) {
                let pv = PartToken.PartValue._new1347(t1, nt.endToken, nt.value.toString());
                res.values.push(pv);
                pv.correctValue();
                res.endToken = pv.endToken;
                t1 = res.endToken.next;
                continue;
            }
            if ((t1 === tt1 && ((res.typ === PartTokenItemType.APPENDIX || res.typ === PartTokenItemType.ADDAGREE)) && t1.isValue("К", null)) && t1.next !== null) {
                if ((t1.next.getReferent() instanceof DecreeReferent) || DecreeToken.isKeyword(t1.next, false) !== null || DecreeToken.isKeyword(t1.next.next, false) !== null) {
                    res.values.push(PartToken.PartValue._new1347(t1, t1, ""));
                    break;
                }
            }
            if (res.typ === PartTokenItemType.ADDAGREE && firstNumPrefix !== null && res.values.length === 0) {
                let ddd = DecreeToken.tryAttach(firstNumPrefix, null, false);
                if (ddd !== null && ddd.typ === DecreeTokenItemType.NUMBER && ddd.value !== null) {
                    if (t1.beginChar <= ddd.endToken.beginChar) {
                        res.values.push(PartToken.PartValue._new1347(t1, ddd.endToken, ddd.value));
                        t1 = res.endToken = ddd.endToken;
                        break;
                    }
                }
            }
            if ((t1 instanceof TextToken) && t1.chars.isLatinLetter) {
                let te = Utils.as(t1, TextToken);
                let j = 0;
                let nn = "";
                for (j = 0; j < te.term.length; j++) {
                    let ch = te.term[j];
                    if (ch === 'O') {
                        if (j === 0) 
                            break;
                        nn += "0";
                    }
                    else if (ch === 'I' || ch === 'L') 
                        nn += "1";
                    else 
                        break;
                }
                if (j >= te.term.length) {
                    res.values.push(PartToken.PartValue._new1347(t1, t1, nn));
                    res.endToken = t1;
                    break;
                }
            }
            if (res.values.length === 0) 
                break;
            if (t1.isCharOf(",.")) {
                if (t1.isNewlineAfter && t1.isChar('.')) 
                    break;
                t1 = t1.next;
                continue;
            }
            if (t1.isHiphen && res.values[res.values.length - 1].value.indexOf('.') > 0) {
                t1 = t1.next;
                continue;
            }
            if (t1.isAnd || t1.isOr) {
                t1 = t1.next;
                and = true;
                continue;
            }
            if (t1.isHiphen) {
                let nmax = Utils.as(t1.next, NumberToken);
                if (nmax === null) 
                    nmax = NumberHelper.tryParseRoman(t1.next);
                if (nmax === null || nmax.intValue === null) 
                    break;
                let min = res.values[res.values.length - 1].intValue;
                if (min === 0) 
                    break;
                let max = nmax.intValue;
                if (max < min) 
                    break;
                if ((max - min) > 200) 
                    break;
                let val = PartToken.PartValue._new1347(t1.next, (nmax === t1.next ? t1.next : nmax.endToken), max.toString());
                val.correctValue();
                res.values.push(val);
                res.endToken = val.endToken;
                t1 = res.endToken.next;
                continue;
            }
            break;
        }
        if (res.decree === null && (res.endToken.whitespacesAfterCount < 3) && (res.endToken.next.getReferent() instanceof DecreeReferent)) {
            res.endToken = res.endToken.next;
            res.decree = Utils.as(res.endToken.getReferent(), DecreeReferent);
            if (res.typ === PartTokenItemType.PART && res.decree.kind === DecreeKind.KODEX) {
                let nam = Utils.notNull(res.decree.getStringValue("NAME"), "");
                if (nam.includes("ГРАЖДАНСКИЙ") || nam.includes("НАЛОГОВЫЙ")) 
                    res.typ = PartTokenItemType.DOCPART;
            }
        }
        let tte2 = res.endToken.next;
        if (tte2 !== null && tte2.isChar('.') && !tte2.isNewlineAfter) 
            tte2 = tte2.next;
        if ((res.whitespacesAfterCount < 3) && BracketHelper.canBeStartOfSequence(tte2, true, false)) {
            let lev = PartToken._getRank(res.typ);
            if (((lev > 0 && lev <= PartToken._getRank(PartTokenItemType.CLAUSE))) || res.typ === PartTokenItemType.TABLE || res.typ === PartTokenItemType.FORM) {
                let br = BracketHelper.tryParse(tte2, BracketParseAttr.CANCONTAINSVERBS, 100);
                if (br !== null && br.endToken.next !== null && res.values.length > 0) {
                    if (br.endToken.next.isValue("ЗАМЕНИТЬ", null) || br.endToken.next.isValue("ИСКЛЮЧИТЬ", null)) 
                        br = null;
                }
                if (br !== null) {
                    res.name = br;
                    res.endToken = br.endToken;
                    for (let tt2 = res.endToken.next; tt2 !== null; tt2 = tt2.next) {
                        if (!tt2.isCommaAnd) 
                            break;
                        br = BracketHelper.tryParse(tt2.next, BracketParseAttr.CANCONTAINSVERBS, 100);
                        if (br === null || (br.lengthChar < 10)) 
                            break;
                        if (res.addNames === null) 
                            res.addNames = new Array();
                        res.addNames.push(br);
                        res.endToken = br.endToken;
                        if (tt2.isAnd) 
                            break;
                        tt2 = br.endToken;
                    }
                }
            }
        }
        if (res.values.length === 0 && res.name === null) {
            if ((((!ignoreNumber && res.typ !== PartTokenItemType.PREAMBLE && res.typ !== PartTokenItemType.NAME) && res.typ !== PartTokenItemType.TABLE && res.typ !== PartTokenItemType.SUBPROGRAM) && res.typ !== PartTokenItemType.NOTICE && res.typ !== PartTokenItemType.FOOTNOTE) && res.typ !== PartTokenItemType.FORMULA && res.typ !== PartTokenItemType.APPENDIX) 
                return null;
            if (res.beginToken !== res.endToken) 
                res.endToken = res.endToken.previous;
        }
        if (res.endToken.next !== null && res.endToken.next.isChar('(')) {
            let br = BracketHelper.tryParse(res.endToken.next, BracketParseAttr.NO, 100);
            if (br !== null && (br.lengthChar < 40)) {
                if ((br.beginToken.next.isValue("СЕКРЕТНО", null) || br.beginToken.next.isValue("СОВЕРШЕННО", null) || br.beginToken.next.isValue("ДСП", null)) || br.beginToken.next.isValue2("ДЛЯ", "СЛУЖЕБНОГО")) {
                    res.isConfidential = true;
                    res.endToken = br.endToken;
                }
            }
        }
        if (res.typ === PartTokenItemType.TABLE && res.beginToken === res.endToken && res.beginToken.isValue("НОРМА", null)) 
            return null;
        return res;
    }
    
    static _createPartTyp0(t1, prev) {
        let isShort = false;
        let wrapisShort1391 = new RefOutArgWrapper();
        let pt = PartToken.__createPartTyp(t1, prev, wrapisShort1391);
        isShort = wrapisShort1391.value;
        if (pt === null) 
            return null;
        if (t1.lengthChar > 4) {
            pt.morph = t1.morph;
            if ((t1 instanceof TextToken) && t1.term === "СТАТЬЮ") {
                pt.morph = t1.morph.clone();
                pt.morph.removeItems(MorphCase.ACCUSATIVE, false);
            }
        }
        if ((isShort && !pt.endToken.isWhitespaceAfter && pt.endToken.next !== null) && pt.endToken.next.isChar('.')) {
            if (!pt.endToken.next.isNewlineAfter) 
                pt.endToken = pt.endToken.next;
        }
        return pt;
    }
    
    static __createPartTyp(t1, prev, isShort) {
        isShort.value = false;
        if (t1 === null) 
            return null;
        if (t1.isValue("ТЕРМИНОЛОГИЧЕСКИЙ", null)) {
            let res = PartToken.__createPartTyp(t1.next, prev, isShort);
            if (res !== null) 
                res.beginToken = t1;
            return res;
        }
        if (t1.isValue("ЧАСТЬ", "ЧАСТИНА") || t1.isValue("PART", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.PART);
        if (t1.isValue("Ч", null)) {
            isShort.value = true;
            return PartToken._new1058(t1, t1, PartTokenItemType.PART);
        }
        if (t1.isValue("ГЛАВА", null) || t1.isValue("ГЛ", null) || t1.isValue("CHAPTER", null)) {
            isShort.value = t1.lengthChar === 2;
            return PartToken._new1058(t1, t1, PartTokenItemType.CHAPTER);
        }
        if (t1.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК") || t1.isValue("ПРИЛ", null) || t1.isValue("APPENDIX", null)) {
            if ((t1.isNewlineBefore && t1.lengthChar > 6 && t1.next !== null) && t1.next.isChar(':')) 
                return null;
            if (t1.previous !== null && t1.previous.isValue("МОБИЛЬНЫЙ", null)) 
                return null;
            isShort.value = t1.lengthChar < 5;
            return PartToken._new1058(t1, t1, PartTokenItemType.APPENDIX);
        }
        if (t1.isValue("ПРИМЕЧАНИЕ", "ПРИМІТКА") || t1.isValue("ПРИМ", null)) {
            isShort.value = t1.lengthChar < 5;
            return PartToken._new1058(t1, t1, PartTokenItemType.NOTICE);
        }
        if (t1.isValue("ФОРМУЛА", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.FORMULA);
        if (t1.isValue("ФОРМА", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.FORM);
        if (t1.isValue("ТАБЛИЦА", null) || t1.isValue("НОРМА", null)) {
            let res = PartToken._new1058(t1, t1, PartTokenItemType.TABLE);
            if (t1.next !== null && t1.next.isValue("НОРМА", null)) 
                res.endToken = t1.next;
            return res;
        }
        if (t1.isValue("ЛИСТ", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.LIST);
        if (t1.isValue("СТРОКА", null) || t1.isValue("ПОЗИЦИЯ", null)) {
            if (t1.next !== null && t1.next.isValue("ТАБЛИЦА", null)) 
                return PartToken._new1058(t1, t1.next, PartTokenItemType.TABLEROW);
            return PartToken._new1058(t1, t1, PartTokenItemType.TABLEROW);
        }
        if (t1.isValue("ГРАФА", null) || t1.isValue("СУБПОЗИЦИЯ", null)) {
            if (t1.next !== null && t1.next.isValue("ТАБЛИЦА", null)) 
                return PartToken._new1058(t1, t1.next, PartTokenItemType.TABLEITEM);
            return PartToken._new1058(t1, t1, PartTokenItemType.TABLEITEM);
        }
        if (t1.isValue("ПРОГРАФКА", null)) {
            if (t1.next !== null && t1.next.isValue("ТАБЛИЦА", null)) 
                return PartToken._new1058(t1, t1.next, PartTokenItemType.TABLESUBITEM);
            return PartToken._new1058(t1, t1, PartTokenItemType.TABLESUBITEM);
        }
        if (t1.isValue("СТОЛБЕЦ", null)) {
            if (t1.next !== null && t1.next.isValue("ТАБЛИЦА", null)) 
                return PartToken._new1058(t1, t1.next, PartTokenItemType.TABLECOLUMN);
            return PartToken._new1058(t1, t1, PartTokenItemType.TABLECOLUMN);
        }
        if (t1.isValue("ПРЕДЛОЖЕНИЕ", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.SENTENCE);
        if (t1.isValue("СНОСКА", null)) {
            if (t1.previous !== null && t1.previous.isValue("ЗНАК", null)) {
            }
            else 
                return PartToken._new1058(t1, t1, PartTokenItemType.FOOTNOTE);
        }
        if (t1.isValue("СТАТЬЯ", "СТАТТЯ") || t1.isValue("СТ", null) || t1.isValue("ARTICLE", null)) {
            isShort.value = t1.lengthChar < 3;
            return PartToken._new1058(t1, t1, PartTokenItemType.CLAUSE);
        }
        if (t1.isValue("ПУНКТ", null) || t1.isValue("П", null) || t1.isValue("ПП", null)) {
            isShort.value = t1.lengthChar < 3;
            return PartToken._new1412(t1, t1, PartTokenItemType.ITEM, (t1.isValue("ПП", null) ? PartTokenItemType.SUBITEM : PartTokenItemType.UNDEFINED));
        }
        if (t1.isValue("ПОДПУНКТ", "ПІДПУНКТ") || t1.isValue("ПОЛПУНКТА", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.SUBITEM);
        if (t1.isValue("ПРЕАМБУЛА", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.PREAMBLE);
        if (t1.isValue("НАИМЕНОВАНИЕ", null) || t1.isValue("НАЗВАНИЕ", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.NAME);
        if (t1.isValue("ПОДП", null) || t1.isValue("ПІДП", null)) {
            isShort.value = true;
            return PartToken._new1058(t1, t1, PartTokenItemType.SUBITEM);
        }
        if (t1.isValue("РАЗДЕЛ", "РОЗДІЛ") || t1.isValue("РАЗД", null) || t1.isValue("SECTION", null)) {
            isShort.value = t1.lengthChar < 5;
            return PartToken._new1058(t1, t1, PartTokenItemType.SECTION);
        }
        if (((t1.isValue("Р", null) || t1.isValue("P", null))) && t1.next !== null && t1.next.isChar('.')) {
            if (prev !== null) {
                if (prev.typ === PartTokenItemType.ITEM || prev.typ === PartTokenItemType.SUBITEM) {
                    isShort.value = true;
                    return PartToken._new1058(t1, t1.next, PartTokenItemType.SECTION);
                }
            }
        }
        if (t1.isValue("ПОДРАЗДЕЛ", "ПІДРОЗДІЛ") || t1.isValue("SUBSECTION", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.SUBSECTION);
        if (t1.isValue("ПАРАГРАФ", null) || t1.isValue("§", null) || t1.isValue("PARAGRAPH", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.PARAGRAPH);
        if (t1.isValue("АБЗАЦ", null) || t1.isValue("АБЗ", null)) {
            isShort.value = t1.lengthChar < 7;
            return PartToken._new1058(t1, t1, PartTokenItemType.INDENTION);
        }
        if (t1.isValue("СТРАНИЦА", "СТОРІНКА") || t1.isValue("СТР", "СТОР") || t1.isValue("PAGE", null)) {
            isShort.value = t1.lengthChar < 7;
            return PartToken._new1058(t1, t1, PartTokenItemType.PAGE);
        }
        if (t1.isValue("ПОДАБЗАЦ", "ПІДАБЗАЦ") || t1.isValue("ПОДАБЗ", "ПІДАБЗ")) 
            return PartToken._new1058(t1, t1, PartTokenItemType.SUBINDENTION);
        if (t1.isValue("ПОДПАРАГРАФ", "ПІДПАРАГРАФ") || t1.isValue("SUBPARAGRAPH", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.SUBPARAGRAPH);
        if (t1.isValue("ПОДПРОГРАММА", "ПІДПРОГРАМА")) 
            return PartToken._new1058(t1, t1, PartTokenItemType.SUBPROGRAM);
        if (t1.isValue("ДОПСОГЛАШЕНИЕ", null)) 
            return PartToken._new1058(t1, t1, PartTokenItemType.ADDAGREE);
        if (((t1.isValue("ДОП", null) || t1.isValue("ДОПОЛНИТЕЛЬНЫЙ", "ДОДАТКОВА"))) && t1.next !== null) {
            let tt = t1.next;
            if (tt.isChar('.') && tt.next !== null) 
                tt = tt.next;
            if (tt.isValue("СОГЛАШЕНИЕ", "УГОДА")) 
                return PartToken._new1058(t1, tt, PartTokenItemType.ADDAGREE);
        }
        return null;
    }
    
    static tryAttachList(t, inBracket = false, maxCount = 40) {
        let p = PartToken.tryAttach(t, null, inBracket, false);
        if (p === null) 
            return null;
        if (p.typ === PartTokenItemType.PREFIX) {
            if ((p.whitespacesAfterCount < 3) && (p.endToken.next instanceof NumberToken)) {
            }
            else 
                return null;
        }
        let res = new Array();
        res.push(p);
        if (p.isNewlineAfter && p.isNewlineBefore) {
            if (!p.beginToken.chars.isAllLower) 
                return res;
        }
        let tt = p.endToken.next;
        while (tt !== null) {
            if (tt.whitespacesBeforeCount > 15) {
                if (tt.previous !== null && tt.previous.isCommaAnd) {
                }
                else 
                    break;
            }
            if (maxCount > 0 && res.length >= maxCount) 
                break;
            let delim = false;
            if (((tt.isCharOf(",;.:") || tt.isAnd || tt.isOr)) && tt.next !== null) {
                if (tt.isCharOf(";.:")) {
                    if (tt.isNewlineAfter) 
                        break;
                    res[res.length - 1].hasTerminator = true;
                }
                else {
                    res[res.length - 1].delimAfter = true;
                    if ((tt.next !== null && tt.next.isValue("А", null) && tt.next.next !== null) && tt.next.next.isValue("ТАКЖЕ", "ТАКОЖ")) 
                        tt = tt.next.next;
                }
                tt = tt.next;
                delim = true;
            }
            if (tt === null) 
                break;
            if (tt.isNewlineBefore) {
                if (tt.chars.isLetter && !tt.chars.isAllLower) 
                    break;
            }
            if (tt.isChar('(')) {
                let br = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                if (br !== null) {
                    let li = PartToken.tryAttachList(tt.next, true, 40);
                    if (li !== null && li.length > 0) {
                        if (li[0].typ === PartTokenItemType.PARAGRAPH || li[0].typ === PartTokenItemType.PART || li[0].typ === PartTokenItemType.ITEM) {
                            if (li[li.length - 1].endToken.next === br.endToken) {
                                if (p.values.length > 1) {
                                    for (let ii = 1; ii < p.values.length; ii++) {
                                        let pp = PartToken._new1058(p.values[ii].beginToken, (ii === (p.values.length - 1) ? p.endToken : p.values[ii].endToken), p.typ);
                                        pp.values.push(p.values[ii]);
                                        res.push(pp);
                                    }
                                    if (p.values[1].beginToken.previous !== null && p.values[1].beginToken.previous.endChar >= p.beginToken.beginChar) 
                                        p.endToken = p.values[1].beginToken.previous;
                                    p.values.splice(1, p.values.length - 1);
                                }
                                res.splice(res.length, 0, ...li);
                                li[li.length - 1].endToken = br.endToken;
                                tt = br.endToken.next;
                                continue;
                            }
                        }
                    }
                }
            }
            let p0 = PartToken.tryAttach(tt, p, inBracket, false);
            if (p0 === null && ((tt.isValue("В", null) || tt.isValue("ДО", null)))) 
                p0 = PartToken.tryAttach(tt.next, p, inBracket, false);
            if (p0 === null && ((tt.isValue("К", null) || tt.isValue("УКАЗАННЫЙ", null)))) {
                if (tt.next !== null && tt.next.getMorphClassInDictionary().isAdjective) 
                    tt = tt.next;
                p0 = PartToken.tryAttach(tt.next, p, inBracket, false);
            }
            if (p0 === null) {
                if (BracketHelper.isBracket(tt, false)) {
                    let br = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                    if (br !== null) {
                        p0 = PartToken.tryAttach(br.endToken.next, null, false, false);
                        if (p0 !== null && p0.typ !== PartTokenItemType.PREFIX && p0.values.length > 0) {
                            if (tt.isChar('(')) {
                                let p1 = PartToken.tryAttach(tt.next, p, true, false);
                                if (p1 !== null && p1.typ !== PartTokenItemType.PREFIX) {
                                    res.push(p1);
                                    p1.endToken = br.endToken;
                                    tt = br.endToken.next;
                                    continue;
                                }
                            }
                            res[res.length - 1].endToken = br.endToken;
                            res[res.length - 1].name = br;
                            if (p0.isNewlineBefore) 
                                break;
                            p = p0;
                            res.push(p);
                            tt = p.endToken.next;
                            continue;
                        }
                        if ((BracketHelper.isBracket(tt, true) && (tt.whitespacesBeforeCount < 3) && res[res.length - 1].typ === PartTokenItemType.APPENDIX) && res[res.length - 1].name === null) {
                            res[res.length - 1].endToken = br.endToken;
                            res[res.length - 1].name = br;
                            tt = br.endToken.next;
                            continue;
                        }
                    }
                }
                if (tt.isNewlineBefore) {
                    if (res.length === 1 && res[0].isNewlineBefore) 
                        break;
                    if (tt.previous !== null && tt.previous.isCommaAnd) {
                    }
                    else 
                        break;
                }
                if ((tt instanceof NumberToken) && delim) {
                    p0 = null;
                    if (p.typ === PartTokenItemType.CLAUSE || inBracket) 
                        p0 = PartToken._new1058(tt, tt, PartTokenItemType.CLAUSE);
                    else if (res.length > 1 && res[res.length - 2].typ === PartTokenItemType.CLAUSE && res[res.length - 1].typ === PartTokenItemType.PART) 
                        p0 = PartToken._new1058(tt, tt, PartTokenItemType.CLAUSE);
                    else if ((res.length > 2 && res[res.length - 3].typ === PartTokenItemType.CLAUSE && res[res.length - 2].typ === PartTokenItemType.PART) && res[res.length - 1].typ === PartTokenItemType.ITEM) 
                        p0 = PartToken._new1058(tt, tt, PartTokenItemType.CLAUSE);
                    else if (res.length > 0 && res[res.length - 1].values.length > 0 && res[res.length - 1].values[0].value.includes(".")) 
                        p0 = PartToken._new1058(tt, tt, res[res.length - 1].typ);
                    if (p0 === null) 
                        break;
                    let vv = PartToken.PartValue._new1347(tt, tt, tt.value.toString());
                    p0.values.push(vv);
                    vv.correctValue();
                    p0.endToken = vv.endToken;
                    tt = p0.endToken.next;
                    if (tt !== null && tt.isHiphen && (tt.next instanceof NumberToken)) {
                        tt = tt.next;
                        vv = PartToken.PartValue._new1347(tt, tt, tt.value.toString());
                        vv.correctValue();
                        p0.values.push(vv);
                        p0.endToken = vv.endToken;
                        tt = p0.endToken.next;
                    }
                }
            }
            if (tt !== null && tt.isChar(',') && !tt.isNewlineAfter) {
                let p1 = PartToken.tryAttach(tt.next, p, false, false);
                if (p1 !== null && PartToken._getRank(p1.typ) > 0 && PartToken._getRank(p.typ) > 0) {
                    if (PartToken._getRank(p1.typ) < PartToken._getRank(p.typ)) 
                        p0 = p1;
                }
            }
            if (p0 === null) 
                break;
            if (p0.isNewlineBefore && res.length === 1 && res[0].isNewlineBefore) 
                break;
            if (p0.morph !== null && p0.morph._case.isInstrumental) {
                if ((p.typ !== PartTokenItemType.PREFIX && !p.delimAfter && p.morph !== null) && !p.morph._case.isInstrumental) 
                    break;
                else if ((p.beginToken instanceof TextToken) && p.beginToken.term === "СТАТЬЮ") 
                    break;
            }
            if (p0.typ === PartTokenItemType.ITEM && p.typ === PartTokenItemType.ITEM) {
                if (p0.altTyp === PartTokenItemType.UNDEFINED && p.altTyp === PartTokenItemType.SUBITEM) {
                    p.typ = PartTokenItemType.SUBITEM;
                    p.altTyp = PartTokenItemType.UNDEFINED;
                }
                else if (p.altTyp === PartTokenItemType.UNDEFINED && p0.altTyp === PartTokenItemType.SUBITEM) {
                    p0.typ = PartTokenItemType.SUBITEM;
                    p0.altTyp = PartTokenItemType.UNDEFINED;
                }
                else if (p0.altTyp === PartTokenItemType.SUBITEM && p.altTyp === PartTokenItemType.SUBITEM) {
                    let _next = PartToken.tryAttach(p0.endToken.next, null, false, false);
                    if (_next !== null && _next.typ === PartTokenItemType.ITEM && _next.altTyp === PartTokenItemType.UNDEFINED) {
                        p.typ = PartTokenItemType.SUBITEM;
                        p.altTyp = PartTokenItemType.UNDEFINED;
                        p0.typ = PartTokenItemType.SUBITEM;
                        p0.altTyp = PartTokenItemType.UNDEFINED;
                    }
                }
            }
            p = p0;
            res.push(p);
            if (p.typ === PartTokenItemType.APPENDIX && res.length > 1 && res[res.length - 2].typ === PartTokenItemType.APPENDIX) {
                if (p.beginToken.previous.isValue("К", null) || ((p.beginToken.previous.previous !== null && p.beginToken.previous.previous.isValue("К", null)))) 
                    res[res.length - 2].typ = PartTokenItemType.APPENDIX2;
            }
            tt = p.endToken.next;
        }
        for (let i = 0; i < (res.length - 1); i++) {
            if (res[i].typ === PartTokenItemType.PART && res[i + 1].typ === PartTokenItemType.PART && res[i].values.length > 1) {
                let v1 = res[i].values[res[i].values.length - 2].intValue;
                let v2 = res[i].values[res[i].values.length - 1].intValue;
                if (v1 === 0 || v2 === 0) 
                    continue;
                if ((v2 - v1) < 10) 
                    continue;
                let pt = PartToken._new1058(res[i].endToken, res[i].endToken, PartTokenItemType.CLAUSE);
                pt.values.push(PartToken.PartValue._new1347(res[i].endToken, res[i].endToken, v2.toString()));
                res[i].values.splice(res[i].values.length - 1, 1);
                if (res[i].endToken !== res[i].beginToken) 
                    res[i].endToken = res[i].endToken.previous;
                res.splice(i + 1, 0, pt);
            }
        }
        if ((res.length === 1 && res[0].typ === PartTokenItemType.SUBPROGRAM && res[0].endToken.next !== null) && res[0].endToken.next.isChar('.')) 
            res[0].endToken = res[0].endToken.next;
        for (let i = res.length - 1; i >= 0; i--) {
            p = res[i];
            if ((p.decree === null && p.isNewlineAfter && p.isNewlineBefore) && p.typ !== PartTokenItemType.SUBPROGRAM) {
                res.splice(i, res.length - i);
                continue;
            }
            if (((i === 0 && res.length > 1 && ((p.isNewlineBefore || ((p.beginToken.previous !== null && p.beginToken.previous.isTableControlChar))))) && p.hasTerminator && p.endToken.next !== null) && p.endToken.next.isChar('.') && MiscHelper.canBeStartOfSentence(p.endToken.next.next)) {
                res.splice(i, 1);
                continue;
            }
        }
        if (res.length > 1 && res[res.length - 1].typ === PartTokenItemType.NAME) 
            res.splice(res.length - 1, 1);
        if (res.length === 1 && res[0].typ === PartTokenItemType.PREFIX) 
            return null;
        if (res.length === 1 && res[0].typ === PartTokenItemType.SENTENCE) {
            let dt = DecreeToken.tryAttach(res[0].endToken.next, null, false);
            if (dt !== null && dt.typ === DecreeTokenItemType.DATE) 
                return null;
        }
        return (res.length === 0 ? null : res);
    }
    
    canBeNextNarrow(p, parts) {
        if (this.typ === PartTokenItemType.FORMULA) 
            return false;
        if (p.typ === PartTokenItemType.FORMULA) 
            return true;
        if (p.typ === PartTokenItemType.FREETEXT) 
            return true;
        if (this.typ === PartTokenItemType.FREETEXT) 
            return false;
        if (this.typ === PartTokenItemType.SENTENCE) 
            return false;
        if (p.typ === PartTokenItemType.SENTENCE) {
            if (((this.typ === PartTokenItemType.PREAMBLE || this.typ === PartTokenItemType.INDENTION || this.typ === PartTokenItemType.PART) || this.typ === PartTokenItemType.ITEM || this.typ === PartTokenItemType.SUBITEM) || this.typ === PartTokenItemType.TABLESUBITEM) 
                return true;
            return false;
        }
        if (this.typ === PartTokenItemType.TABLE) {
            if (((p.typ === PartTokenItemType.TABLECOLUMN || p.typ === PartTokenItemType.TABLEROW || p.typ === PartTokenItemType.TABLEITEM) || p.typ === PartTokenItemType.TABLESUBITEM || p.typ === PartTokenItemType.NAME) || p.typ === PartTokenItemType.ITEM) 
                return true;
        }
        if (this.typ === p.typ) {
            if (this.typ !== PartTokenItemType.SUBITEM) 
                return false;
            if (p.values !== null && p.values.length > 0 && p.values[0].intValue === 0) {
                if (this.values !== null && this.values.length > 0 && this.values[0].intValue > 0) 
                    return true;
            }
            return false;
        }
        if (this.typ === PartTokenItemType.PART || p.typ === PartTokenItemType.PART) 
            return true;
        if (this.typ === PartTokenItemType.NOTICE || this.typ === PartTokenItemType.FOOTNOTE) {
            if (p.typ === PartTokenItemType.INDENTION) 
                return true;
        }
        let i1 = PartToken._getRank(this.typ);
        let i2 = PartToken._getRank(p.typ);
        if (this.typ === PartTokenItemType.TABLEROW && parts !== null) {
            for (const pp of parts) {
                if (pp.typ === PartTokenItemType.ITEM) {
                    i1 += 2;
                    break;
                }
            }
        }
        if (p.typ === PartTokenItemType.TABLEROW && parts !== null) {
            for (const pp of parts) {
                if (pp.typ === PartTokenItemType.ITEM) {
                    i2 += 2;
                    break;
                }
            }
        }
        if (i1 >= 0 && i2 >= 0) 
            return i1 < i2;
        return false;
    }
    
    static isPartBefore(t0) {
        if (t0 === null) 
            return false;
        let i = 0;
        for (let tt = t0.previous; tt !== null; tt = tt.previous) {
            if (tt.isNewlineAfter || (tt instanceof ReferentToken)) 
                break;
            else {
                let st = PartToken.tryAttach(tt, null, false, false);
                if (st !== null) {
                    if (st.endToken.next === t0) 
                        return true;
                    break;
                }
                if ((tt instanceof TextToken) && tt.chars.isLetter) {
                    if ((++i) > 2) 
                        break;
                }
            }
        }
        return false;
    }
    
    static _getRank(t) {
        if (t === PartTokenItemType.DOCPART) 
            return 1;
        if (t === PartTokenItemType.APPENDIX) 
            return 1;
        if (t === PartTokenItemType.APPENDIX2) 
            return 2;
        if (t === PartTokenItemType.SECTION) 
            return 2;
        if (t === PartTokenItemType.SUBPROGRAM) 
            return 2;
        if (t === PartTokenItemType.SUBSECTION) 
            return 3;
        if (t === PartTokenItemType.CHAPTER) 
            return 4;
        if (t === PartTokenItemType.PREAMBLE) 
            return 5;
        if (t === PartTokenItemType.PARAGRAPH) 
            return 5;
        if (t === PartTokenItemType.SUBPARAGRAPH) 
            return 6;
        if (t === PartTokenItemType.PAGE) 
            return 6;
        if (t === PartTokenItemType.CLAUSE) 
            return 7;
        if (t === PartTokenItemType.FORM) 
            return 8;
        if (t === PartTokenItemType.TABLE) 
            return 8;
        if (t === PartTokenItemType.LIST) 
            return 9;
        if (t === PartTokenItemType.PART) 
            return 9;
        if (t === PartTokenItemType.NOTICE) 
            return 9;
        if (t === PartTokenItemType.TABLEROW) 
            return 10;
        if (t === PartTokenItemType.TABLEITEM) 
            return 11;
        if (t === PartTokenItemType.TABLESUBITEM) 
            return 12;
        if (t === PartTokenItemType.ITEM) 
            return 10;
        if (t === PartTokenItemType.SUBITEM) 
            return 11;
        if (t === PartTokenItemType.NAME) 
            return 12;
        if (t === PartTokenItemType.INDENTION) 
            return 13;
        if (t === PartTokenItemType.SUBINDENTION) 
            return 14;
        if (t === PartTokenItemType.SENTENCE) 
            return 15;
        if (t === PartTokenItemType.TABLECOLUMN) 
            return 16;
        if (t === PartTokenItemType.FOOTNOTE) 
            return 16;
        if (t === PartTokenItemType.FORMULA) 
            return 17;
        if (t === PartTokenItemType.FREETEXT) 
            return 20;
        return 0;
    }
    
    static _getAttrNameByTyp(_typ) {
        if (_typ === PartTokenItemType.CHAPTER) 
            return DecreePartReferent.ATTR_CHAPTER;
        if (_typ === PartTokenItemType.APPENDIX) 
            return DecreePartReferent.ATTR_APPENDIX;
        if (_typ === PartTokenItemType.APPENDIX2) 
            return DecreePartReferent.ATTR_APPENDIX2;
        if (_typ === PartTokenItemType.CLAUSE) 
            return DecreePartReferent.ATTR_CLAUSE;
        if (_typ === PartTokenItemType.INDENTION) 
            return DecreePartReferent.ATTR_INDENTION;
        if (_typ === PartTokenItemType.ITEM) 
            return DecreePartReferent.ATTR_ITEM;
        if (_typ === PartTokenItemType.PARAGRAPH) 
            return DecreePartReferent.ATTR_PARAGRAPH;
        if (_typ === PartTokenItemType.SUBPARAGRAPH) 
            return DecreePartReferent.ATTR_SUBPARAGRAPH;
        if (_typ === PartTokenItemType.PART) 
            return DecreePartReferent.ATTR_PART;
        if (_typ === PartTokenItemType.SECTION) 
            return DecreePartReferent.ATTR_SECTION;
        if (_typ === PartTokenItemType.SUBSECTION) 
            return DecreePartReferent.ATTR_SUBSECTION;
        if (_typ === PartTokenItemType.SUBINDENTION) 
            return DecreePartReferent.ATTR_SUBINDENTION;
        if (_typ === PartTokenItemType.SUBITEM) 
            return DecreePartReferent.ATTR_SUBITEM;
        if (_typ === PartTokenItemType.PREAMBLE) 
            return DecreePartReferent.ATTR_PREAMBLE;
        if (_typ === PartTokenItemType.NOTICE) 
            return DecreePartReferent.ATTR_NOTICE;
        if (_typ === PartTokenItemType.FOOTNOTE) 
            return DecreePartReferent.ATTR_FOOTNOTE;
        if (_typ === PartTokenItemType.FORMULA) 
            return DecreePartReferent.ATTR_FORMULA;
        if (_typ === PartTokenItemType.FORM) 
            return DecreePartReferent.ATTR_FORM;
        if (_typ === PartTokenItemType.LIST) 
            return DecreePartReferent.ATTR_LIST;
        if (_typ === PartTokenItemType.TABLE) 
            return DecreePartReferent.ATTR_TABLE;
        if (_typ === PartTokenItemType.TABLECOLUMN) 
            return DecreePartReferent.ATTR_TABLECOLUMN;
        if (_typ === PartTokenItemType.TABLEROW) 
            return DecreePartReferent.ATTR_TABLEROW;
        if (_typ === PartTokenItemType.TABLEITEM) 
            return DecreePartReferent.ATTR_TABLEITEM;
        if (_typ === PartTokenItemType.TABLESUBITEM) 
            return DecreePartReferent.ATTR_TABLESUBITEM;
        if (_typ === PartTokenItemType.SENTENCE) 
            return DecreePartReferent.ATTR_SENTENCE;
        if (_typ === PartTokenItemType.NAME) 
            return DecreePartReferent.ATTR_NAMEASITEM;
        if (_typ === PartTokenItemType.SUBPROGRAM) 
            return DecreePartReferent.ATTR_SUBPROGRAM;
        if (_typ === PartTokenItemType.ADDAGREE) 
            return DecreePartReferent.ATTR_ADDAGREE;
        if (_typ === PartTokenItemType.DOCPART) 
            return DecreePartReferent.ATTR_DOCPART;
        if (_typ === PartTokenItemType.PAGE) 
            return DecreePartReferent.ATTR_PAGE;
        if (_typ === PartTokenItemType.FREETEXT) 
            return DecreePartReferent.ATTR_FREETEXT;
        return null;
    }
    
    static _getInstrKindByTyp(_typ) {
        if (_typ === PartTokenItemType.CHAPTER) 
            return InstrumentKind.CHAPTER;
        if (_typ === PartTokenItemType.APPENDIX) 
            return InstrumentKind.APPENDIX;
        if (_typ === PartTokenItemType.CLAUSE) 
            return InstrumentKind.CLAUSE;
        if (_typ === PartTokenItemType.INDENTION) 
            return InstrumentKind.INDENTION;
        if (_typ === PartTokenItemType.ITEM) 
            return InstrumentKind.ITEM;
        if (_typ === PartTokenItemType.PARAGRAPH) 
            return InstrumentKind.PARAGRAPH;
        if (_typ === PartTokenItemType.SUBPARAGRAPH) 
            return InstrumentKind.SUBPARAGRAPH;
        if (_typ === PartTokenItemType.PART) 
            return InstrumentKind.CLAUSEPART;
        if (_typ === PartTokenItemType.SECTION) 
            return InstrumentKind.SECTION;
        if (_typ === PartTokenItemType.SUBSECTION) 
            return InstrumentKind.SUBSECTION;
        if (_typ === PartTokenItemType.SUBITEM) 
            return InstrumentKind.SUBITEM;
        if (_typ === PartTokenItemType.PREAMBLE) 
            return InstrumentKind.PREAMBLE;
        if (_typ === PartTokenItemType.NOTICE) 
            return InstrumentKind.NOTICE;
        if (_typ === PartTokenItemType.DOCPART) 
            return InstrumentKind.DOCPART;
        if (_typ === PartTokenItemType.TABLE) 
            return InstrumentKind.TABLE;
        return InstrumentKind.UNDEFINED;
    }
    
    static _getTypeByAttrName(_name) {
        if (_name === DecreePartReferent.ATTR_CHAPTER) 
            return PartTokenItemType.CHAPTER;
        if (_name === DecreePartReferent.ATTR_APPENDIX) 
            return PartTokenItemType.APPENDIX;
        if (_name === DecreePartReferent.ATTR_APPENDIX2) 
            return PartTokenItemType.APPENDIX2;
        if (_name === DecreePartReferent.ATTR_CLAUSE) 
            return PartTokenItemType.CLAUSE;
        if (_name === DecreePartReferent.ATTR_INDENTION) 
            return PartTokenItemType.INDENTION;
        if (_name === DecreePartReferent.ATTR_ITEM) 
            return PartTokenItemType.ITEM;
        if (_name === DecreePartReferent.ATTR_PARAGRAPH) 
            return PartTokenItemType.PARAGRAPH;
        if (_name === DecreePartReferent.ATTR_SUBPARAGRAPH) 
            return PartTokenItemType.SUBPARAGRAPH;
        if (_name === DecreePartReferent.ATTR_PART) 
            return PartTokenItemType.PART;
        if (_name === DecreePartReferent.ATTR_SECTION) 
            return PartTokenItemType.SECTION;
        if (_name === DecreePartReferent.ATTR_SUBSECTION) 
            return PartTokenItemType.SUBSECTION;
        if (_name === DecreePartReferent.ATTR_SUBINDENTION) 
            return PartTokenItemType.SUBINDENTION;
        if (_name === DecreePartReferent.ATTR_SUBITEM) 
            return PartTokenItemType.SUBITEM;
        if (_name === DecreePartReferent.ATTR_NOTICE) 
            return PartTokenItemType.NOTICE;
        if (_name === DecreePartReferent.ATTR_FOOTNOTE) 
            return PartTokenItemType.FOOTNOTE;
        if (_name === DecreePartReferent.ATTR_FORMULA) 
            return PartTokenItemType.FORMULA;
        if (_name === DecreePartReferent.ATTR_FORM) 
            return PartTokenItemType.FORM;
        if (_name === DecreePartReferent.ATTR_LIST) 
            return PartTokenItemType.LIST;
        if (_name === DecreePartReferent.ATTR_TABLE) 
            return PartTokenItemType.TABLE;
        if (_name === DecreePartReferent.ATTR_TABLECOLUMN) 
            return PartTokenItemType.TABLECOLUMN;
        if (_name === DecreePartReferent.ATTR_TABLEROW) 
            return PartTokenItemType.TABLEROW;
        if (_name === DecreePartReferent.ATTR_TABLEITEM) 
            return PartTokenItemType.TABLEITEM;
        if (_name === DecreePartReferent.ATTR_TABLESUBITEM) 
            return PartTokenItemType.TABLESUBITEM;
        if (_name === DecreePartReferent.ATTR_SENTENCE) 
            return PartTokenItemType.SENTENCE;
        if (_name === DecreePartReferent.ATTR_NAMEASITEM) 
            return PartTokenItemType.NAME;
        if (_name === DecreePartReferent.ATTR_PREAMBLE) 
            return PartTokenItemType.PREAMBLE;
        if (_name === DecreePartReferent.ATTR_SUBPROGRAM) 
            return PartTokenItemType.SUBPROGRAM;
        if (_name === DecreePartReferent.ATTR_ADDAGREE) 
            return PartTokenItemType.ADDAGREE;
        if (_name === DecreePartReferent.ATTR_DOCPART) 
            return PartTokenItemType.DOCPART;
        if (_name === DecreePartReferent.ATTR_FREETEXT) 
            return PartTokenItemType.FREETEXT;
        return PartTokenItemType.PREFIX;
    }
    
    static tryCreateBetween(p1, p2) {
        const NumberingHelper = require("./../../instrument/internal/NumberingHelper");
        let notEqAttr = null;
        let val1 = null;
        let val2 = null;
        for (const s1 of p1.slots) {
            if (p2.findSlot(s1.typeName, s1.value, true) !== null) 
                continue;
            else {
                if (notEqAttr !== null) 
                    return null;
                val2 = p2.getStringValue(s1.typeName);
                if (val2 === null) 
                    return null;
                notEqAttr = s1.typeName;
                val1 = Utils.asString(s1.value);
            }
        }
        if (val1 === null || val2 === null) 
            return null;
        let diap = NumberingHelper.createDiap(val1, val2);
        if (diap === null || (diap.length < 3)) 
            return null;
        let res = new Array();
        for (let i = 1; i < (diap.length - 1); i++) {
            let dpr = new DecreePartReferent();
            for (const s of p1.slots) {
                let val = s.value;
                if (s.typeName === notEqAttr) 
                    val = diap[i];
                dpr.addSlot(s.typeName, val, false, 0);
            }
            res.push(dpr);
        }
        return res;
    }
    
    static getNumber(str) {
        if (Utils.isNullOrEmpty(str)) 
            return 0;
        let i = 0;
        let wrapi1441 = new RefOutArgWrapper();
        let inoutres1442 = Utils.tryParseInt(str, wrapi1441);
        i = wrapi1441.value;
        if (inoutres1442) 
            return i;
        if (!Utils.isLetter(str[0])) 
            return 0;
        let ch = str[0].toUpperCase();
        if ((ch.charCodeAt(0)) < 0x80) {
            i = ((ch.charCodeAt(0)) - ('A'.charCodeAt(0))) + 1;
            if ((ch === 'Z' && str.length > 2 && str[1] === '.') && Utils.isDigit(str[2])) {
                let n = 0;
                let wrapn1437 = new RefOutArgWrapper();
                let inoutres1438 = Utils.tryParseInt(str.substring(2), wrapn1437);
                n = wrapn1437.value;
                if (inoutres1438) 
                    i += n;
            }
        }
        else if (LanguageHelper.isCyrillicChar(ch)) {
            i = PartToken.ruNums.indexOf(ch);
            if (i < 0) 
                return 0;
            i++;
            if ((ch === 'Я' && str.length > 2 && str[1] === '.') && Utils.isDigit(str[2])) {
                let n = 0;
                let wrapn1439 = new RefOutArgWrapper();
                let inoutres1440 = Utils.tryParseInt(str.substring(2), wrapn1439);
                n = wrapn1439.value;
                if (inoutres1440) 
                    i += n;
            }
        }
        if (i < 0) 
            return 0;
        return i;
    }
    
    compareTo(other) {
        if ((this.typ.value()) > (other.typ.value())) 
            return -1;
        if ((this.typ.value()) < (other.typ.value())) 
            return 1;
        return 0;
    }
    
    static sort(list) {
        for (let ii = 0; ii < list.length; ii++) {
            for (let jj = 0; jj < (list.length - 1); jj++) {
                if (list[jj].compareTo(list[jj + 1]) > 0) {
                    let pp = list[jj];
                    list[jj] = list[jj + 1];
                    list[jj + 1] = pp;
                }
            }
        }
    }
    
    static _new1052(_arg1, _arg2, _arg3, _arg4) {
        let res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.tag = _arg4;
        return res;
    }
    
    static _new1056(_arg1, _arg2, _arg3, _arg4, _arg5) {
        let res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.morph = _arg4;
        res.tag = _arg5;
        return res;
    }
    
    static _new1058(_arg1, _arg2, _arg3) {
        let res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        return res;
    }
    
    static _new1060(_arg1, _arg2, _arg3, _arg4) {
        let res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.morph = _arg4;
        return res;
    }
    
    static _new1357(_arg1, _arg2, _arg3, _arg4) {
        let res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.isDoubt = _arg4;
        return res;
    }
    
    static _new1412(_arg1, _arg2, _arg3, _arg4) {
        let res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.altTyp = _arg4;
        return res;
    }
    
    static static_constructor() {
        PartToken.ruNums = "АБВГДЕЖЗИКЛМНОПРСТУФХЦЧШЩЭЮЯ";
    }
}


PartToken.PartValue = class  extends MetaToken {
    
    constructor(begin, end) {
        super(begin, end, null);
        this.value = null;
    }
    
    get sourceValue() {
        const MetaToken = require("./../../MetaToken");
        let t0 = this.beginToken;
        let t1 = this.endToken;
        if (t1.isChar('.')) 
            t1 = t1.previous;
        else if (t1.isChar(')')) {
            let hasBr = false;
            for (let tt = t0; tt !== null && (tt.endChar < this.endChar); tt = tt.next) {
                if (tt.isChar('(')) 
                    hasBr = true;
            }
            if (!hasBr) 
                t1 = t1.previous;
        }
        if (t0.beginChar > t1.beginChar) 
            return "";
        return new MetaToken(t0, t1).getSourceText();
    }
    
    get intValue() {
        if (Utils.isNullOrEmpty(this.value)) 
            return 0;
        let num = 0;
        let wrapnum1345 = new RefOutArgWrapper();
        let inoutres1346 = Utils.tryParseInt(this.value, wrapnum1345);
        num = wrapnum1345.value;
        if (inoutres1346) 
            return num;
        return 0;
    }
    
    toString() {
        return this.value;
    }
    
    correctValue() {
        const DecreeReferent = require("./../DecreeReferent");
        const TerminParseAttr = require("./../../core/TerminParseAttr");
        const NumberToken = require("./../../NumberToken");
        const TextToken = require("./../../TextToken");
        const BracketHelper = require("./../../core/BracketHelper");
        const DecreeChangeToken = require("./DecreeChangeToken");
        if ((this.endToken.next instanceof TextToken) && this.endToken.next.lengthChar === 1 && this.endToken.next.chars.isLetter) {
            if (!this.endToken.isWhitespaceAfter) {
                this.value += this.endToken.next.term;
                this.endToken = this.endToken.next;
            }
            else if ((this.endToken.whitespacesAfterCount < 2) && this.endToken.next.next !== null && this.endToken.next.next.isChar(')')) {
                this.value += this.endToken.next.term;
                this.endToken = this.endToken.next.next;
            }
        }
        if (((this.endToken.whitespacesAfterCount < 3) && BracketHelper.canBeStartOfSequence(this.endToken.next, false, false) && (this.endToken.next.next instanceof TextToken)) && this.endToken.next.next.lengthChar === 1 && BracketHelper.canBeEndOfSequence(this.endToken.next.next.next, false, this.endToken.next, false)) {
            this.value = (this.value + "." + this.endToken.next.next.term);
            this.endToken = this.endToken.next.next.next;
        }
        if (((this.endToken.whitespacesAfterCount < 3) && BracketHelper.canBeStartOfSequence(this.endToken.next, false, false) && (this.endToken.next.next instanceof NumberToken)) && BracketHelper.canBeEndOfSequence(this.endToken.next.next.next, false, this.endToken.next, false)) {
            this.value = (this.value + "." + this.endToken.next.next.value);
            this.endToken = this.endToken.next.next.next;
        }
        if ((this.endToken.next instanceof NumberToken) && (this.endToken.whitespacesAfterCount < 2) && (this.endToken.next.whitespacesAfterCount < 2)) {
            let ok = false;
            let tt2 = this.endToken.next;
            if (tt2.isNewlineAfter) 
                ok = true;
            else if (tt2.next.getReferent() instanceof DecreeReferent) 
                ok = true;
            else if (tt2.next.isCharOf("<:.")) 
                ok = true;
            else if (tt2.next.isValue("ПОСЛЕ", null) || DecreeChangeToken.M_TERMS.tryParse(tt2.next, TerminParseAttr.NO) !== null) 
                ok = true;
            else {
                let ne = PartToken.tryAttach(tt2.next, null, false, false);
                if (ne !== null && ne.values.length === 1) 
                    ok = true;
            }
            if (ok) {
                this.endToken = this.endToken.next;
                this.value = (this.value + "." + this.endToken.value);
            }
        }
        for (let t = this.endToken.next; t !== null; t = t.next) {
            if (t.isWhitespaceBefore) {
                if (t.whitespacesBeforeCount > 1) 
                    break;
                if (t.isChar('<')) {
                }
                else {
                    if (((t instanceof TextToken) && t.lengthChar === 1 && t.next !== null) && t.next.isChar(')')) {
                        this.value = (((this.value != null ? this.value : "")) + "." + t.term);
                        this.endToken = (t = t.next);
                    }
                    break;
                }
            }
            if (t.isCharOf("_.") && !t.isWhitespaceAfter) {
                if (t.next instanceof NumberToken) {
                    this.value = (((this.value != null ? this.value : "")) + "." + t.next.value);
                    this.endToken = (t = t.next);
                    continue;
                }
                if (((t.next !== null && t.next.isChar('(') && (t.next.next instanceof NumberToken)) && !t.next.isWhitespaceAfter && t.next.next.next !== null) && t.next.next.next.isChar(')')) {
                    this.value = (((this.value != null ? this.value : "")) + "." + t.next.next.value);
                    this.endToken = t.next.next.next;
                    continue;
                }
            }
            if (t.isCharOf("ˡ¹²³")) {
                this.value = (this.value + "." + (t.isCharOf("ˡ¹") ? "1" : (t.isChar('²') ? "2" : "3")));
                this.endToken = t;
                continue;
            }
            if ((t.isHiphen && !t.isWhitespaceAfter && (t.next instanceof NumberToken)) && t.next.intValue !== null) {
                let pp = PartToken.PartValue._new1347(t.next, t.next, t.next.value);
                pp.correctValue();
                if (pp.value === t.next.value) {
                    let n1 = 0;
                    let wrapn11348 = new RefOutArgWrapper();
                    Utils.tryParseInt(this.value, wrapn11348);
                    n1 = wrapn11348.value;
                    if (n1 === 0 || n1 >= t.next.intValue) {
                        this.value = (((this.value != null ? this.value : "")) + "." + t.next.value);
                        this.endToken = (t = t.next);
                        continue;
                    }
                    if (((this.value !== null && this.value.indexOf('.') > 0 && (t.previous instanceof NumberToken)) && t.next.next !== null && t.next.next.isChar('.')) && !(t.next.next.next instanceof NumberToken)) {
                        this.value = (((this.value != null ? this.value : "")) + "." + t.next.value);
                        this.endToken = (t = t.next.next);
                        break;
                    }
                }
            }
            if (t.isCharOf("(<") && (t.next instanceof NumberToken) && t.next.next !== null) {
                if (t.next.next.isCharOf(")>")) {
                    this.value = (((this.value != null ? this.value : "")) + "." + t.next.value);
                    this.endToken = (t = t.next.next);
                }
                else if ((t.next.next.isCharOf(".-") && (t.next.next.next instanceof NumberToken) && t.next.next.next.next !== null) && t.next.next.next.next.isCharOf(")>")) {
                    this.value = (((this.value != null ? this.value : "")) + "." + t.next.value + "." + t.next.next.next.value);
                    this.endToken = (t = t.next.next.next.next);
                }
                if (t.next !== null && t.next.isChar('.') && !t.isWhitespaceAfter) 
                    t = t.next;
                continue;
            }
            if ((t.isChar('\\') && (t.next instanceof NumberToken) && !t.isWhitespaceBefore) && !t.isWhitespaceAfter) {
                this.value = (((this.value != null ? this.value : "")) + "." + t.next.value);
                this.endToken = (t = t.next);
                continue;
            }
            break;
        }
        if (this.endToken.next !== null && this.endToken.next.isCharOf(".") && !this.endToken.isWhitespaceAfter) {
            if (this.endToken.next.next !== null && (((this.endToken.next.next.getReferent() instanceof DecreeReferent) || this.endToken.next.next.isHiphen)) && !this.endToken.next.isNewlineAfter) 
                this.endToken = this.endToken.next;
        }
        if (this.beginToken === this.endToken && this.endToken.next !== null && this.endToken.next.isChar(')')) {
            let ok = true;
            let lev = 0;
            for (let ttt = this.beginToken.previous; ttt !== null; ttt = ttt.previous) {
                if (ttt.isNewlineAfter) 
                    break;
                if (ttt.isChar(')')) 
                    lev++;
                else if (ttt.isChar('(')) {
                    lev--;
                    if (lev < 0) {
                        ok = false;
                        break;
                    }
                }
            }
            if (ok) {
                let tt = this.endToken.next.next;
                if (tt !== null) {
                    if ((tt.getReferent() instanceof DecreeReferent) || PartToken.tryAttach(tt, null, false, false) !== null) 
                        this.endToken = this.endToken.next;
                }
            }
        }
    }
    
    static _new1053(_arg1, _arg2, _arg3) {
        let res = new PartToken.PartValue(_arg1, _arg2);
        res.value = _arg3;
        return res;
    }
    
    static _new1347(_arg1, _arg2, _arg3) {
        let res = new PartToken.PartValue(_arg1, _arg2);
        res.value = _arg3;
        return res;
    }
}


PartToken.static_constructor();

module.exports = PartToken