/*
 * 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 GetTextAttr = require("./../../core/GetTextAttr");
const DecreeTokenItemType = require("./../../decree/internal/DecreeTokenItemType");
const NounPhraseHelper = require("./../../core/NounPhraseHelper");
const DecreeKind = require("./../../decree/DecreeKind");
const MorphNumber = require("./../../../morph/MorphNumber");
const MetaToken = require("./../../MetaToken");
const NounPhraseParseAttr = require("./../../core/NounPhraseParseAttr");
const MiscHelper = require("./../../core/MiscHelper");
const NumberHelper = require("./../../core/NumberHelper");
const PartTokenItemType = require("./../../decree/internal/PartTokenItemType");
const Token = require("./../../Token");
const OrganizationReferent = require("./../../org/OrganizationReferent");
const LanguageHelper = require("./../../../morph/LanguageHelper");
const ParticipantTokenKinds = require("./ParticipantTokenKinds");
const NumberSpellingType = require("./../../NumberSpellingType");
const InstrumentKind = require("./../InstrumentKind");
const BracketParseAttr = require("./../../core/BracketParseAttr");
const MorphBaseInfo = require("./../../../morph/MorphBaseInfo");
const BracketHelper = require("./../../core/BracketHelper");
const DecreeChangeReferent = require("./../../decree/DecreeChangeReferent");
const ComplexNumCompareType = require("./../../core/ComplexNumCompareType");
const TableHelper = require("./../../core/TableHelper");
const ComplexNumComparer = require("./../../core/ComplexNumComparer");
const ComplexNumToken = require("./../../core/ComplexNumToken");
const InstrToken1Types = require("./InstrToken1Types");
const NumberTypes = require("./NumberTypes");
const InstrToken1StdTitleType = require("./InstrToken1StdTitleType");
const ParticipantToken = require("./ParticipantToken");
const DecreePartReferent = require("./../../decree/DecreePartReferent");
const ReferentToken = require("./../../ReferentToken");
const DecreeReferent = require("./../../decree/DecreeReferent");
const NumberToken = require("./../../NumberToken");
const PersonReferent = require("./../../person/PersonReferent");
const TextToken = require("./../../TextToken");
const InstrumentParticipantReferent = require("./../InstrumentParticipantReferent");
const DecreeToken = require("./../../decree/internal/DecreeToken");
const InstrToken = require("./InstrToken");
const PartToken = require("./../../decree/internal/PartToken");

class InstrToken1 extends MetaToken {
    
    constructor(b, e) {
        super(b, e, null);
        this.iRef = null;
        this.isExpired = false;
        this.numbers = new Array();
        this.minNumber = null;
        this.numTyp = NumberTypes.UNDEFINED;
        this.numSuffix = null;
        this.numBeginToken = null;
        this.numEndToken = null;
        this.isNumDoubt = false;
        this.m_Cnum = null;
        this.typ = InstrToken1Types.LINE;
        this.signValues = new Array();
        this.value = null;
        this.allUpper = false;
        this.hasVerb = false;
        this.hasManySpecChars = false;
        this.indentsExpired = false;
        this.titleTyp = InstrToken1StdTitleType.UNDEFINED;
        this.indexNoKeyword = false;
        this.subItems = null;
    }
    
    get lastNumber() {
        if (this.numbers.length < 1) 
            return 0;
        return PartToken.getNumber(this.numbers[this.numbers.length - 1]);
    }
    
    get firstNumber() {
        if (this.numbers.length < 1) 
            return 0;
        return PartToken.getNumber(this.numbers[0]);
    }
    
    get middleNumber() {
        if (this.numbers.length < 2) 
            return 0;
        return PartToken.getNumber(this.numbers[1]);
    }
    
    get lastMinNumber() {
        if (this.minNumber === null) 
            return 0;
        return PartToken.getNumber(this.minNumber);
    }
    
    get cnum() {
        if (this.m_Cnum !== null) 
            return this.m_Cnum;
        if (this.numBeginToken !== null) 
            this.m_Cnum = ComplexNumToken.tryParse(this.numBeginToken, null, false, false);
        else 
            this.m_Cnum = ComplexNumToken.tryParse(this.beginToken, null, false, false);
        return this.m_Cnum;
    }
    
    get hasChanges() {
        for (let t = (this.numEndToken != null ? this.numEndToken : this.beginToken); t !== null; t = t.next) {
            if (t.getReferent() instanceof DecreeChangeReferent) 
                return true;
            if (t.endChar > this.endChar) 
                break;
        }
        return false;
    }
    
    get isPureHiphenLine() {
        for (let tt = this.beginToken; tt !== null && tt.endChar <= this.endChar; tt = tt.next) {
            if (tt.isHiphen || tt.isChar('_')) {
            }
            else 
                return false;
        }
        return true;
    }
    
    get isItalicFont() {
        let st = this.beginToken.kit.sofa.styles;
        if (st === null) 
            return false;
        let yes = 0;
        let no = 0;
        for (let tt = this.beginToken; tt !== null && tt.endChar <= this.endChar; tt = tt.next) {
            let ok = false;
            for (let i = tt.beginChar; i <= tt.endChar; i++) {
                if ((((st[i]) & 2)) !== 0) 
                    ok = true;
            }
            if (ok) 
                yes++;
            else 
                no++;
        }
        if (yes > no) 
            return true;
        return false;
    }
    
    get isBoldFont() {
        let st = this.beginToken.kit.sofa.styles;
        if (st === null) 
            return false;
        let yes = 0;
        let no = 0;
        for (let tt = this.beginToken; tt !== null && tt.endChar <= this.endChar; tt = tt.next) {
            let ok = false;
            for (let i = tt.beginChar; i <= tt.endChar; i++) {
                if ((((st[i]) & 1)) !== 0) 
                    ok = true;
            }
            if (ok) 
                yes++;
            else 
                no++;
        }
        if (yes > no) 
            return true;
        return false;
    }
    
    toString() {
        let res = new StringBuilder();
        res.append(String(this.typ)).append(" ").append(String(this.numTyp)).append(" ");
        if (this.isNumDoubt) 
            res.append("(?) ");
        if (this.indentsExpired) 
            res.append("(Indents Expired) ");
        if (this.isExpired) 
            res.append("(Expired) ");
        if (this.hasChanges) 
            res.append("(HasChanges) ");
        for (let i = 0; i < this.numbers.length; i++) {
            res.append((i > 0 ? "." : "")).append(this.numbers[i]);
        }
        if (this.numSuffix !== null) 
            res.append(" Suf='").append(this.numSuffix).append("'");
        if (this.value !== null) 
            res.append(" '").append(this.value).append("'");
        for (const s of this.signValues) {
            res.append(" [").append(s.toString()).append("]");
        }
        if (this.allUpper) 
            res.append(" AllUpper");
        if (this.hasVerb) 
            res.append(" HasVerb");
        if (this.hasManySpecChars) 
            res.append(" HasManySpecChars");
        if (this.isItalicFont) 
            res.append(" Italic");
        if (this.isBoldFont) 
            res.append(" Bold");
        if (this.titleTyp !== InstrToken1StdTitleType.UNDEFINED) 
            res.append(" ").append(String(this.titleTyp));
        if (this.value === null) 
            res.append(": ").append(this.getSourceText());
        return res.toString();
    }
    
    checkNext(_next, canFollow = false) {
        let n1 = this.cnum;
        if (n1 === null) 
            return false;
        let n2 = _next.cnum;
        if (n2 === null) 
            return false;
        let cmp = new ComplexNumComparer();
        cmp.process(n1, n2);
        if (cmp.typ === ComplexNumCompareType.LESS && cmp.delta === 1 && cmp.rank >= 0.8) 
            return true;
        if (canFollow && cmp.canFollow) 
            return true;
        return false;
    }
    
    static parse(t, ignoreDirectives, cur = null, lev = 0, prev = null, isCitat = false, maxChar = 0, canBeTableCell = false, isInIndex = false) {
        const NumberingHelper = require("./NumberingHelper");
        const FragToken = require("./FragToken");
        if (t === null) 
            return null;
        if (lev > 30) 
            return null;
        if (t.isCharOf("({")) {
            let edt = null;
            let fr = FragToken._createEditions(t);
            if (fr !== null) 
                edt = InstrToken1._new1999(fr.beginToken, fr.endToken, InstrToken1Types.EDITIONS);
            else {
                let t2 = InstrToken1._createEdition(t);
                if (t2 !== null) 
                    edt = InstrToken1._new1999(t, t2, InstrToken1Types.EDITIONS);
            }
            if (edt !== null) {
                if (edt.endToken.next !== null && edt.endToken.next.isChar('.')) 
                    edt.endToken = edt.endToken.next;
                for (let tt23 = edt.beginToken; tt23 !== null && (tt23.endChar < edt.endChar); tt23 = tt23.next) {
                    if (tt23.isValue2("УТРАТИТЬ", "СИЛУ") || tt23.isValue("ИСКЛЮЧИТЬ", null)) 
                        edt.isExpired = true;
                }
                return edt;
            }
        }
        let t0 = t;
        let t00 = null;
        let res = InstrToken1._new2229(t0, t, true);
        for (; t !== null; t = (t === null ? null : t.next)) {
            if (!t.isTableControlChar) 
                break;
            else {
                if (t.isChar(String.fromCharCode(0x1E))) {
                    let isTable = false;
                    let rows = TableHelper.tryParseRows(t, 0, true, false);
                    if (rows !== null && rows.length > 0) {
                        isTable = true;
                        if (rows[0].cells.length > 2 || rows[0].cells.length === 0) {
                        }
                        else if (lev >= 10) 
                            isTable = false;
                        else {
                            let it11 = InstrToken1.parse(rows[0].beginToken, true, null, lev + 1, null, false, maxChar, canBeTableCell, false);
                            if (canBeTableCell) {
                                if (it11 !== null) 
                                    return it11;
                            }
                            if (it11 !== null && it11.numbers.length > 0) {
                                if (it11.typContainerRank > 0 || it11.lastNumber === 1 || it11.titleTyp !== InstrToken1StdTitleType.UNDEFINED) 
                                    isTable = false;
                            }
                        }
                    }
                    if (isTable) {
                        let le = 1;
                        for (t = t.next; t !== null; t = t.next) {
                            if (t.isChar(String.fromCharCode(0x1E))) 
                                le++;
                            else if (t.isChar(String.fromCharCode(0x1F))) {
                                if ((--le) === 0) {
                                    res.endToken = t;
                                    res.hasVerb = true;
                                    res.allUpper = false;
                                    return res;
                                }
                            }
                        }
                    }
                }
                if (t !== null) 
                    res.endToken = t;
            }
        }
        if (t === null) {
            if (t0 instanceof TextToken) 
                return null;
            t = res.endToken;
        }
        let dt = DecreeToken.tryAttach(t, null, false);
        if (dt === null && (((t.getReferent() instanceof PersonReferent) || (t.getReferent() instanceof InstrumentParticipantReferent)))) {
            dt = DecreeToken._new1122(t, t, DecreeTokenItemType.OWNER);
            dt.ref = Utils.as(t, ReferentToken);
        }
        if (dt !== null && dt.endToken.isNewlineAfter) {
            if (dt.typ === DecreeTokenItemType.DATE || dt.typ === DecreeTokenItemType.NUMBER || dt.typ === DecreeTokenItemType.OWNER) {
                res.typ = InstrToken1Types.SIGNS;
                res.signValues.push(dt);
                res.endToken = dt.endToken;
                res.allUpper = false;
                return res;
            }
        }
        if (t.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК") && t.morph._case.isNominative) {
            if (t.next !== null && ((((t.next.isValue("В", null) && !t.next.isNewlineAfter)) || t.next.isChar(':')))) {
            }
            else {
                res.typ = InstrToken1Types.APPENDIX;
                if (t.getReferent() instanceof DecreePartReferent) 
                    t = t.kit.debedToken(t);
                for (t = t.next; t !== null; t = t.next) {
                    if (res.numEndToken === null) {
                        let ttt = Utils.notNull(MiscHelper.checkNumberPrefix(t), t);
                        NumberingHelper.parseNumber(ttt, res, prev);
                        if (res.numEndToken !== null) {
                            res.endToken = (t = res.numEndToken);
                            continue;
                        }
                    }
                    dt = DecreeToken.tryAttach(t, null, false);
                    if (dt !== null) {
                        if (dt.typ === DecreeTokenItemType.NUMBER) {
                            res.numBeginToken = dt.beginToken;
                            res.numEndToken = dt.endToken;
                            if (dt.value !== null) 
                                res.numbers.push(dt.value.toUpperCase());
                        }
                        t = res.endToken = dt.endToken;
                        continue;
                    }
                    if ((t instanceof NumberToken) && ((t.isNewlineAfter || ((t.next !== null && t.next.isChar('.') && t.next.isNewlineAfter))))) {
                        res.numBeginToken = t;
                        res.numbers.push(t.value.toString());
                        if (t.next !== null && t.next.isChar('.')) 
                            t = t.next;
                        res.numEndToken = t;
                        res.endToken = t;
                        continue;
                    }
                    if (((t instanceof NumberToken) && (t.next instanceof TextToken) && t.next.lengthChar === 1) && ((t.next.isNewlineAfter || ((t.next.next !== null && t.next.next.isChar('.')))))) {
                        res.numBeginToken = t;
                        res.numbers.push(t.value.toString());
                        res.numbers.push(t.next.term);
                        res.numTyp = NumberTypes.COMBO;
                        t = t.next;
                        if (t.next !== null && t.next.isChar('.')) 
                            t = t.next;
                        res.numEndToken = t;
                        res.endToken = t;
                        continue;
                    }
                    if (res.numEndToken === null) {
                        NumberingHelper.parseNumber(t, res, prev);
                        if (res.numEndToken !== null) {
                            res.endToken = (t = res.numEndToken);
                            continue;
                        }
                    }
                    if (t.isValue("К", "ДО") && t.next !== null && (t.next.getReferent() instanceof DecreeReferent)) 
                        break;
                    if (t.isValue("УТРАТИТЬ", null)) 
                        break;
                    if (t.chars.isLetter) {
                        let lat = NumberHelper.tryParseRoman(t);
                        if (lat !== null && !t.isValue("C", null) && !t.isValue("С", null)) {
                            res.numBeginToken = t;
                            res.numbers.push(lat.value.toString());
                            res.numTyp = NumberTypes.ROMAN;
                            t = lat.endToken;
                            if (t.next !== null && ((t.next.isChar('.') || t.next.isChar(')')))) 
                                t = t.next;
                            res.numEndToken = t;
                            res.endToken = t;
                            continue;
                        }
                        if (t.lengthChar === 1 && t.chars.isAllUpper && (t instanceof TextToken)) {
                            res.numBeginToken = t;
                            res.numbers.push(t.term);
                            res.numTyp = NumberTypes.LETTER;
                            if (t.next !== null && ((t.next.isChar('.') || t.next.isChar(')')))) 
                                t = t.next;
                            res.numEndToken = t;
                            res.endToken = t;
                            continue;
                        }
                    }
                    if (InstrToken._checkEntered(t) !== null) 
                        break;
                    if (t instanceof TextToken) {
                        if (t.isPureVerb) {
                            res.typ = InstrToken1Types.LINE;
                            break;
                        }
                    }
                    break;
                }
                if (res.typ === InstrToken1Types.APPENDIX && res.numbers.length === 0 && t0.morph.number !== MorphNumber.SINGULAR) 
                    res.typ = InstrToken1Types.LINE;
                if (res.typ !== InstrToken1Types.LINE) 
                    return res;
            }
        }
        if (t.isNewlineBefore) {
            if (t.isValue("МНЕНИЕ", "ДУМКА") || ((t.isValue("ОСОБОЕ", "ОСОБЛИВА") && t.next !== null && t.next.isValue("МНЕНИЕ", "ДУМКА")))) {
                let t1 = t.next;
                if (t1 !== null && t1.isValue("МНЕНИЕ", "ДУМКА")) 
                    t1 = t1.next;
                let ok = false;
                if (t1 !== null) {
                    if (t1.isNewlineBefore || (t1.getReferent() instanceof PersonReferent)) 
                        ok = true;
                }
                if (ok) {
                    res.typ = InstrToken1Types.APPENDIX;
                    res.endToken = t1.previous;
                    return res;
                }
            }
            if ((t.getReferent() instanceof DecreeReferent) && t.getReferent().kind === DecreeKind.PUBLISHER) 
                res.typ = InstrToken1Types.APPROVED;
            if ((t instanceof TextToken) && t.term === "ПРИМЕЧАНИЯ") {
                if ((t.previous !== null && t.previous.isTableControlChar && t.next !== null) && t.next.isTableControlChar) {
                }
                else if (t.isNewlineAfter) {
                    res.typ = InstrToken1Types.NOTICE;
                    return res;
                }
                if (t.next !== null && t.next.isChar(':') && (t.next.next instanceof NumberToken)) {
                    res.typ = InstrToken1Types.NOTICE;
                    res.endToken = t.next;
                    return res;
                }
            }
        }
        if (t.isValue("КОНСУЛЬТАНТПЛЮС", null) || t.isValue("ГАРАНТ", null) || ((t.isValue("ИНФОРМАЦИЯ", null) && t.isNewlineBefore))) {
            let t1 = t.next;
            let ok = false;
            if (t.isValue("ИНФОРМАЦИЯ", null)) {
                if (((t.next !== null && t.next.isValue("О", null) && t.next.next !== null) && t.next.next.isValue("ИЗМЕНЕНИЕ", null) && t.next.next.next !== null) && t.next.next.next.isChar(':')) {
                    t1 = t.next.next.next.next;
                    ok = true;
                }
            }
            else if (t1 !== null && t1.isChar(':')) {
                t1 = t1.next;
                ok = true;
            }
            if (t1 !== null && ((t1.isValue("ПРИМЕЧАНИЕ", null) || ok))) {
                if (t1.next !== null && t1.next.isChar('.')) 
                    t1 = t1.next;
                let re = InstrToken1._new1999(t, t1, InstrToken1Types.COMMENT);
                let hiph = false;
                for (t1 = t1.next; t1 !== null; t1 = t1.next) {
                    re.endToken = t1;
                    if (!t1.isNewlineAfter) 
                        continue;
                    if (t1.next === null) 
                        break;
                    if (t1.next.isValue("СМ", null) || t1.next.isValue("ПУНКТ", null)) 
                        continue;
                    if (!t1.next.isHiphen) 
                        hiph = false;
                    else if (t1.next.isHiphen) {
                        if (t1.isChar(':')) 
                            hiph = true;
                        if (hiph) 
                            continue;
                    }
                    break;
                }
                return re;
            }
        }
        let checkComment = 0;
        for (let ttt = t; ttt !== null; ttt = ttt.next) {
            if (((ttt.isNewlineBefore || ttt.isTableControlChar)) && ttt !== t) 
                break;
            if (ttt.morph._class.isPreposition) 
                continue;
            let npt = NounPhraseHelper.tryParse(ttt, NounPhraseParseAttr.NO, 0, null);
            if (npt === null) 
                break;
            if (npt.noun.isValue("ПРИМЕНЕНИЕ", "ЗАСТОСУВАННЯ") || npt.noun.isValue("ВОПРОС", "ПИТАННЯ")) {
                checkComment++;
                ttt = npt.endToken;
            }
            else 
                break;
        }
        if (checkComment > 0 || t.isValue("О", "ПРО")) {
            let t1 = null;
            let ok = false;
            let dref = null;
            for (let ttt = t.next; ttt !== null; ttt = ttt.next) {
                t1 = ttt;
                if (t1.isValue("СМ", null) && t1.next !== null && t1.next.isChar('.')) {
                    if (checkComment > 0) 
                        ok = true;
                    if ((t1.next.next instanceof ReferentToken) && (((t1.next.next.getReferent() instanceof DecreeReferent) || (t1.next.next.getReferent() instanceof DecreePartReferent)))) {
                        ok = true;
                        dref = Utils.as(t1.next.next.getReferent(), DecreeReferent);
                    }
                }
                if (ttt.isNewlineAfter) 
                    break;
            }
            if (ok) {
                let cmt = InstrToken1._new1999(t, t1, InstrToken1Types.COMMENT);
                if (dref !== null && t1.next !== null && t1.next.getReferent() === dref) {
                    if (t1.next.next !== null && t1.next.next.isValue("УТРАТИТЬ", "ВТРАТИТИ")) {
                        for (let ttt = t1.next.next; ttt !== null; ttt = ttt.next) {
                            if (ttt.isNewlineBefore) 
                                break;
                            cmt.endToken = ttt;
                        }
                    }
                }
                return cmt;
            }
        }
        let tt = InstrToken._checkApproved(t);
        if (tt !== null) {
            res.endToken = tt;
            if (tt.next !== null && (tt.next.getReferent() instanceof DecreeReferent)) {
                res.typ = InstrToken1Types.APPROVED;
                res.endToken = tt.next;
                return res;
            }
            let tt1 = tt;
            if (tt1.isChar(':') && tt1.next !== null) 
                tt1 = tt1.next;
            if ((tt1.getReferent() instanceof PersonReferent) || (tt1.getReferent() instanceof InstrumentParticipantReferent)) {
                res.typ = InstrToken1Types.APPROVED;
                res.endToken = tt1;
                return res;
            }
            let dt1 = DecreeToken.tryAttach(tt.next, null, false);
            if (dt1 !== null && dt1.typ === DecreeTokenItemType.TYP) {
                res.typ = InstrToken1Types.APPROVED;
                let err = 0;
                for (let ttt = dt1.endToken.next; ttt !== null; ttt = ttt.next) {
                    if (DecreeToken.isKeyword(ttt, false) !== null) 
                        break;
                    dt1 = DecreeToken.tryAttach(ttt, null, false);
                    if (dt1 !== null) {
                        if (dt1.typ === DecreeTokenItemType.TYP || dt1.typ === DecreeTokenItemType.NAME) 
                            break;
                        res.endToken = (ttt = dt1.endToken);
                        continue;
                    }
                    if (ttt.morph._class.isPreposition || ttt.morph._class.isConjunction) 
                        continue;
                    if (ttt.whitespacesBeforeCount > 15) 
                        break;
                    if ((++err) > 10) 
                        break;
                }
                return res;
            }
        }
        let val = null;
        let wrapval2238 = new RefOutArgWrapper();
        let tt2 = InstrToken1._checkDirective(t, wrapval2238);
        val = wrapval2238.value;
        if (tt2 !== null) {
            if (tt2.isNewlineAfter || ((tt2.next !== null && ((tt2.next.isCharOf(":") || ((tt2.next.isChar('.') && tt2 !== t)))) && ((tt2.next.isNewlineAfter || t.chars.isAllUpper))))) 
                return InstrToken1._new2233(t, (tt2.isNewlineAfter ? tt2 : tt2.next), InstrToken1Types.DIRECTIVE, val);
        }
        if ((lev < 3) && t !== null) {
            if ((t.isValue("СОДЕРЖИМОЕ", "ВМІСТ") || t.isValue("СОДЕРЖАНИЕ", "ЗМІСТ") || t.isValue("ОГЛАВЛЕНИЕ", "ЗМІСТ")) || ((t.isValue("СПИСОК", null) && t.next !== null && t.next.isValue("РАЗДЕЛ", null)))) {
                let t11 = t.next;
                if (t.isValue("СПИСОК", null)) 
                    t11 = t11.next;
                if (t11 !== null && !t11.isNewlineAfter) {
                    let npt = NounPhraseHelper.tryParse(t11, NounPhraseParseAttr.NO, 0, null);
                    if (npt !== null && npt.morph._case.isGenitive) 
                        t11 = npt.endToken.next;
                }
                if (t11 !== null && t11.isCharOf(":.;")) 
                    t11 = t11.next;
                if (t11 !== null && t11.isNewlineBefore) {
                    let first = InstrToken1.parse(t11, ignoreDirectives, null, lev + 1, null, false, 0, false, true);
                    if (first !== null && (first.lengthChar < 4)) 
                        first = InstrToken1.parse(first.endToken.next, ignoreDirectives, null, lev + 1, null, false, 0, false, false);
                    let fstr = MiscHelper.getTextValueOfMetaToken(first, GetTextAttr.NO);
                    if (first !== null) {
                        let cou = 0;
                        let itprev = null;
                        let hasApp = false;
                        for (tt = first.endToken.next; tt !== null; tt = tt.next) {
                            if (tt.isValue("ПРИЛОЖЕНИЕ", null)) {
                            }
                            if (tt.isNewlineBefore) {
                                if ((++cou) > 400) 
                                    break;
                            }
                            let it = InstrToken1.parse(tt, ignoreDirectives, null, lev + 1, null, false, 0, false, true);
                            if (it === null) 
                                break;
                            let ok = false;
                            if (first.numbers.length === 1 && it.numbers.length === 1) {
                                if (it.typ === InstrToken1Types.APPENDIX && first.typ !== InstrToken1Types.APPENDIX) {
                                }
                                else if (first.numbers[0] === it.numbers[0]) 
                                    ok = true;
                            }
                            else if (first.value !== null && it.value !== null && first.value.startsWith(it.value)) 
                                ok = true;
                            else {
                                let str = MiscHelper.getTextValueOfMetaToken(it, GetTextAttr.NO);
                                if (str === fstr) 
                                    ok = true;
                            }
                            if ((ok && first.typ !== InstrToken1Types.APPENDIX && itprev !== null) && itprev.typ === InstrToken1Types.APPENDIX) {
                                let it2 = InstrToken1.parse(it.endToken.next, ignoreDirectives, null, lev + 1, null, false, 0, false, true);
                                if (it2 !== null && it2.typ === InstrToken1Types.APPENDIX) 
                                    ok = false;
                            }
                            if (!ok && cou > 4 && first.numbers.length > 0) {
                                if (it.numbers.length === 1 && it.numbers[0] === "1") {
                                    if (it.titleTyp === InstrToken1StdTitleType.OTHERS) 
                                        ok = true;
                                }
                            }
                            if (ok) {
                                if (t.previous === null) 
                                    return null;
                                res.endToken = tt.previous;
                                res.typ = InstrToken1Types.INDEX;
                                return res;
                            }
                            if (it.typ === InstrToken1Types.APPENDIX) 
                                hasApp = true;
                            tt = it.endToken;
                            itprev = it;
                        }
                        cou = 0;
                        for (tt = first.beginToken; tt !== null && tt.endChar <= first.endChar; tt = tt.next) {
                            if (tt.isTableControlChar) 
                                cou++;
                        }
                        if (cou > 5) {
                            res.endToken = first.endToken;
                            res.typ = InstrToken1Types.INDEX;
                            return res;
                        }
                    }
                }
            }
        }
        let tt01 = (t !== null && t.isValue("ПОЛОЖЕНИЕ", "ПОЛОЖЕННЯ") ? t.next : t);
        let pts = PartToken.tryAttachList(tt01, false, 40);
        tt = null;
        if ((pts !== null && pts.length > 0 && pts[0].typ !== PartTokenItemType.PREFIX) && pts[0].values.length > 0 && !pts[0].isNewlineAfter) 
            tt = pts[pts.length - 1].endToken.next;
        if ((tt01 instanceof ReferentToken) && !tt01.isNewlineAfter) {
            if ((tt01.getReferent() instanceof DecreePartReferent) || (tt01.getReferent() instanceof DecreeReferent)) 
                tt = tt01.next;
        }
        if (tt !== null) {
            let ok1 = false;
            if (tt.isCharOf(".)]")) {
            }
            else 
                for (; tt !== null; tt = tt.next) {
                    if (tt.isValue("ПРИМЕНЯТЬСЯ", "ЗАСТОСОВУВАТИСЯ")) 
                        ok1 = true;
                    if ((tt.isValue("ВСТУПАТЬ", "ВСТУПАТИ") && tt.next !== null && tt.next.next !== null) && tt.next.next.isValue("СИЛА", "ЧИННІСТЬ")) 
                        ok1 = true;
                    if (tt.isNewlineAfter) {
                        if (ok1) 
                            return InstrToken1._new1999(t, tt, InstrToken1Types.COMMENT);
                        break;
                    }
                }
        }
        let multiNums = false;
        if (t !== null && (((t.isNewlineBefore || isInIndex || isCitat) || ((t.previous !== null && t.previous.isTableControlChar)))) && !t.isTableControlChar) {
            let ok = true;
            if (t.next !== null && t.chars.isAllLower) {
                if (!t.morph._case.isNominative) 
                    ok = false;
                else if (t.next !== null && t.next.isCharOf(",:;.")) 
                    ok = false;
                else {
                    let npt = NounPhraseHelper.tryParse(t.previous, NounPhraseParseAttr.NO, 0, null);
                    if (npt !== null && npt.endToken === t) 
                        ok = false;
                }
            }
            if (ok && (t instanceof TextToken)) {
                ok = false;
                let s = t.term;
                if (s === "ГЛАВА" || s === "ГОЛОВА") {
                    res.typ = InstrToken1Types.CHAPTER;
                    t = t.next;
                    ok = true;
                }
                else if (s === "ГЛАВЫ") {
                    res.typ = InstrToken1Types.CHAPTER;
                    t = t.next;
                    ok = true;
                    multiNums = true;
                }
                else if (s === "СТАТЬЯ" || s === "СТАТТЯ") {
                    res.typ = InstrToken1Types.CLAUSE;
                    t = t.next;
                    ok = true;
                }
                else if (s === "СТАТЬИ") {
                    res.typ = InstrToken1Types.CLAUSE;
                    t = t.next;
                    ok = true;
                    multiNums = true;
                }
                else if (s === "РАЗДЕЛ" || s === "РОЗДІЛ") {
                    res.typ = InstrToken1Types.SECTION;
                    t = t.next;
                    ok = true;
                }
                else if (s === "РАЗДЕЛЫ") {
                    res.typ = InstrToken1Types.SECTION;
                    t = t.next;
                    ok = true;
                    multiNums = true;
                }
                else if (s === "ЧАСТЬ" || s === "ЧАСТИНА") {
                    res.typ = InstrToken1Types.DOCPART;
                    t = t.next;
                    ok = true;
                }
                else if (s === "ЧАСТИ") {
                    res.typ = InstrToken1Types.DOCPART;
                    t = t.next;
                    ok = true;
                    multiNums = true;
                }
                else if (s === "ПОДРАЗДЕЛ" || s === "ПІДРОЗДІЛ") {
                    res.typ = InstrToken1Types.SUBSECTION;
                    t = t.next;
                    ok = true;
                }
                else if (s === "ПОДРАЗДЕЛЫ") {
                    res.typ = InstrToken1Types.SUBSECTION;
                    t = t.next;
                    ok = true;
                    multiNums = true;
                }
                else if ((s === "ПРИМЕЧАНИЕ" || s === "ПРИМІТКА" || s === "ПРИМЕЧАНИЯ") || s === "ПРИМІТКИ") {
                    if ((t.previous !== null && t.previous.isTableControlChar && t.next !== null) && t.next.isTableControlChar) {
                    }
                    else {
                        res.typ = InstrToken1Types.NOTICE;
                        t = t.next;
                        if (t !== null && t.isCharOf(".:")) {
                            res.endToken = t;
                            t = t.next;
                        }
                        ok = true;
                    }
                }
                else if (s === "§" || s === "ПАРАГРАФ") {
                    res.typ = InstrToken1Types.PARAGRAPH;
                    t = t.next;
                    ok = true;
                }
                else if (s === "ПАРАГРАФЫ") {
                    res.typ = InstrToken1Types.PARAGRAPH;
                    t = t.next;
                    ok = true;
                    multiNums = true;
                }
                else if (s === "ТАБЛИЦА" || s === "НОРМА") {
                    res.typ = InstrToken1Types.TABLE;
                    t = t.next;
                    ok = true;
                }
                else if (s === "ФОРМА") {
                    res.typ = InstrToken1Types.FORM;
                    t = t.next;
                    ok = true;
                }
                if (ok) {
                    let ttt = t;
                    if (ttt !== null && (ttt instanceof NumberToken)) 
                        ttt = ttt.next;
                    if (ttt !== null && !ttt.isNewlineBefore) {
                        if (PartToken.tryAttach(ttt, null, false, false) !== null) 
                            res.typ = InstrToken1Types.LINE;
                        else if (InstrToken._checkEntered(ttt) !== null) {
                            res.typ = InstrToken1Types.EDITIONS;
                            t00 = res.beginToken;
                        }
                        else if (res.beginToken.chars.isAllLower) {
                            if (res.beginToken.newlinesBeforeCount > 3) {
                            }
                            else 
                                res.typ = InstrToken1Types.LINE;
                        }
                    }
                }
            }
        }
        let num = res.typ !== InstrToken1Types.EDITIONS;
        let hasLetters = false;
        let isApp = cur !== null && ((cur.kind === InstrumentKind.APPENDIX || cur.kind === InstrumentKind.INTERNALDOCUMENT));
        for (; t !== null; t = t.next) {
            if (maxChar > 0 && t.beginChar > maxChar) 
                break;
            if (t.isNewlineBefore && t !== res.beginToken) {
                if (res.numbers.length === 2) {
                    if (res.numbers[0] === "3" && res.numbers[1] === "4") {
                    }
                }
                let isNewLine = true;
                if ((t.newlinesBeforeCount === 1 && t.previous !== null && t.previous.chars.isLetter) && lev === 0) {
                    let npt = NounPhraseHelper.tryParse(t.previous, NounPhraseParseAttr.NO, 0, null);
                    if (npt !== null && npt.endChar > t.beginChar) 
                        isNewLine = false;
                    else if (t.previous.getMorphClassInDictionary().isAdjective) {
                        npt = NounPhraseHelper.tryParse(t, NounPhraseParseAttr.NO, 0, null);
                        if (npt !== null && npt.morph.checkAccord(t.previous.morph, false, false)) 
                            isNewLine = false;
                    }
                    if (!isNewLine) {
                        let tes = InstrToken1.parse(t, true, cur, lev + 1, null, false, 0, false, false);
                        if (tes !== null && tes.numbers.length > 0) 
                            break;
                    }
                    else if (res.numbers.length > 0) {
                        let tes = InstrToken1.parse(t, true, cur, lev + 1, null, false, 0, false, false);
                        if (tes !== null && tes.numbers.length > 0) 
                            break;
                    }
                }
                if (isNewLine && t.chars.isLetter) {
                    if (!MiscHelper.canBeStartOfSentence(t)) {
                        let nnn = ComplexNumToken.tryParse(t, null, false, false);
                        if (nnn !== null) {
                        }
                        else if (t.previous !== null && t.previous.isCharOf(":;.]")) {
                        }
                        else if ((t.previous !== null && t.previous.isComma && t.previous.previous !== null) && t.previous.previous.isChar(']')) {
                        }
                        else if ((t.isValue("НЕТ", null) || t.isValue("НЕ", null) || t.isValue("ОТСУТСТВОВАТЬ", null)) || t.isChar('[') || t.isValue("ГДЕ", null)) {
                        }
                        else if ((res.numbers.length > 0 && t.previous !== null && t.previous.chars.isAllUpper) && !t.chars.isAllUpper) {
                        }
                        else if (t.previous !== null && ((t.previous.isValue("ИЛИ", null) || t.previous.isCommaAnd)) && res.numbers.length > 0) {
                            let vvv = InstrToken1.parse(t, true, cur, lev + 1, null, false, 0, false, false);
                            if (vvv !== null && vvv.numbers.length > 0) 
                                isNewLine = true;
                        }
                        else 
                            isNewLine = false;
                    }
                }
                if (t.isChar('(')) {
                    let br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                    if (br !== null && br.lengthChar > 10) {
                        let nnn = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
                        if (nnn !== null && nnn.typ === InstrToken1Types.EDITIONS) {
                        }
                        else 
                            isNewLine = false;
                    }
                }
                if (MiscHelper.checkFalseNewline(t)) 
                    continue;
                if (isNewLine) 
                    break;
                else {
                }
            }
            if (t === res.beginToken || ((res.numEndToken !== null && t === res.numEndToken.next))) {
                let tte = null;
                let pp = PartToken.tryAttach(t, null, false, true);
                if (pp !== null && pp.endToken.next !== null) 
                    tte = pp.endToken.next;
                if (tte !== null) {
                    if (tte.isValue2("УТРАТИТЬ", "СИЛУ")) 
                        res.isExpired = true;
                    else if (tte.isValue("ИСКЛЮЧИТЬ", null) || tte.isValue("ИСКЛЮЧАТЬ", null)) 
                        res.isExpired = true;
                }
            }
            if (t.isTableControlChar && t !== res.beginToken) {
                if (canBeTableCell || t.isChar(String.fromCharCode(0x1E)) || t.isChar(String.fromCharCode(0x1F))) 
                    break;
                if (num && res.numbers.length > 0) 
                    num = false;
                else if (t.previous === res.numEndToken) {
                }
                else if (!t.isNewlineAfter) 
                    continue;
                else 
                    break;
            }
            if (isInIndex && !t.isNewlineBefore && !t.chars.isAllLower) {
                let _typ = PartToken.tryAttach(t, null, false, false);
                if (_typ !== null) {
                    if (((_typ.typ === PartTokenItemType.CHAPTER || _typ.typ === PartTokenItemType.CLAUSE || _typ.typ === PartTokenItemType.SECTION) || _typ.typ === PartTokenItemType.SUBSECTION || _typ.typ === PartTokenItemType.PARAGRAPH) || _typ.typ === PartTokenItemType.APPENDIX) {
                        if (_typ.values.length === 1) 
                            break;
                    }
                }
                let dp = Utils.as(t.getReferent(), DecreePartReferent);
                if (dp !== null) {
                    if (((dp.getSlotValue(DecreePartReferent.ATTR_CHAPTER) !== null || dp.getSlotValue(DecreePartReferent.ATTR_CLAUSE) !== null || dp.getSlotValue(DecreePartReferent.ATTR_SECTION) !== null) || dp.getSlotValue(DecreePartReferent.ATTR_SUBSECTION) !== null || dp.getSlotValue(DecreePartReferent.ATTR_PARAGRAPH) !== null) || dp.getSlotValue(DecreePartReferent.ATTR_APPENDIX) !== null) {
                        t = t.kit.debedToken(t);
                        break;
                    }
                }
            }
            if ((t.isChar('[') && t === t0 && (t.next instanceof NumberToken)) && t.next.next !== null && t.next.next.isChar(']')) {
                num = false;
                res.numbers.push(t.next.value.toString());
                res.numTyp = NumberTypes.DIGIT;
                res.numSuffix = "]";
                res.numBeginToken = t;
                res.numEndToken = t.next.next;
                t = res.numEndToken;
                continue;
            }
            if (t.isChar('(')) {
                num = false;
                if (FragToken._createEditions(t) !== null) 
                    break;
                if (InstrToken1._createEdition(t) !== null) 
                    break;
                let br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                if (br !== null) {
                    if (t === res.beginToken) {
                        let lat = NumberHelper.tryParseRoman(t.next);
                        if (lat !== null && lat.endToken.next === br.endToken) {
                            res.numbers.push(lat.value.toString());
                            res.numSuffix = ")";
                            res.numBeginToken = t;
                            res.numEndToken = br.endToken;
                            res.numTyp = (lat.typ === NumberSpellingType.ROMAN ? NumberTypes.ROMAN : NumberTypes.DIGIT);
                        }
                        else if (((t === t0 && t.isNewlineBefore && br.lengthChar === 3) && br.endToken === t.next.next && (t.next instanceof TextToken)) && t.next.chars.isLatinLetter) {
                            res.numBeginToken = t;
                            res.numTyp = NumberTypes.LETTER;
                            res.numbers.push(t.next.term);
                            res.endToken = (res.numEndToken = t.next.next);
                        }
                    }
                    t = res.endToken = br.endToken;
                    continue;
                }
            }
            if (num) {
                if (res.typ === InstrToken1Types.TABLE) {
                    let ttt = MiscHelper.checkNumberPrefix(t);
                    if (ttt !== null) 
                        t = ttt;
                }
                NumberingHelper.parseNumber(t, res, prev);
                num = false;
                if (res.numbers.length > 0) {
                }
                if (res.typ === InstrToken1Types.NOTICE) 
                    break;
                if (res.typ === InstrToken1Types.FORM || res.typ === InstrToken1Types.TABLE) {
                    if (res.numbers.length === 0) {
                        if (!t.isChar('.')) 
                            res.typ = InstrToken1Types.LINE;
                        else {
                        }
                    }
                }
                if (multiNums && res.minNumber === null) {
                    res.numbers.splice(0, res.numbers.length);
                    res.typ = InstrToken1Types.LINE;
                    res.numEndToken = (res.numBeginToken = null);
                }
                if (res.numEndToken !== null && res.numEndToken.endChar >= t.endChar) {
                    t = res.numEndToken;
                    if (res.numEndToken.isNewlineAfter && res.beginToken === res.numBeginToken) {
                        res.numbers.splice(0, res.numbers.length);
                        res.numBeginToken = null;
                        res.numEndToken = null;
                        res.numSuffix = null;
                        res.numTyp = NumberTypes.UNDEFINED;
                        break;
                    }
                    continue;
                }
            }
            if (res.numbers.length === 0) 
                num = false;
            if ((t instanceof TextToken) && t.chars.isLetter) {
                hasLetters = true;
                if (t00 === null) 
                    t00 = t;
                num = false;
                if (t.chars.isCapitalUpper && res.lengthChar > 20) {
                    if (t.isValue("РУКОВОДСТВУЯСЬ", null)) {
                        if (MiscHelper.canBeStartOfSentence(t) || t.previous.isComma) 
                            break;
                    }
                    else if (t.isValue("НА", null) && t.next !== null && t.next.isValue("ОСНОВАНИЕ", null)) {
                        let ttt = InstrToken1.parse(t, true, null, lev + 1, null, false, 0, false, false);
                        if (ttt !== null && ttt.toString().toUpperCase().includes("РУКОВОДСТВУЯСЬ")) {
                            if (MiscHelper.canBeStartOfSentence(t)) 
                                break;
                        }
                    }
                }
                if (!t.chars.isAllUpper) 
                    res.allUpper = false;
                if (t.isPureVerb) {
                    if (t.previous !== null && t.previous.isValue("КОТОРЫЙ", null)) {
                    }
                    else if (t.chars.isCyrillicLetter) {
                        let npt = NounPhraseHelper.tryParse((t.morph._class.isPreposition ? t.next : t), NounPhraseParseAttr.NO, 0, null);
                        if (npt !== null) {
                        }
                        else 
                            res.hasVerb = true;
                    }
                }
            }
            else if (t instanceof ReferentToken) {
                hasLetters = true;
                if (t00 === null) 
                    t00 = t;
                num = false;
                if (t.getReferent() instanceof DecreeChangeReferent) {
                    res.hasVerb = true;
                    res.allUpper = false;
                }
                if (t.getReferent() instanceof InstrumentParticipantReferent) {
                    if (!t.chars.isAllUpper) 
                        res.allUpper = false;
                }
            }
            if (t !== res.beginToken && InstrToken1._isFirstLine(t)) 
                break;
            let tmp = null;
            let wraptmp2235 = new RefOutArgWrapper();
            tt2 = InstrToken1._checkDirective(t, wraptmp2235);
            tmp = wraptmp2235.value;
            if (tt2 !== null && res.numbers.length === 0) {
                if (tt2.next !== null && tt2.next.isCharOf(":.") && tt2.next.isNewlineAfter) {
                    if (ignoreDirectives && !t.isNewlineBefore) 
                        t = tt2;
                    else 
                        break;
                }
            }
            res.endToken = t;
        }
        if (res.typContainerRank > 0 && t00 !== null) {
            if (t00.chars.isAllLower) {
                res.typ = InstrToken1Types.LINE;
                res.numbers.splice(0, res.numbers.length);
                res.numTyp = NumberTypes.UNDEFINED;
            }
        }
        if (t00 !== null) {
            let len = res.endChar - t00.beginChar;
            if (len < 1000) {
                res.value = MiscHelper.getTextValue(t00, res.endToken, GetTextAttr.NO);
                if (LanguageHelper.endsWith(res.value, ".")) 
                    res.value = res.value.substring(0, 0 + res.value.length - 1);
            }
        }
        if (!hasLetters) 
            res.allUpper = false;
        if (res.numTyp !== NumberTypes.UNDEFINED && res.beginToken === res.numBeginToken && res.endToken === res.numEndToken) {
            if (res.endToken.next !== null && res.endToken.next.isChar('(')) {
            }
            else {
                let ok = false;
                if (prev !== null) {
                    if (NumberingHelper.calcDelta(prev, res, true) === 1) 
                        ok = true;
                }
                if (!ok) {
                    let res1 = InstrToken1.parse(res.endToken.next, true, null, lev + 1, null, false, 0, false, false);
                    if (res1 !== null) {
                        if (NumberingHelper.calcDelta(res, res1, true) === 1) 
                            ok = true;
                    }
                }
                if (!ok) {
                    res.numTyp = NumberTypes.UNDEFINED;
                    res.numbers.splice(0, res.numbers.length);
                }
            }
        }
        if (res.typ === InstrToken1Types.APPENDIX || res.typContainerRank > 0) {
            if (res.typ === InstrToken1Types.CLAUSE && res.lastNumber === 17) {
            }
            tt = ((res.numEndToken != null ? res.numEndToken : res.beginToken)).next;
            if (tt !== null) {
                for (; tt !== null; tt = tt.next) {
                    if (!tt.isCharOf(".(-")) 
                        break;
                }
                let ttt = InstrToken._checkEntered(tt);
                if (ttt !== null) {
                    if (tt.isValue("УТРАТИТЬ", null) && tt.previous !== null && tt.previous.isCharOf("(.-")) {
                        res.value = null;
                        res.isExpired = true;
                    }
                    else if (res.typ !== InstrToken1Types.CLAUSE && res.typ !== InstrToken1Types.CHAPTER && res.typ !== InstrToken1Types.SECTION) {
                        res.typ = InstrToken1Types.EDITIONS;
                        res.numbers.splice(0, res.numbers.length);
                        res.numTyp = NumberTypes.UNDEFINED;
                        res.value = null;
                    }
                }
            }
        }
        if (res.typ === InstrToken1Types.DOCPART) {
        }
        let badNumber = false;
        if ((res.typContainerRank > 0 && res.numTyp !== NumberTypes.UNDEFINED && res.numEndToken !== null) && !res.numEndToken.isNewlineAfter && res.numEndToken.next !== null) {
            let t1 = res.numEndToken.next;
            let bad = false;
            if (t1.chars.isAllLower) 
                bad = true;
            if (bad) 
                badNumber = true;
        }
        if (res.numTyp !== NumberTypes.UNDEFINED && !isCitat) {
            if (res.isNewlineBefore || isInIndex) {
            }
            else if (res.beginToken.previous !== null && res.beginToken.previous.isTableControlChar) {
            }
            else if (prev !== null && prev.typ === InstrToken1Types.NOTICE) {
            }
            else 
                badNumber = true;
            if (res.numSuffix === "-") 
                badNumber = true;
        }
        if (res.typ === InstrToken1Types.LINE && res.numbers.length > 0 && isCitat) {
            let tt0 = res.beginToken.previous;
            if (BracketHelper.canBeStartOfSequence(tt0, true, true)) 
                tt0 = tt0.previous;
            if (tt0 !== null) 
                tt0 = tt0.previous;
            for (; tt0 !== null; tt0 = tt0.previous) {
                if (tt0.isValue("ГЛАВА", "ГОЛОВА")) 
                    res.typ = InstrToken1Types.CHAPTER;
                else if (tt0.isValue("СТАТЬЯ", "СТАТТЯ")) 
                    res.typ = InstrToken1Types.CLAUSE;
                else if (tt0.isValue("РАЗДЕЛ", "РОЗДІЛ")) 
                    res.typ = InstrToken1Types.SECTION;
                else if (tt0.isValue("ЧАСТЬ", "ЧАСТИНА")) 
                    res.typ = InstrToken1Types.DOCPART;
                else if (tt0.isValue("ПОДРАЗДЕЛ", "ПІДРОЗДІЛ")) 
                    res.typ = InstrToken1Types.SUBSECTION;
                else if (tt0.isValue("ПАРАГРАФ", null)) 
                    res.typ = InstrToken1Types.PARAGRAPH;
                else if (tt0.isValue("ПРИМЕЧАНИЕ", "ПРИМІТКА")) 
                    res.typ = InstrToken1Types.NOTICE;
                if (tt0.isNewlineBefore) 
                    break;
            }
        }
        if (badNumber) {
            res.typ = InstrToken1Types.LINE;
            res.numTyp = NumberTypes.UNDEFINED;
            res.value = null;
            res.numbers.splice(0, res.numbers.length);
            res.numBeginToken = (res.numEndToken = null);
        }
        if ((res.typ === InstrToken1Types.SECTION || res.typ === InstrToken1Types.PARAGRAPH || res.typ === InstrToken1Types.CHAPTER) || res.typ === InstrToken1Types.CLAUSE) {
            if (res.numbers.length === 0) 
                res.typ = InstrToken1Types.LINE;
        }
        if (res.endToken.isChar('>') && res.beginToken.isValue("ПУТЕВОДИТЕЛЬ", null)) {
            res.typ = InstrToken1Types.COMMENT;
            for (let ttt = res.endToken.next; ttt !== null; ttt = ttt.next) {
                let li2 = InstrToken1.parse(ttt, true, null, lev + 1, null, false, 0, false, false);
                if (li2 !== null && li2.endToken.isChar('>')) {
                    res.endToken = (ttt = li2.endToken);
                    continue;
                }
                break;
            }
            return res;
        }
        if (res.typ === InstrToken1Types.LINE) {
            if (res.numTyp !== NumberTypes.UNDEFINED) {
                let ttt = res.beginToken.previous;
                if (ttt instanceof TextToken) {
                    if (ttt.isValue("ПУНКТ", null)) {
                        res.numTyp = NumberTypes.UNDEFINED;
                        res.value = null;
                        res.numbers.splice(0, res.numbers.length);
                    }
                }
                for (const nn of res.numbers) {
                    let vv = 0;
                    let wrapvv2236 = new RefOutArgWrapper();
                    let inoutres2237 = Utils.tryParseInt(nn, wrapvv2236);
                    vv = wrapvv2236.value;
                    if (inoutres2237) {
                        if (vv > 1000 && res.numBeginToken === res.beginToken) {
                            res.numTyp = NumberTypes.UNDEFINED;
                            res.value = null;
                            res.numbers.splice(0, res.numbers.length);
                            break;
                        }
                    }
                }
            }
            if (InstrToken1._isFirstLine(res.beginToken)) 
                res.typ = InstrToken1Types.FIRSTLINE;
            if (res.numTyp === NumberTypes.DIGIT) {
                if (res.numSuffix === null) 
                    res.isNumDoubt = true;
            }
            if (res.numbers.length === 0) {
                let pt = PartToken.tryAttach(res.beginToken, null, false, false);
                if (pt !== null && pt.typ !== PartTokenItemType.PREFIX) {
                    tt = pt.endToken.next;
                    if (tt !== null && ((tt.isCharOf(".") || tt.isHiphen))) 
                        tt = tt.next;
                    tt = InstrToken._checkEntered(tt);
                    if (tt !== null) {
                        res.typ = InstrToken1Types.EDITIONS;
                        if (tt.previous !== null) 
                            res.isExpired = tt.previous.isValue("УТРАТИТЬ", "ВТРАТИТИ");
                    }
                    if (pt.typ === PartTokenItemType.INDENTION && res.isExpired && ((pt.values.length === 1 || pt.values.length === 2))) {
                        res.indentsExpired = true;
                        if (pt.values.length === 1) 
                            res.numbers.push(pt.values[0].value);
                        else if (pt.values[0].intValue > 0 && pt.values[1].intValue > pt.values[0].intValue) {
                            for (let nnn = pt.values[0].intValue; nnn <= pt.values[1].intValue; nnn++) {
                                res.numbers.push(nnn.toString());
                            }
                        }
                    }
                }
                else {
                    tt = InstrToken._checkEntered(res.beginToken);
                    if (tt !== null && tt.next !== null && (tt.next.getReferent() instanceof DecreeReferent)) 
                        res.typ = InstrToken1Types.EDITIONS;
                    else if (res.beginToken.isValue("АБЗАЦ", null) && res.beginToken.next !== null && res.beginToken.next.isValue("УТРАТИТЬ", "ВТРАТИТИ")) 
                        res.isExpired = true;
                }
            }
        }
        if (res.typ === InstrToken1Types.LINE && res.numTyp === NumberTypes.ROMAN) {
            let res1 = InstrToken1.parse(res.endToken.next, true, cur, lev + 1, null, false, 0, false, false);
            if (res1 !== null && res1.typ === InstrToken1Types.CLAUSE) 
                res.typ = InstrToken1Types.CHAPTER;
        }
        let specs = 0;
        let _chars = 0;
        if (res.numbers.length === 2 && res.numbers[0] === "2" && res.numbers[1] === "3") {
        }
        for (tt = (res.numEndToken === null ? res.beginToken : res.numEndToken.next); tt !== null; tt = tt.next) {
            if (tt.endChar > res.endToken.endChar) 
                break;
            let tto = Utils.as(tt, TextToken);
            if (tto === null) 
                continue;
            if (!tto.chars.isLetter) {
                if (!tto.isCharOf(",;.():") && !BracketHelper.isBracket(tto, false)) 
                    specs += tto.lengthChar;
            }
            else 
                _chars += tto.lengthChar;
        }
        if ((specs + _chars) > 0) {
            if (((Utils.intDiv(specs * 100, (specs + _chars)))) > 10) 
                res.hasManySpecChars = true;
        }
        res.titleTyp = InstrToken1StdTitleType.UNDEFINED;
        let words = 0;
        for (tt = (res.numBeginToken === null ? res.beginToken : res.numBeginToken.next); tt !== null && tt.endChar <= res.endChar; tt = tt.next) {
            if (!(tt instanceof TextToken) || tt.isChar('_')) {
                res.titleTyp = InstrToken1StdTitleType.UNDEFINED;
                break;
            }
            if (!tt.chars.isLetter || tt.morph._class.isConjunction || tt.morph._class.isPreposition) 
                continue;
            let npt = NounPhraseHelper.tryParse(tt, NounPhraseParseAttr.NO, 0, null);
            if (npt !== null) {
                words++;
                let ii = 0;
                for (ii = 0; ii < InstrToken1.m_StdReqWords.length; ii++) {
                    if (npt.noun.isValue(InstrToken1.m_StdReqWords[ii], null)) 
                        break;
                }
                if (ii < InstrToken1.m_StdReqWords.length) {
                    tt = npt.endToken;
                    res.titleTyp = InstrToken1StdTitleType.REQUISITES;
                    continue;
                }
                if (npt.noun.isValue("ВВЕДЕНИЕ", "ВВЕДЕННЯ") || npt.noun.isValue("ВСТУПЛЕНИЕ", "ВСТУП")) {
                    words++;
                    tt = npt.endToken;
                    res.titleTyp = InstrToken1StdTitleType.OTHERS;
                    continue;
                }
                if (((npt.noun.isValue("ПОЛОЖЕНИЕ", "ПОЛОЖЕННЯ") || npt.noun.isValue("СОКРАЩЕНИЕ", "СКОРОЧЕННЯ") || npt.noun.isValue("ТЕРМИН", "ТЕРМІН")) || npt.noun.isValue("ОПРЕДЕЛЕНИЕ", "ВИЗНАЧЕННЯ") || npt.noun.isValue("АББРЕВИАТУРА", "АБРЕВІАТУРА")) || npt.noun.isValue("ЛИТЕРАТУРА", "ЛІТЕРАТУРА") || npt.noun.isValue("НАЗВАНИЕ", "НАЗВА")) {
                    tt = npt.endToken;
                    res.titleTyp = InstrToken1StdTitleType.OTHERS;
                    continue;
                }
                if (npt.noun.isValue("ПАСПОРТ", null)) {
                    tt = npt.endToken;
                    res.titleTyp = InstrToken1StdTitleType.OTHERS;
                    let npt2 = NounPhraseHelper.tryParse(npt.endToken.next, NounPhraseParseAttr.NO, 0, null);
                    if (npt2 !== null && npt2.morph._case.isGenitive && (npt2.whitespacesBeforeCount < 3)) 
                        tt = npt2.endToken;
                    continue;
                }
                if (npt.noun.isValue("ПРЕДМЕТ", null)) {
                    tt = npt.endToken;
                    res.titleTyp = InstrToken1StdTitleType.SUBJECT;
                    continue;
                }
                if (npt.endToken instanceof TextToken) {
                    let term = npt.endToken.term;
                    if (term === "ПРИЛОЖЕНИЯ" || term === "ПРИЛОЖЕНИЙ") {
                        tt = npt.endToken;
                        res.titleTyp = InstrToken1StdTitleType.OTHERS;
                        continue;
                    }
                }
                if (((npt.noun.isValue("МОМЕНТ", null) || npt.noun.isValue("ЗАКЛЮЧЕНИЕ", "ВИСНОВОК") || npt.noun.isValue("ДАННЫЕ", null)) || npt.isValue("ДОГОВОР", "ДОГОВІР") || npt.isValue("КОНТРАКТ", null)) || npt.isValue("СПИСОК", null) || npt.isValue("ПЕРЕЧЕНЬ", "ПЕРЕЛІК")) {
                    tt = npt.endToken;
                    continue;
                }
            }
            let pp = ParticipantToken.tryAttach(tt, null, null, false);
            if (pp !== null && pp.kind === ParticipantTokenKinds.PURE) {
                tt = pp.endToken;
                continue;
            }
            res.titleTyp = InstrToken1StdTitleType.UNDEFINED;
            break;
        }
        if (res.titleTyp !== InstrToken1StdTitleType.UNDEFINED && res.numbers.length === 0) {
            t = res.beginToken;
            if (!(t instanceof TextToken) || !t.chars.isLetter || t.chars.isAllLower) 
                res.titleTyp = InstrToken1StdTitleType.UNDEFINED;
        }
        if ((res.numbers.length === 0 && !res.isNewlineBefore && res.beginToken.previous !== null) && res.beginToken.previous.isTableControlChar) 
            res.titleTyp = InstrToken1StdTitleType.UNDEFINED;
        for (t = res.endToken.next; t !== null; t = t.next) {
            if (!t.isTableControlChar) 
                break;
            else if (t.isChar(String.fromCharCode(0x1E))) 
                break;
            else 
                res.endToken = t;
        }
        if (res.numbers.length === 0 && res.hasVerb && res.typ === InstrToken1Types.LINE) {
            if (res.beginToken.isValue3("В", "СООТВЕТСТВИИ", "С")) {
                let hasDecr = false;
                let hasDate = false;
                for (t = res.beginToken.next.next.next; t !== null && t.endChar <= res.endChar; t = t.next) {
                    let r = t.getReferent();
                    if (r !== null) {
                        if ((r instanceof DecreeReferent) || (r instanceof DecreePartReferent)) 
                            hasDecr = true;
                        else if (r.typeName === "DATE") 
                            hasDate = true;
                        else 
                            break;
                        continue;
                    }
                    if (t.lengthChar < 2) 
                        continue;
                    if (t.isValue("БУДЕТ", null)) {
                        if (hasDate && hasDecr) 
                            res.typ = InstrToken1Types.COMMENT;
                    }
                    break;
                }
            }
        }
        return res;
    }
    
    static _isFirstLine(t) {
        let tt = Utils.as(t, TextToken);
        if (tt === null) 
            return false;
        let v = tt.term;
        if ((((v === "ИСХОДЯ" || v === "ВИХОДЯЧИ")) && t.next !== null && t.next.isValue("ИЗ", "З")) && t.next.next !== null && t.next.next.isValue("ИЗЛОЖЕННОЕ", "ВИКЛАДЕНЕ")) 
            return true;
        if ((((v === "НА" || v === "HA")) && t.next !== null && t.next.isValue("ОСНОВАНИЕ", "ПІДСТАВА")) && t.next.next !== null && t.next.next.isValue("ИЗЛОЖЕННОЕ", "ВИКЛАДЕНЕ")) 
            return true;
        if (((v === "УЧИТЫВАЯ" || v === "ВРАХОВУЮЧИ")) && t.next !== null && t.next.isValue("ИЗЛОЖЕННОЕ", "ВИКЛАДЕНЕ")) 
            return true;
        if ((v === "ЗАСЛУШАВ" || v === "РАССМОТРЕВ" || v === "ЗАСЛУХАВШИ") || v === "РОЗГЛЯНУВШИ") 
            return true;
        if (v === "РУКОВОДСТВУЯСЬ" || v === "КЕРУЮЧИСЬ") 
            return tt.isNewlineBefore;
        return false;
    }
    
    static _createEdition(t) {
        if (t === null || t.next === null) 
            return null;
        let ok = false;
        let t1 = t;
        let br = 0;
        if (t.isChar('(') && ((t.isNewlineBefore || ((t.previous !== null && t.previous.isChar(')')))))) {
            ok = true;
            br = 1;
            t1 = t.next;
        }
        if (!ok || t1 === null) 
            return null;
        ok = false;
        let dts = PartToken.tryAttachList(t1, true, 40);
        if (dts !== null && dts.length > 0) 
            t1 = dts[dts.length - 1].endToken.next;
        let t2 = InstrToken._checkEntered(t1);
        if (t2 === null && t1 !== null) 
            t2 = InstrToken._checkEntered(t1.next);
        if (t2 !== null) 
            ok = true;
        if (!ok) 
            return null;
        for (t1 = t2; t1 !== null; t1 = t1.next) {
            if (t1.isChar(')')) {
                if ((--br) === 0) 
                    return t1;
            }
            else if (t1.isChar('(')) 
                br++;
            else if (t1.isNewlineAfter) 
                break;
        }
        return null;
    }
    
    static _checkDirective(t, val) {
        val.value = null;
        if (t === null || t.morph._class.isAdjective) 
            return null;
        for (let ii = 0; ii < InstrToken.m_Directives.length; ii++) {
            if (t.isValue(InstrToken.m_Directives[ii], null)) {
                val.value = InstrToken.m_DirectivesNorm[ii];
                if (t.whitespacesBeforeCount < 7) {
                    if (((((val.value !== "ПРИКАЗ" && val.value !== "ПОСТАНОВЛЕНИЕ" && val.value !== "УСТАНОВЛЕНИЕ") && val.value !== "РЕШЕНИЕ" && val.value !== "ЗАЯВЛЕНИЕ") && val.value !== "НАКАЗ" && val.value !== "ПОСТАНОВА") && val.value !== "ВСТАНОВЛЕННЯ" && val.value !== "РІШЕННЯ") && val.value !== "ЗАЯВУ") {
                        if ((t.next !== null && t.next.isChar(':') && t.next.isNewlineAfter) && t.chars.isAllUpper) {
                        }
                        else 
                            break;
                    }
                }
                if (t.next !== null && t.next.isValue("СЛЕДУЮЩЕЕ", "НАСТУПНЕ")) 
                    return t.next;
                if (((val.value === "ЗАЯВЛЕНИЕ" || val.value === "ЗАЯВА")) && t.next !== null && (t.next.getReferent() instanceof OrganizationReferent)) 
                    t = t.next;
                return t;
            }
        }
        if (t.chars.isLetter && t.lengthChar === 1) {
            if (t.isNewlineBefore || ((t.next !== null && t.next.chars.isLetter && t.next.lengthChar === 1))) {
                for (let ii = 0; ii < InstrToken.m_Directives.length; ii++) {
                    let res = MiscHelper.tryAttachWordByLetters(InstrToken.m_Directives[ii], t, true);
                    if (res !== null) {
                        val.value = InstrToken.m_DirectivesNorm[ii];
                        return res;
                    }
                }
            }
        }
        return null;
    }
    
    get typContainerRank() {
        let res = InstrToken1._calcRank(this.typ);
        return res;
    }
    
    static _calcRank(ty) {
        if (ty === InstrToken1Types.DOCPART) 
            return 1;
        if (ty === InstrToken1Types.SECTION) 
            return 2;
        if (ty === InstrToken1Types.SUBSECTION) 
            return 3;
        if (ty === InstrToken1Types.CHAPTER) 
            return 4;
        if (ty === InstrToken1Types.PARAGRAPH) 
            return 5;
        if (ty === InstrToken1Types.SUBPARAGRAPH) 
            return 6;
        if (ty === InstrToken1Types.CLAUSE) 
            return 7;
        return 0;
    }
    
    canBeContainerFor(lt) {
        let r = InstrToken1._calcRank(this.typ);
        let r1 = InstrToken1._calcRank(lt.typ);
        if (r > 0 && r1 > 0) 
            return r < r1;
        return false;
    }
    
    static _new1999(_arg1, _arg2, _arg3) {
        let res = new InstrToken1(_arg1, _arg2);
        res.typ = _arg3;
        return res;
    }
    
    static _new2229(_arg1, _arg2, _arg3) {
        let res = new InstrToken1(_arg1, _arg2);
        res.allUpper = _arg3;
        return res;
    }
    
    static _new2233(_arg1, _arg2, _arg3, _arg4) {
        let res = new InstrToken1(_arg1, _arg2);
        res.typ = _arg3;
        res.value = _arg4;
        return res;
    }
    
    static _new2246(_arg1, _arg2, _arg3, _arg4) {
        let res = new InstrToken1(_arg1, _arg2);
        res.indexNoKeyword = _arg3;
        res.typ = _arg4;
        return res;
    }
    
    static static_constructor() {
        InstrToken1.m_StdReqWords = Array.from(["РЕКВИЗИТ", "ПОДПИСЬ", "СТОРОНА", "АДРЕС", "ТЕЛЕФОН", "МЕСТО", "НАХОЖДЕНИЕ", "МЕСТОНАХОЖДЕНИЕ", "ТЕРМИН", "ОПРЕДЕЛЕНИЕ", "СЧЕТ", "РЕКВІЗИТ", "ПІДПИС", "СТОРОНА", "АДРЕСА", "МІСЦЕ", "ЗНАХОДЖЕННЯ", "МІСЦЕЗНАХОДЖЕННЯ", "ТЕРМІН", "ВИЗНАЧЕННЯ", "РАХУНОК"]);
    }
}


InstrToken1.static_constructor();

module.exports = InstrToken1