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

const UriReferent = require("./../../uri/UriReferent");
const NounPhraseParseAttr = require("./../../core/NounPhraseParseAttr");
const DecreePartReferent = require("./../../decree/DecreePartReferent");
const NounPhraseHelper = require("./../../core/NounPhraseHelper");
const DecreeTokenItemType = require("./../../decree/internal/DecreeTokenItemType");
const GeoReferent = require("./../../geo/GeoReferent");
const BankDataReferent = require("./../../bank/BankDataReferent");
const DateReferent = require("./../../date/DateReferent");
const MorphLang = require("./../../../morph/MorphLang");
const MorphNumber = require("./../../../morph/MorphNumber");
const MorphGender = require("./../../../morph/MorphGender");
const MorphClass = require("./../../../morph/MorphClass");
const MiscHelper = require("./../../core/MiscHelper");
const DecreeKind = require("./../../decree/DecreeKind");
const NumberToken = require("./../../NumberToken");
const Termin = require("./../../core/Termin");
const BracketParseAttr = require("./../../core/BracketParseAttr");
const MetaToken = require("./../../MetaToken");
const InstrumentParticipantReferent = require("./../InstrumentParticipantReferent");
const PersonPropertyReferent = require("./../../person/PersonPropertyReferent");
const PersonReferent = require("./../../person/PersonReferent");
const ILTypes = require("./ILTypes");
const TextToken = require("./../../TextToken");
const TerminParseAttr = require("./../../core/TerminParseAttr");
const ReferentToken = require("./../../ReferentToken");
const BracketHelper = require("./../../core/BracketHelper");
const TerminCollection = require("./../../core/TerminCollection");
const TableHelper = require("./../../core/TableHelper");
const InstrToken1Types = require("./InstrToken1Types");
const OrganizationReferent = require("./../../org/OrganizationReferent");
const DecreeReferent = require("./../../decree/DecreeReferent");
const DecreeToken = require("./../../decree/internal/DecreeToken");
const PersonAnalyzer = require("./../../person/PersonAnalyzer");

class InstrToken extends MetaToken {
    
    constructor(b, e) {
        super(b, e, null);
        this.typ = ILTypes.UNDEFINED;
        this.value = null;
        this.ref = null;
        this.hasVerb = false;
        this.noWords = false;
    }
    
    static initialize() {
        if (InstrToken.m_Ontology !== null) 
            return;
        InstrToken.m_Ontology = new TerminCollection();
        let t = null;
        t = new Termin("МЕСТО ПЕЧАТИ");
        t.addAbridge("М.П.");
        t.addAbridge("M.П.");
        InstrToken.m_Ontology.add(t);
        t = new Termin("МІСЦЕ ПЕЧАТКИ", MorphLang.UA);
        t.addAbridge("М.П.");
        t.addAbridge("M.П.");
        InstrToken.m_Ontology.add(t);
        t = new Termin("ПОДПИСЬ");
        InstrToken.m_Ontology.add(t);
        t = new Termin("ПІДПИС", MorphLang.UA);
        InstrToken.m_Ontology.add(t);
        t = Termin._new1197("ФАМИЛИЯ ИМЯ ОТЧЕСТВО", "ФИО");
        t.addAbridge("Ф.И.О.");
        InstrToken.m_Ontology.add(t);
        t = Termin._new2198("ПРІЗВИЩЕ ІМЯ ПО БАТЬКОВІ", MorphLang.UA, "ФИО");
        InstrToken.m_Ontology.add(t);
        t = new Termin("ФАМИЛИЯ");
        t.addAbridge("ФАМ.");
        InstrToken.m_Ontology.add(t);
        t = new Termin("ПРІЗВИЩЕ", MorphLang.UA);
        t.addAbridge("ФАМ.");
        InstrToken.m_Ontology.add(t);
        InstrToken.m_Ontology.add(new Termin("ИМЯ"));
        InstrToken.m_Ontology.add(new Termin("ІМЯ", MorphLang.UA));
    }
    
    get isPurePerson() {
        if (this.ref instanceof ReferentToken) {
            let rt = Utils.as(this.ref, ReferentToken);
            if ((rt.referent instanceof PersonReferent) || (rt.referent instanceof PersonPropertyReferent)) 
                return true;
            if (rt.referent instanceof InstrumentParticipantReferent) {
                for (let t = rt.beginToken; t !== null && t.endChar <= rt.endChar; t = t.next) {
                    if ((t.getReferent() instanceof PersonReferent) || (t.getReferent() instanceof PersonPropertyReferent)) 
                        return true;
                    else if ((t instanceof TextToken) && t.chars.isLetter) 
                        break;
                }
                return false;
            }
        }
        return this.ref instanceof PersonReferent;
    }
    
    get isPodpisStoron() {
        if (!this.isNewlineBefore || !this.isNewlineAfter) 
            return false;
        if (!this.beginToken.isValue("ПОДПИСЬ", "ПІДПИС")) 
            return false;
        let t = this.beginToken.next;
        if (t !== null && t.isValue("СТОРОНА", null)) 
            t = t.next;
        if (t !== null && t.isCharOf(":.")) 
            t = t.next;
        if (this.endToken.next === t) 
            return true;
        return false;
    }
    
    get hasTableChars() {
        for (let t = this.beginToken; t !== null && t.endChar <= this.endChar; t = t.next) {
            if (t.isTableControlChar) 
                return true;
        }
        if (this.endToken.next !== null && this.endToken.next.isTableControlChar && !this.endToken.next.isChar(String.fromCharCode(0x1E))) 
            return true;
        if (this.beginToken.previous !== null && this.beginToken.previous.isTableControlChar && !this.beginToken.previous.isChar(String.fromCharCode(0x1F))) 
            return true;
        return false;
    }
    
    get onlyPerson() {
        let hasPers = false;
        for (let t = this.beginToken; t !== null && t.endChar <= this.endChar; t = t.next) {
            if ((t.getReferent() instanceof PersonReferent) || (t.getReferent() instanceof PersonPropertyReferent)) 
                hasPers = true;
            else if ((t instanceof TextToken) && (t.lengthChar < 2)) {
            }
            else 
                return false;
        }
        return hasPers;
    }
    
    toString() {
        let tmp = new StringBuilder();
        tmp.append("[").append(this.lengthChar).append("] ");
        if (this.isNewlineBefore) 
            tmp.append("<<");
        tmp.append(this.typ.toString());
        if (this.value !== null) 
            tmp.append(" '").append(this.value).append("'");
        if (this.ref !== null) 
            tmp.append(" -> ").append(this.ref.toString());
        if (this.hasVerb) 
            tmp.append(" HasVerb");
        if (this.noWords) 
            tmp.append(" NoWords");
        if (this.hasTableChars) 
            tmp.append(" HasTableChars");
        if (this.isNewlineAfter) 
            tmp.append(">>");
        tmp.append(": ").append(this.getSourceText());
        return tmp.toString();
    }
    
    static parseList(t0, maxChar = 0) {
        const InstrToken1 = require("./InstrToken1");
        let res = new Array();
        for (let t = t0; t !== null; t = t.next) {
            if (maxChar > 0) {
                if (t.beginChar > maxChar) 
                    break;
            }
            if (res.length === 272) {
            }
            let it = InstrToken.parse(t, maxChar, (res.length > 0 ? res[res.length - 1] : null));
            if (it === null) 
                break;
            if (res.length === 50) {
            }
            if (it.lengthChar > 1000) {
            }
            if (it.typ === ILTypes.APPENDIX) {
            }
            else if (t.isValue("ПРИЛОЖЕНИЕ", null)) {
            }
            if (it.typ === ILTypes.TYP) {
            }
            if (res.length > 0) {
                if (res[res.length - 1].endChar > it.beginChar) 
                    break;
            }
            if ((it.endToken.next instanceof TextToken) && it.endToken.next.isChar('.')) 
                it.endToken = it.endToken.next;
            if (it.typ === ILTypes.UNDEFINED && t.isNewlineBefore && !t.isTableControlChar) {
                let it1 = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
                if (it1 !== null && it1.hasChanges && it1.endChar > it.endChar) 
                    it.endToken = it1.endToken;
            }
            res.push(it);
            if (it.endChar > t.beginChar) 
                t = it.endToken;
        }
        return res;
    }
    
    static _correctPerson(res) {
        let specChars = 0;
        if (!res.isPurePerson) {
            res.typ = ILTypes.UNDEFINED;
            return res;
        }
        for (let t = res.endToken.next; t !== null; t = t.next) {
            if ((t instanceof ReferentToken) && (res.ref instanceof ReferentToken)) {
                let ok = false;
                if (t.getReferent() === res.ref.referent) 
                    ok = true;
                let ip = Utils.as(res.ref.referent, InstrumentParticipantReferent);
                if (ip !== null && ip.containsRef(t.getReferent())) 
                    ok = true;
                if (!ok && t.previous !== null && t.previous.isTableControlChar) {
                    if ((res.ref.referent instanceof PersonPropertyReferent) && (t.getReferent() instanceof PersonReferent)) {
                        ok = true;
                        res.ref = t;
                    }
                }
                if (ok) {
                    res.endToken = t;
                    continue;
                }
            }
            let tok = InstrToken.m_Ontology.tryParse(t, TerminParseAttr.NO);
            if (tok !== null) {
                if ((((tok.termin.canonicText === "ПОДПИСЬ" || tok.termin.canonicText === "ПІДПИС")) && t.isNewlineBefore && t.next !== null) && t.next.isValue("СТОРОНА", null)) 
                    break;
                res.endToken = (t = tok.endToken);
                continue;
            }
            if (t.isChar(',')) 
                continue;
            if (t.isTableControlChar && !t.isNewlineBefore) 
                continue;
            if (t.isCharOf("_/\\")) {
                res.endToken = t;
                specChars++;
                continue;
            }
            if (t.isChar('(') && t.next !== null) {
                if ((((tok = InstrToken.m_Ontology.tryParse(t.next, TerminParseAttr.NO)))) !== null) {
                    let br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                    if (br !== null) {
                        res.endToken = (t = br.endToken);
                        continue;
                    }
                }
            }
            break;
        }
        let rt0 = Utils.as(res.ref, ReferentToken);
        if (rt0 !== null && (rt0.referent instanceof InstrumentParticipantReferent)) {
            for (let tt = res.beginToken; tt !== null && tt.endChar <= res.endChar; tt = tt.next) {
                if ((tt.getReferent() instanceof PersonReferent) || (tt.getReferent() instanceof PersonPropertyReferent)) {
                    res.ref = tt;
                    return res;
                }
                else if ((tt instanceof TextToken) && tt.isCharOf("_/\\")) 
                    specChars++;
                else if (tt instanceof MetaToken) {
                    for (let ttt = tt.beginToken; ttt !== null && ttt.endChar <= tt.endChar; ttt = ttt.next) {
                        if ((ttt.getReferent() instanceof PersonReferent) || (ttt.getReferent() instanceof PersonPropertyReferent)) {
                            res.ref = ttt;
                            return res;
                        }
                        else if ((ttt instanceof TextToken) && ttt.isCharOf("_/\\")) 
                            specChars++;
                    }
                }
            }
            if (specChars < 10) 
                res.typ = ILTypes.UNDEFINED;
        }
        return res;
    }
    
    static parse(t, maxChar = 0, prev = null) {
        const InstrToken1 = require("./InstrToken1");
        let isStartOfLine = false;
        let t00 = t;
        if (t !== null) {
            if (t.isChar(String.fromCharCode(0x1E))) {
                if (t.next !== null && t.next.isValue("ПРИЛОЖЕНИЕ", null)) {
                }
                else {
                    let rows = TableHelper.tryParseRows(t, maxChar, true, false);
                    if (rows !== null && rows.length > 3) 
                        return InstrToken._new2199(t, rows[rows.length - 1].endToken, ILTypes.UNDEFINED);
                }
            }
            isStartOfLine = t00.isNewlineBefore;
            if (t.previous !== null && t.previous.isChar(String.fromCharCode(0x1F))) 
                isStartOfLine = true;
            while (t !== null) {
                if (t.isChar(String.fromCharCode(0x1F))) 
                    return InstrToken._new2200(t00, t, true);
                else if (t.isTableControlChar) {
                    if (t.isNewlineAfter && !isStartOfLine) 
                        isStartOfLine = true;
                    t = t.next;
                }
                else 
                    break;
            }
        }
        if (t === null) 
            return null;
        if (t.isNewlineBefore) 
            isStartOfLine = true;
        if (isStartOfLine) {
            if ((t.isValue("СОДЕРЖИМОЕ", "ВМІСТ") || t.isValue("СОДЕРЖАНИЕ", "ЗМІСТ") || t.isValue("ОГЛАВЛЕНИЕ", "ЗМІСТ")) || ((t.isValue("СПИСОК", null) && t.next !== null && t.next.isValue("РАЗДЕЛ", null)))) {
                let cont = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
                if (cont !== null && cont.typ === InstrToken1Types.INDEX) 
                    return new InstrToken(t, cont.endToken);
            }
        }
        let t0 = t;
        let t1 = null;
        let hasWord = false;
        for (; t !== null; t = t.next) {
            if (t.isNewlineBefore && t !== t0) 
                break;
            if (maxChar > 0 && t.beginChar > maxChar) 
                break;
            if (isStartOfLine && t === t0) {
                if (t.isValue("ГЛАВА", null)) {
                    let _next = InstrToken.parse(t.next, 0, null);
                    if (_next !== null && _next.typ === ILTypes.PERSON) {
                        _next.beginToken = t;
                        return _next;
                    }
                }
                if (t.isValue("ИСП", null)) {
                    let tt2 = t.next;
                    if (tt2 !== null && tt2.isChar('.')) 
                        tt2 = tt2.next;
                    let _next = InstrToken.parse(tt2, 0, null);
                    if (_next !== null && _next.typ === ILTypes.PERSON) {
                        _next.beginToken = t;
                        return _next;
                    }
                }
                let tt = null;
                if ((t.getReferent() instanceof PersonReferent) || (t.getReferent() instanceof PersonPropertyReferent) || (t.getReferent() instanceof InstrumentParticipantReferent)) 
                    return InstrToken._correctPerson(InstrToken._new2201(t00, t, ILTypes.PERSON, t));
                let isRef = false;
                if (t.getReferent() instanceof PersonPropertyReferent) {
                    tt = t.next;
                    isRef = true;
                }
                else if (prev !== null && prev.typ === ILTypes.PERSON) {
                    let rt = t.kit.processReferent(PersonAnalyzer.ANALYZER_NAME, t, null);
                    if (rt !== null) {
                        if (rt.referent instanceof PersonReferent) 
                            return InstrToken._new2199(t00, rt.endToken, ILTypes.PERSON);
                        tt = rt.endToken.next;
                    }
                }
                let cou = 0;
                let t11 = (tt === null ? null : tt.previous);
                for (; tt !== null; tt = tt.next) {
                    if (tt.isTableControlChar) 
                        continue;
                    let re = tt.getReferent();
                    if (re instanceof PersonReferent) 
                        return InstrToken._new2201(t00, tt, ILTypes.PERSON, tt);
                    if (re instanceof GeoReferent) {
                        t11 = tt;
                        continue;
                    }
                    if (re !== null) 
                        break;
                    if (DecreeToken.isKeyword(tt, false) !== null) 
                        break;
                    if (tt.isNewlineBefore) {
                        if ((++cou) > 4) 
                            break;
                    }
                }
                if (tt === null && isRef) 
                    return InstrToken._new2201(t00, (t11 != null ? t11 : t), ILTypes.PERSON, t);
            }
            let dt = DecreeToken.tryAttach(t, null, false);
            if ((dt !== null && dt.typ === DecreeTokenItemType.NUMBER && prev !== null) && prev.typ === ILTypes.APPENDIX) 
                dt = null;
            if (dt !== null) {
                if (dt.typ === DecreeTokenItemType.TYP && !t.chars.isAllLower) {
                    if (t !== t0) 
                        break;
                    let _hasVerb = false;
                    for (let tt = dt.endToken; tt !== null; tt = tt.next) {
                        if (tt.isNewlineBefore) 
                            break;
                        else if ((tt instanceof TextToken) && tt.isPureVerb) {
                            _hasVerb = true;
                            break;
                        }
                    }
                    if (!_hasVerb) {
                        let res2 = InstrToken._new2205(t0, dt.endToken, ILTypes.TYP, (dt.fullValue != null ? dt.fullValue : dt.value));
                        if (res2.value === "ДОПОЛНИТЕЛЬНОЕ СОГЛАШЕНИЕ" || res2.value === "ДОДАТКОВА УГОДА") {
                            if (res2.beginChar > 500 && res2.newlinesBeforeCount > 1) 
                                res2.typ = ILTypes.APPENDIX;
                        }
                        return res2;
                    }
                }
                if (dt.typ === DecreeTokenItemType.NUMBER) {
                    if (t !== t0) 
                        break;
                    return InstrToken._new2205(t0, dt.endToken, ILTypes.REGNUMBER, dt.value);
                }
                if (dt.typ === DecreeTokenItemType.ORG) {
                    if (t !== t0) 
                        break;
                    return InstrToken._new2207(t0, dt.endToken, ILTypes.ORGANIZATION, dt.ref, dt.value);
                }
                if (dt.typ === DecreeTokenItemType.TERR) {
                    if (t !== t0) 
                        break;
                    let re = InstrToken._new2207(t0, dt.endToken, ILTypes.GEO, dt.ref, dt.value);
                    t1 = re.endToken.next;
                    if (t1 !== null && t1.isChar(',')) 
                        t1 = t1.next;
                    if (t1 !== null && t1.isValue("КРЕМЛЬ", null)) 
                        re.endToken = t1;
                    else if ((t1 !== null && t1.isValue("ДОМ", "БУДИНОК") && t1.next !== null) && t1.next.isValue("СОВЕТ", "РАД")) {
                        re.endToken = t1.next;
                        if (t1.next.next !== null && (t1.next.next.getReferent() instanceof GeoReferent)) 
                            re.endToken = t1.next.next;
                    }
                    return re;
                }
                if (dt.typ === DecreeTokenItemType.OWNER) {
                    if (t !== t0) 
                        break;
                    if (dt.ref !== null && dt.ref.referent.toString().startsWith("агент")) 
                        dt = null;
                    if (dt !== null) {
                        let res1 = InstrToken._new2207(t0, dt.endToken, ILTypes.PERSON, dt.ref, dt.value);
                        return InstrToken._correctPerson(res1);
                    }
                }
            }
            if (BracketHelper.canBeStartOfSequence(t, false, false)) {
                let br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                if (br !== null) {
                    t = (t1 = br.endToken);
                    continue;
                }
                if (t.next !== null && BracketHelper.canBeEndOfSequence(t.next, false, null, false)) {
                    t = (t1 = t.next);
                    continue;
                }
            }
            if (t instanceof TextToken) {
                if (t.isChar('_')) {
                    t1 = t;
                    continue;
                }
            }
            let r = t.getReferent();
            if (r instanceof DateReferent) {
                let tt = t;
                if (tt.next !== null && tt.next.isCharOf(",;")) 
                    tt = tt.next;
                if (!t.isNewlineBefore && !tt.isNewlineAfter) {
                    t1 = tt;
                    continue;
                }
                if (!hasWord) 
                    return InstrToken._new2201(t, tt, ILTypes.DATE, t);
                if (t !== t0) 
                    break;
            }
            hasWord = true;
            if (r instanceof InstrumentParticipantReferent) {
                for (let tt = t.beginToken; tt !== null && (tt.endChar < t.endChar); tt = tt.next) {
                    let rr = tt.getReferent();
                    if (rr === null) 
                        continue;
                    if ((rr instanceof OrganizationReferent) || (rr instanceof BankDataReferent) || (rr instanceof UriReferent)) {
                        r = null;
                        break;
                    }
                }
            }
            if ((r instanceof PersonReferent) || (r instanceof PersonPropertyReferent) || (r instanceof InstrumentParticipantReferent)) {
                if (t !== t0) 
                    break;
                if (r instanceof InstrumentParticipantReferent) {
                }
                let res1 = InstrToken._new2201(t, t, ILTypes.PERSON, t);
                return InstrToken._correctPerson(res1);
            }
            if (r instanceof OrganizationReferent) {
                if (t !== t0) 
                    break;
                return InstrToken._new2201(t, t, ILTypes.ORGANIZATION, t);
            }
            if (r instanceof DecreePartReferent) {
                let dpr = Utils.as(r, DecreePartReferent);
                if (dpr.appendix !== null) {
                    if (t.isNewlineBefore || isStartOfLine) {
                        if (t.isNewlineAfter || t.whitespacesBeforeCount > 30) 
                            return InstrToken._new2205(t, t, ILTypes.APPENDIX, "ПРИЛОЖЕНИЕ");
                        let ok = true;
                        for (let tt = t.next; tt !== null; tt = tt.next) {
                            if (tt.isNewlineBefore) 
                                break;
                            let npt = NounPhraseHelper.tryParse(tt, NounPhraseParseAttr.NO, 0, null);
                            if (npt !== null) {
                                tt = npt.endToken;
                                continue;
                            }
                            ok = false;
                            break;
                        }
                        if (ok) 
                            return InstrToken._new2205(t, t, ILTypes.APPENDIX, "ПРИЛОЖЕНИЕ");
                    }
                }
            }
            if ((r instanceof DecreeReferent) && r.kind === DecreeKind.PUBLISHER && t === t0) {
                let res1 = InstrToken._new2199(t, t, ILTypes.APPROVED);
                for (let tt = t.next; tt !== null; tt = tt.next) {
                    if (tt.isCharOf(",;")) 
                        continue;
                    if ((tt.getReferent() instanceof DecreeReferent) && tt.getReferent().kind === DecreeKind.PUBLISHER) 
                        res1.endToken = t;
                    else 
                        break;
                }
                return res1;
            }
            if (t.isValue("ЗА", null) && t.next !== null && t.isNewlineBefore) {
                let rr = t.next.getReferent();
                if ((rr instanceof PersonReferent) || (rr instanceof PersonPropertyReferent) || (rr instanceof InstrumentParticipantReferent)) {
                    if (t !== t0) 
                        break;
                    let res1 = InstrToken._new2201(t, t.next, ILTypes.PERSON, t.next);
                    t = t.next.next;
                    if ((rr instanceof InstrumentParticipantReferent) && t !== null) {
                        if ((((r = t.getReferent()))) !== null) {
                            if ((r instanceof PersonReferent) || (r instanceof PersonPropertyReferent)) {
                                res1.endToken = t;
                                res1.ref = t;
                            }
                        }
                    }
                    return res1;
                }
            }
            for (let ii = 0; ii < InstrToken.m_Directives.length; ii++) {
                if (t.isValue(InstrToken.m_Directives[ii], null)) {
                    if (t.next !== null && t.next.isValue("СЛЕДУЮЩЕЕ", "НАСТУПНЕ")) {
                        if (t !== t0) 
                            break;
                        let t11 = t.next;
                        let ok = false;
                        if (t11.next !== null && t11.next.isCharOf(":.") && t11.next.isNewlineAfter) {
                            ok = true;
                            t11 = t11.next;
                        }
                        if (ok) 
                            return InstrToken._new2205(t, t11, ILTypes.DIRECTIVE, InstrToken.m_DirectivesNorm[ii]);
                    }
                    if (t.isNewlineAfter || ((t.next !== null && t.next.isChar(':') && t.next.isNewlineAfter))) {
                        if (t !== t0) 
                            break;
                        if (!t.isNewlineBefore) {
                            if ((InstrToken.m_DirectivesNorm[ii] !== "ПРИКАЗ" && InstrToken.m_DirectivesNorm[ii] !== "ПОСТАНОВЛЕНИЕ" && InstrToken.m_DirectivesNorm[ii] !== "НАКАЗ") && InstrToken.m_DirectivesNorm[ii] !== "ПОСТАНОВУ") 
                                break;
                        }
                        return InstrToken._new2205(t, (t.isNewlineAfter ? t : t.next), ILTypes.DIRECTIVE, InstrToken.m_DirectivesNorm[ii]);
                    }
                    break;
                }
            }
            if (t.isNewlineBefore && t.chars.isLetter && t.lengthChar === 1) {
                for (const d of InstrToken.m_Directives) {
                    let t11 = MiscHelper.tryAttachWordByLetters(d, t, true);
                    if (t11 !== null) {
                        if (t11.next !== null && t11.next.isChar(':')) 
                            t11 = t11.next;
                        return InstrToken._new2199(t, t11, ILTypes.DIRECTIVE);
                    }
                }
            }
            let tte = (t instanceof MetaToken ? t.beginToken : t);
            let term = (tte instanceof TextToken ? tte.term : null);
            if (isStartOfLine && !tte.chars.isAllLower && t === t0) {
                let npt = NounPhraseHelper.tryParse(tte, NounPhraseParseAttr.NO, 0, null);
                if (npt !== null && npt.morph._case.isNominative && (npt.endToken instanceof TextToken)) {
                    let term1 = npt.endToken.term;
                    if ((((term1 === "ПРИЛОЖЕНИЕ" || term1 === "ДОДАТОК" || term1 === "МНЕНИЕ") || term1 === "ДУМКА" || term1 === "АКТ") || term === "ЗАЯВКА" || term1 === "ПРИЛОЖЕНИЯ") || term === "ДОДАТКИ") {
                        let tt1 = npt.endToken.next;
                        let dt1 = DecreeToken.tryAttach(tt1, null, false);
                        if (dt1 !== null && dt1.typ === DecreeTokenItemType.NUMBER) 
                            tt1 = dt1.endToken.next;
                        else if (tt1 instanceof NumberToken) 
                            tt1 = tt1.next;
                        else if ((tt1 instanceof TextToken) && tt1.lengthChar === 1 && tt1.chars.isLetter) 
                            tt1 = tt1.next;
                        let ok = true;
                        if (tt1 !== null && tt1.isHiphen && (tt1.next instanceof NumberToken)) 
                            tt1 = tt1.next.next;
                        else if (term1 === "ПРИЛОЖЕНИЯ" || term === "ДОДАТКИ") 
                            ok = false;
                        if (tt1 === null) 
                            ok = false;
                        else if (tt1.isValue("В", "У")) 
                            ok = false;
                        else if (tt1.isValue("К", null) && tt1.isNewlineBefore) 
                            return InstrToken._new2205(t, t, ILTypes.APPENDIX, term1);
                        else if (tt1.isValue("УТРАТИТЬ", null)) 
                            return InstrToken._new2205(t, t, ILTypes.APPENDIX, term1);
                        else if (!tt1.isNewlineBefore && InstrToken._checkEntered(tt1) !== null) 
                            ok = false;
                        else if (tt1 === t.next && ((tt1.isChar(':') || ((tt1.isValue("НА", null) && term1 !== "ЗАЯВКА"))))) 
                            ok = false;
                        else if (term1 === "МНЕНИЕ" || term1 === "ДУМКА") {
                            ok = false;
                            if (tt1 !== null) {
                                if (tt1.isValue("СУДЬЯ", null)) 
                                    ok = true;
                                else if ((tt1 instanceof ReferentToken) && tt1.referent.typeName === "PERSON") 
                                    ok = true;
                            }
                        }
                        if (term1 === "ПРИЛОЖЕНИЯ" || term === "ДОДАТКИ") 
                            ok = false;
                        if (ok) {
                            let br = BracketHelper.tryParse(tt1, BracketParseAttr.NO, 100);
                            if (br !== null) {
                                tt1 = br.endToken.next;
                                if (br.endToken.next === null || !br.endToken.isNewlineAfter || br.endToken.next.isCharOf(";,")) 
                                    ok = false;
                                if (tt1 !== null && tt1.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК")) 
                                    ok = false;
                            }
                        }
                        if (prev !== null && prev.typ === ILTypes.APPENDIX) 
                            ok = false;
                        if (ok) {
                            let cou = 0;
                            for (let ttt = tte.previous; ttt !== null && (cou < 300); ttt = ttt.previous,cou++) {
                                if (ttt.isTableControlChar) {
                                    if (!ttt.isChar(String.fromCharCode(0x1F))) {
                                        if (ttt === tte.previous && ttt.isChar(String.fromCharCode(0x1E))) {
                                        }
                                        else 
                                            ok = false;
                                    }
                                    break;
                                }
                            }
                        }
                        if (ok) {
                            let it1 = InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
                            if (it1 !== null) {
                                if (it1.hasVerb) 
                                    ok = false;
                            }
                        }
                        if (ok && t.previous !== null) {
                            for (let ttp = t.previous; ttp !== null; ttp = ttp.previous) {
                                if (ttp.isTableControlChar && !ttp.isChar(String.fromCharCode(0x1F))) 
                                    continue;
                                if (BracketHelper.isBracket(ttp, false) && !BracketHelper.canBeEndOfSequence(ttp, false, null, false)) 
                                    continue;
                                if (ttp.isCharOf(";:")) 
                                    ok = false;
                                break;
                            }
                        }
                        if ((ok && t.previous !== null && (t.newlinesBeforeCount < 3)) && !t.isNewlineAfter) {
                            let lines = 0;
                            for (let ttp = t.previous; ttp !== null; ttp = ttp.previous) {
                                if (!ttp.isNewlineBefore) 
                                    continue;
                                for (; ttp !== null && (ttp.endChar < t.beginChar); ttp = ttp.next) {
                                    if (ttp instanceof NumberToken) {
                                    }
                                    else if ((ttp instanceof TextToken) && ttp.lengthChar > 1) {
                                        if (ttp.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК")) 
                                            ok = false;
                                        break;
                                    }
                                    else 
                                        break;
                                }
                                if ((++lines) > 1) 
                                    break;
                            }
                        }
                        if (ok && ((term1 !== "ПРИЛОЖЕНИЕ" && term1 !== "ДОДАТОК" && term1 !== "МНЕНИЕ"))) {
                            if (t.newlinesBeforeCount < 3) 
                                ok = false;
                        }
                        if (ok) 
                            return InstrToken._new2205(t, t, ILTypes.APPENDIX, term1);
                    }
                }
            }
            let app = false;
            if ((((term === "ОСОБОЕ" || term === "ОСОБЛИВЕ")) && t.next !== null && t.next.isValue("МНЕНИЕ", "ДУМКА")) && t === t0 && isStartOfLine) 
                app = true;
            if ((((term === "ДОПОЛНИТЕЛЬНОЕ" || term === "ДОДАТКОВА")) && t.next !== null && t.next.isValue("СОГЛАШЕНИЕ", "УГОДА")) && t === t0 && isStartOfLine) 
                app = true;
            if (app) {
                for (let tt = t.next; tt !== null; tt = tt.next) {
                    if (tt.isNewlineBefore) 
                        break;
                    else if (tt.getMorphClassInDictionary().equals(MorphClass.VERB)) {
                        app = false;
                        break;
                    }
                }
                if (app) 
                    return InstrToken._new2199(t, t.next, ILTypes.APPENDIX);
            }
            if (!t.chars.isAllLower && t === t0) {
                let tt = InstrToken._checkApproved(t);
                if (tt !== null) {
                    if (tt.next !== null && (tt.next.getReferent() instanceof DecreeReferent)) 
                        return InstrToken._new2201(t, tt, ILTypes.APPROVED, tt.next.getReferent());
                    let dt1 = DecreeToken.tryAttach(tt.next, null, false);
                    if (dt1 !== null && dt1.typ === DecreeTokenItemType.TYP) 
                        return InstrToken._new2199(t, tt, ILTypes.APPROVED);
                }
            }
            t1 = t;
            isStartOfLine = false;
        }
        if (t1 === null) 
            t1 = t;
        if (t1 === null) 
            return null;
        let res = InstrToken._new2199(t00, t1, ILTypes.UNDEFINED);
        res.noWords = true;
        for (t = t0; t !== null && t.endChar <= t1.endChar; t = t.next) {
            if (!(t instanceof TextToken)) {
                if (t instanceof ReferentToken) 
                    res.noWords = false;
                continue;
            }
            if (!t.chars.isLetter) 
                continue;
            res.noWords = false;
            if (t.isPureVerb) 
                res.hasVerb = true;
        }
        if (t0.isValue("ВОПРОС", "ПИТАННЯ") && t0.next !== null && t0.next.isCharOf(":.")) 
            res.typ = ILTypes.QUESTION;
        return res;
    }
    
    static _checkApproved(t) {
        if (t === null) 
            return null;
        if (((!t.isValue("УТВЕРЖДЕН", "ЗАТВЕРДЖЕНИЙ") && !t.isValue("УТВЕРЖДАТЬ", "СТВЕРДЖУВАТИ") && !t.isValue("УТВЕРДИТЬ", "ЗАТВЕРДИТИ")) && !t.isValue("ВВЕСТИ", null) && !t.isValue("СОГЛАСОВАНО", "ПОГОДЖЕНО")) && !t.isValue("СОГЛАСОВАТЬ", "ПОГОДИТИ")) 
            return null;
        if (t.morph.containsAttr("инф.", null) && t.morph.containsAttr("сов.в.", null)) 
            return null;
        if (t.morph.containsAttr("возвр.", null)) 
            return null;
        let t0 = t;
        let t1 = t;
        for (t = t.next; t !== null; t = t.next) {
            if (t.morph._class.isPreposition || t.morph._class.isConjunction) 
                continue;
            if (t.isChar(':')) 
                continue;
            if (t.isValue("ДЕЙСТВИЕ", "ДІЯ") || t.isValue("ВВЕСТИ", null) || t.isValue("ВВОДИТЬ", "ВВОДИТИ")) {
                t1 = t;
                continue;
            }
            let tt = InstrToken._checkApproved(t);
            if (tt !== null) {
                if (!tt.isNewlineBefore && tt.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false) !== t0.getNormalCaseText(null, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, false)) {
                    t1 = (tt = t);
                    continue;
                }
            }
            break;
        }
        return t1;
    }
    
    static _checkEntered(t) {
        if (t === null) 
            return null;
        if ((((t.isValue("ВСТУПАТЬ", "ВСТУПАТИ") || t.isValue("ВСТУПИТЬ", "ВСТУПИТИ"))) && t.next !== null && t.next.isValue("В", "У")) && t.next.next !== null && t.next.next.isValue("СИЛА", "ЧИННІСТЬ")) 
            return t.next.next;
        if (t.isValue("УТРАТИТЬ", "ВТРАТИТИ") && t.next !== null && t.next.isValue("СИЛА", "ЧИННІСТЬ")) 
            return t.next;
        if (t.isValue("ДЕЙСТВОВАТЬ", "ДІЯТИ") && t.next !== null && t.next.isValue("ДО", null)) 
            return t.next;
        if (((t.isValue("В", null) || t.isValue("B", null))) && t.next !== null) {
            if (t.next.isValue("РЕДАКЦИЯ", "РЕДАКЦІЯ")) 
                return t.next;
            if (t.next.isValue("РЕД", null)) {
                if (t.next.next !== null && t.next.next.isChar('.')) 
                    return t.next.next;
                return t.next;
            }
        }
        if (t.isValue("РЕДАКЦИЯ", "РЕДАКЦІЯ")) 
            return t.next;
        if (t.isValue("РЕД", null)) {
            if (t.next !== null && t.next.isChar('.')) 
                return t.next;
            return t;
        }
        return InstrToken._checkApproved(t);
    }
    
    static _new2199(_arg1, _arg2, _arg3) {
        let res = new InstrToken(_arg1, _arg2);
        res.typ = _arg3;
        return res;
    }
    
    static _new2200(_arg1, _arg2, _arg3) {
        let res = new InstrToken(_arg1, _arg2);
        res.noWords = _arg3;
        return res;
    }
    
    static _new2201(_arg1, _arg2, _arg3, _arg4) {
        let res = new InstrToken(_arg1, _arg2);
        res.typ = _arg3;
        res.ref = _arg4;
        return res;
    }
    
    static _new2205(_arg1, _arg2, _arg3, _arg4) {
        let res = new InstrToken(_arg1, _arg2);
        res.typ = _arg3;
        res.value = _arg4;
        return res;
    }
    
    static _new2207(_arg1, _arg2, _arg3, _arg4, _arg5) {
        let res = new InstrToken(_arg1, _arg2);
        res.typ = _arg3;
        res.ref = _arg4;
        res.value = _arg5;
        return res;
    }
    
    static static_constructor() {
        InstrToken.m_Ontology = null;
        InstrToken.m_Directives = Array.from(["ПРИКАЗЫВАТЬ", "ПРИКАЗАТЬ", "ПРЕДЛАГАТЬ", "ОПРЕДЕЛЯТЬ", "ОПРЕДЕЛЯТЬ", "ОПРЕДЕЛИТЬ", "ПОСТАНОВЛЯТЬ", "ПОСТАНОВИТЬ", "УСТАНОВИТЬ", "РЕШИЛ", "РЕШИТЬ", "ПРОСИТЬ", "ПРИГОВАРИВАТЬ", "ПРИГОВОРИТЬ", "НАКАЗУВАТИ", "ВИЗНАЧАТИ", "ВИЗНАЧИТИ", "УХВАЛЮВАТИ", "УХВАЛИТИ", "ПОСТАНОВЛЯТИ", "ПОСТАНОВИТИ", "ВСТАНОВИТИ", "ВИРІШИВ", "ВИРІШИТИ", "ПРОСИТИ", "ПРИМОВЛЯТИ", "ЗАСУДИТИ"]);
        InstrToken.m_DirectivesNorm = Array.from(["ПРИКАЗ", "ПРИКАЗ", "ПРИКАЗ", "ОПРЕДЕЛЕНИЕ", "ОПРЕДЕЛЕНИЕ", "ОПРЕДЕЛЕНИЕ", "ПОСТАНОВЛЕНИЕ", "ПОСТАНОВЛЕНИЕ", "УСТАНОВЛЕНИЕ", "РЕШЕНИЕ", "РЕШЕНИЕ", "ЗАЯВЛЕНИЕ", "ПРИГОВОР", "ПРИГОВОР", "НАКАЗ", "УХВАЛА", "УХВАЛА", "УХВАЛА", "УХВАЛА", "ПОСТАНОВА", "ПОСТАНОВА", "ВСТАНОВЛЕННЯ", "РІШЕННЯ", "РІШЕННЯ", "ЗАЯВА", "ВИРОК", "ВИРОК"]);
    }
}


InstrToken.static_constructor();

module.exports = InstrToken