/*
 * 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 BracketParseAttr = require("./../../core/BracketParseAttr");
const NumberToken = require("./../../NumberToken");
const PartTokenItemType = require("./../../decree/internal/PartTokenItemType");
const DecreeReferent = require("./../../decree/DecreeReferent");
const LanguageHelper = require("./../../../morph/LanguageHelper");
const NumberTypes = require("./NumberTypes");
const CanBeEqualsAttr = require("./../../core/CanBeEqualsAttr");
const MetaToken = require("./../../MetaToken");
const InstrToken1Types = require("./InstrToken1Types");
const TextToken = require("./../../TextToken");
const MiscHelper = require("./../../core/MiscHelper");
const BracketHelper = require("./../../core/BracketHelper");
const DecreeChangeKind = require("./../../decree/DecreeChangeKind");
const InstrumentKind = require("./../InstrumentKind");
const DecreeChangeReferent = require("./../../decree/DecreeChangeReferent");
const DecreePartReferent = require("./../../decree/DecreePartReferent");
const PartToken = require("./../../decree/internal/PartToken");
const InstrToken1 = require("./InstrToken1");
const FragToken = require("./FragToken");
const ContentAnalyzeWhapper = require("./ContentAnalyzeWhapper");

class ListHelper {
    
    static analyze(res) {
        if (res.number === 4) {
        }
        if (res.children.length === 0) {
            let ki = res.kind;
            if (((ki === InstrumentKind.CHAPTER || ki === InstrumentKind.CLAUSE || ki === InstrumentKind.CONTENT) || ki === InstrumentKind.ITEM || ki === InstrumentKind.SUBITEM) || ki === InstrumentKind.CLAUSEPART || ki === InstrumentKind.INDENTION) {
                let tmp = new Array();
                tmp.push(res);
                ListHelper._analizeListItems(tmp, 0);
            }
            return;
        }
        if (res.kind === InstrumentKind.CLAUSE && res.number === 12) {
        }
        for (let i = 0; i < res.children.length; i++) {
            if (res.children[i].kind === InstrumentKind.INDENTION && ((res.children[i].endToken.isCharOf(":;") || ((((i + 1) < res.children.length) && res.children[i + 1].kind === InstrumentKind.EDITIONS && res.children[i + 1].endToken.isCharOf(":;")))))) {
                let j = 0;
                let cou = 1;
                let listBullet = String.fromCharCode(0);
                for (j = i + 1; j < res.children.length; j++) {
                    let ch = res.children[j];
                    if (ch.kind === InstrumentKind.COMMENT || ch.kind === InstrumentKind.EDITIONS) 
                        continue;
                    if (ch.kind !== InstrumentKind.INDENTION) 
                        break;
                    if (ch.endToken.isCharOf(";") || ((((j + 1) < res.children.length) && res.children[j + 1].kind === InstrumentKind.EDITIONS && res.children[j + 1].endToken.isChar(';')))) {
                        cou++;
                        if ((ch.beginToken instanceof TextToken) && !ch.chars.isLetter) 
                            listBullet = ch.kit.getTextCharacter(ch.beginChar);
                        continue;
                    }
                    if (ch.endToken.isCharOf(".")) {
                        cou++;
                        j++;
                        break;
                    }
                    if (ch.endToken.isCharOf(":")) {
                        if ((listBullet.charCodeAt(0)) !== 0 && ch.beginToken.isChar(listBullet)) {
                            for (let tt = ch.beginToken.next; tt !== null && (tt.endChar < ch.endChar); tt = tt.next) {
                                if (tt.previous.isChar('.') && MiscHelper.canBeStartOfSentence(tt)) {
                                    let ch2 = FragToken._new2024(tt, ch.endToken, InstrumentKind.INDENTION, ch.number);
                                    ch.endToken = tt.previous;
                                    res.children.splice(j + 1, 0, ch2);
                                    for (let k = j + 1; k < res.children.length; k++) {
                                        if (res.children[k].kind === InstrumentKind.INDENTION) 
                                            res.children[k].number++;
                                    }
                                    cou++;
                                    j++;
                                    break;
                                }
                            }
                        }
                        break;
                    }
                    cou++;
                    j++;
                    break;
                }
                if (cou < 3) {
                    i = j;
                    continue;
                }
                if ((i > 0 && !res.children[i].endToken.isChar(':') && res.children[i - 1].kind2 === InstrumentKind.UNDEFINED) && res.children[i - 1].endToken.isChar(':')) 
                    res.children[i - 1].kind2 = InstrumentKind.LISTHEAD;
                for (; i < j; i++) {
                    let ch = res.children[i];
                    if (ch.kind !== InstrumentKind.INDENTION) 
                        continue;
                    if (ch.endToken.isChar(':')) 
                        ch.kind2 = InstrumentKind.LISTHEAD;
                    else if (((i + 1) < j) && res.children[i + 1].kind === InstrumentKind.EDITIONS && res.children[i + 1].endToken.isChar(':')) 
                        ch.kind2 = InstrumentKind.LISTHEAD;
                    else 
                        ch.kind2 = InstrumentKind.LISTITEM;
                }
            }
        }
        let changed = new Array();
        for (let i = 0; i < res.children.length; i++) {
            if (res.number === 7) {
            }
            if (res.children[i].children.length > 0) 
                ListHelper.analyze(res.children[i]);
            else {
                let co = ListHelper._analizeListItems(res.children, i);
                if (co > 0) {
                    changed.push(res.children[i]);
                    if (co > 1) 
                        res.children.splice(i + 1, co - 1);
                    i += (co - 1);
                }
            }
        }
        for (let i = changed.length - 1; i >= 0; i--) {
            if (changed[i].kind === InstrumentKind.CONTENT) {
                let j = res.children.indexOf(changed[i]);
                if (j < 0) 
                    continue;
                res.children.splice(j, 1);
                res.children.splice(j, 0, ...changed[i].children);
            }
        }
    }
    
    static _analizeListItems(chi, ind) {
        if (ind >= chi.length) 
            return -1;
        let res = chi[ind];
        let ki = res.kind;
        if (((ki === InstrumentKind.CHAPTER || ki === InstrumentKind.CLAUSE || ki === InstrumentKind.CONTENT) || ki === InstrumentKind.ITEM || ki === InstrumentKind.SUBITEM) || ki === InstrumentKind.CLAUSEPART || ki === InstrumentKind.INDENTION) {
        }
        else 
            return -1;
        if (res.hasChanges && res.multilineChangesValue !== null) {
            let ci = res.multilineChangesValue;
            let cit = FragToken._new2000(ci.beginToken, ci.endToken, InstrumentKind.CITATION);
            res.children.push(cit);
            if (BracketHelper.isBracket(cit.beginToken.previous, true)) 
                cit.beginToken = cit.beginToken.previous;
            if (BracketHelper.isBracket(cit.endToken.next, true)) {
                cit.endToken = cit.endToken.next;
                if (cit.endToken.next !== null && cit.endToken.next.isCharOf(";.")) 
                    cit.endToken = cit.endToken.next;
            }
            res.fillByContentChildren();
            if (res.children[0].hasChanges) {
            }
            let citKind = InstrumentKind.UNDEFINED;
            if (ci.tag instanceof DecreeChangeReferent) {
                let dcr = Utils.as(ci.tag, DecreeChangeReferent);
                if (dcr.value !== null && dcr.value.newItems.length > 0) {
                    let mnem = dcr.value.newItems[0];
                    let i = 0;
                    if ((((i = mnem.indexOf(' ')))) > 0) 
                        mnem = mnem.substring(0, 0 + i);
                    citKind = PartToken._getInstrKindByTyp(PartToken._getTypeByAttrName(mnem));
                }
                else if (dcr.owners.length > 0 && (dcr.owners[0] instanceof DecreePartReferent) && dcr.kind === DecreeChangeKind.NEW) {
                    let pat = Utils.as(dcr.owners[0], DecreePartReferent);
                    let min = 0;
                    for (const s of pat.slots) {
                        let ty = PartToken._getTypeByAttrName(s.typeName);
                        if (ty === PartTokenItemType.UNDEFINED) 
                            continue;
                        let l = PartToken._getRank(ty);
                        if (l === 0) 
                            continue;
                        if (l > min || min === 0) {
                            min = l;
                            citKind = PartToken._getInstrKindByTyp(ty);
                        }
                    }
                }
            }
            let sub = null;
            if (citKind !== InstrumentKind.UNDEFINED && citKind !== InstrumentKind.APPENDIX) {
                sub = new FragToken(ci.beginToken, ci.endToken);
                let wr = new ContentAnalyzeWhapper();
                wr.analyze(sub, null, true, citKind);
                sub.kind = InstrumentKind.CONTENT;
            }
            else 
                sub = FragToken.createDocument(ci.beginToken, ci.endChar, citKind);
            if (sub === null || sub.children.length === 0) {
            }
            else if ((sub.kind === InstrumentKind.CONTENT && sub.children.length > 0 && sub.children[0].beginToken === sub.beginToken) && sub.children[sub.children.length - 1].endToken === sub.endToken) 
                cit.children.splice(cit.children.length, 0, ...sub.children);
            else 
                cit.children.push(sub);
            return 1;
        }
        let endChar = res.endChar;
        if (res.itok === null) 
            res.itok = InstrToken1.parse(res.beginToken, true, null, 0, null, false, res.endChar, false, false);
        let lines = ListHelper.LineToken.parseList(res.beginToken, endChar, null);
        if (lines === null || (lines.length < 1)) 
            return -1;
        let ret = 1;
        if (res.kind === InstrumentKind.CONTENT) {
            for (let j = ind + 1; j < chi.length; j++) {
                if (chi[j].kind === InstrumentKind.CONTENT) {
                    let lines2 = ListHelper.LineToken.parseList(chi[j].beginToken, chi[j].endChar, lines[lines.length - 1]);
                    if (lines2 === null || (lines2.length < 1)) 
                        break;
                    if (!lines2[0].isListItem) {
                        if ((lines2.length > 1 && lines2[1].isListItem && lines2[0].endToken.isCharOf(":")) && !lines2[0].beginToken.chars.isCapitalUpper) 
                            lines2[0].isListItem = true;
                        else 
                            break;
                    }
                    lines.splice(lines.length, 0, ...lines2);
                    ret = (j - ind) + 1;
                }
                else if (chi[j].kind !== InstrumentKind.EDITIONS && chi[j].kind !== InstrumentKind.COMMENT) 
                    break;
            }
        }
        if (lines.length < 2) 
            return -1;
        if ((lines.length > 1 && lines[0].isListItem && lines[1].isListItem) && lines[0].number !== 1) {
            if (lines.length === 2 || !lines[2].isListItem) 
                lines[0].isListItem = (lines[1].isListItem = false);
        }
        for (let i = 0; i < lines.length; i++) {
            if (lines[i].isListItem) {
                if (i > 0 && lines[i - 1].isListItem) 
                    continue;
                if (((i + 1) < lines.length) && lines[i + 1].isListItem) {
                }
                else {
                    lines[i].isListItem = false;
                    continue;
                }
                let j = 0;
                let newLine = false;
                for (j = i + 1; j < lines.length; j++) {
                    if (!lines[j].isListItem) 
                        break;
                    else if (lines[j].isNewlineBefore) 
                        newLine = true;
                }
                if (newLine) 
                    continue;
                if (i > 0 && lines[i - 1].endToken.isChar(':')) 
                    continue;
                for (j = i; j < lines.length; j++) {
                    if (!lines[j].isListItem) 
                        break;
                    else 
                        lines[j].isListItem = false;
                }
            }
        }
        if (lines.length > 2) {
            let last = lines[lines.length - 1];
            let last2 = lines[lines.length - 2];
            if ((!last.isListItem && last.endToken.isChar('.') && last2.isListItem) && last2.endToken.isChar(';')) {
                if ((last.lengthChar < (last2.lengthChar * 2)) || last.beginToken.chars.isAllLower) 
                    last.isListItem = true;
            }
        }
        for (let i = 0; i < (lines.length - 1); i++) {
            if (!lines[i].isListItem && !lines[i + 1].isListItem) {
                if (((i + 2) < lines.length) && lines[i + 2].isListItem && lines[i + 1].endToken.isChar(':')) {
                }
                else {
                    lines[i].endToken = lines[i + 1].endToken;
                    lines.splice(i + 1, 1);
                    i--;
                }
            }
        }
        for (let i = 0; i < (lines.length - 1); i++) {
            if (lines[i].isListItem) {
                if (lines[i].number === 1) {
                    let ok = true;
                    let num = 1;
                    let nonum = 0;
                    for (let j = i + 1; j < lines.length; j++) {
                        if (!lines[j].isListItem) {
                            ok = false;
                            break;
                        }
                        else if (lines[j].number > 0) {
                            num++;
                            if (lines[j].number !== num) {
                                ok = false;
                                break;
                            }
                        }
                        else 
                            nonum++;
                    }
                    if (!ok || nonum === 0 || (num < 2)) 
                        break;
                    let lt = lines[i];
                    for (let j = i + 1; j < lines.length; j++) {
                        if (lines[j].number > 0) 
                            lt = lines[j];
                        else {
                            let chli = Utils.as(lt.tag, Array);
                            if (chli === null) 
                                lt.tag = (chli = new Array());
                            lt.endToken = lines[j].endToken;
                            chli.push(lines[j]);
                            lines.splice(j, 1);
                            j--;
                        }
                    }
                }
            }
        }
        let cou = 0;
        for (const li of lines) {
            if (li.isListItem) 
                cou++;
        }
        if (cou < 2) 
            return -1;
        for (let i = 0; i < lines.length; i++) {
            if (lines[i].isListItem) {
                let i0 = i;
                let ok = true;
                cou = 1;
                for (; i < lines.length; i++,cou++) {
                    if (!lines[i].isListItem) 
                        break;
                    else if (lines[i].number !== cou) 
                        ok = false;
                }
                if (!ok) {
                    for (i = i0; i < lines.length; i++) {
                        if (!lines[i].isListItem) 
                            break;
                        else 
                            lines[i].number = 0;
                    }
                }
                if (cou > 3 && lines[i0].beginToken.getSourceText() !== lines[i0 + 1].beginToken.getSourceText() && lines[i0 + 1].beginToken.getSourceText() === lines[i0 + 2].beginToken.getSourceText()) {
                    let pref = lines[i0 + 1].beginToken.getSourceText();
                    ok = true;
                    for (let j = i0 + 2; j < i; j++) {
                        if (pref !== lines[j].beginToken.getSourceText()) {
                            ok = false;
                            break;
                        }
                    }
                    if (!ok) 
                        continue;
                    let tt = null;
                    ok = false;
                    for (tt = lines[i0].endToken.previous; tt !== null && tt !== lines[i0].beginToken; tt = tt.previous) {
                        if (tt.getSourceText() === pref) {
                            ok = true;
                            break;
                        }
                    }
                    if (ok) {
                        let li0 = new ListHelper.LineToken(lines[i0].beginToken, tt.previous);
                        lines[i0].beginToken = tt;
                        lines.splice(i0, 0, li0);
                        i++;
                    }
                }
            }
        }
        for (const li of lines) {
            li.correctBeginToken();
            let ch = FragToken._new2024(li.beginToken, li.endToken, (li.isListItem ? InstrumentKind.LISTITEM : InstrumentKind.CONTENT), li.number);
            if (ch.kind === InstrumentKind.CONTENT && ch.endToken.isChar(':')) 
                ch.kind = InstrumentKind.LISTHEAD;
            res.children.push(ch);
            let chli = Utils.as(li.tag, Array);
            if (chli !== null) {
                for (const lt of chli) {
                    ch.children.push(FragToken._new2000(lt.beginToken, lt.endToken, InstrumentKind.LISTITEM));
                }
                if (ch.beginChar < ch.children[0].beginChar) 
                    ch.children.splice(0, 0, FragToken._new2000(ch.beginToken, ch.children[0].beginToken.previous, InstrumentKind.CONTENT));
            }
        }
        return ret;
    }
    
    static correctAppList(lines) {
        for (let i = 0; i < (lines.length - 1); i++) {
            if ((lines[i].typ === InstrToken1Types.LINE && lines[i].numbers.length === 0 && lines[i].beginToken.isValue("ПРИЛОЖЕНИЯ", "ДОДАТОК")) && lines[i + 1].numbers.length > 0 && lines[i].endToken.isChar(':')) {
                let num = 1;
                for (++i; i < lines.length; i++) {
                    if (lines[i].numbers.length === 0) {{
                                if (((i + 1) < lines.length) && lines[i + 1].numbers.length === 1 && lines[i + 1].numbers[0] === num.toString()) {
                                    lines[i - 1].endToken = lines[i].endToken;
                                    lines.splice(i, 1);
                                    i--;
                                    continue;
                                }
                            }
                        break;
                    }
                    else {
                        let nn = 0;
                        let wrapnn2244 = new RefOutArgWrapper();
                        let inoutres2245 = Utils.tryParseInt(lines[i].numbers[0], wrapnn2244);
                        nn = wrapnn2244.value;
                        if (inoutres2245) 
                            num = nn + 1;
                        lines[i].numTyp = NumberTypes.UNDEFINED;
                        lines[i].numbers.splice(0, lines[i].numbers.length);
                    }
                }
            }
        }
        let emptyApps = 0;
        let apps = 0;
        for (let i = 0; i < lines.length; i++) {
            let line = lines[i];
            if (line.typ !== InstrToken1Types.APPENDIX) 
                continue;
            apps++;
            let j = 0;
            for (j = i + 1; j < lines.length; j++) {
                if (lines[j].typ === InstrToken1Types.APPENDIX) 
                    break;
            }
            if (j >= lines.length) 
                break;
            if ((j - i) < 3) 
                emptyApps++;
            i = j - 1;
        }
        if (emptyApps > 1 && emptyApps === (apps - 1)) {
            for (let i = 0; i < lines.length; i++) {
                let line = lines[i];
                if (line.typ !== InstrToken1Types.APPENDIX) 
                    continue;
                line.typ = InstrToken1Types.LINE;
                line.numbers.splice(0, line.numbers.length);
                line.numTyp = NumberTypes.UNDEFINED;
            }
        }
    }
    
    static correctIndex(lines) {
        if (lines.length < 10) 
            return;
        if (lines[0].typ === InstrToken1Types.CLAUSE || lines[0].typ === InstrToken1Types.CHAPTER) {
        }
        else 
            return;
        let index = new Array();
        index.push(lines[0]);
        let content = new Array();
        let i = 0;
        let indText = 0;
        let conText = 0;
        for (i = 1; i < lines.length; i++) {
            if (lines[i].typ === lines[0].typ) {
                if (ListHelper._canBeEquals(lines[i], lines[0])) 
                    break;
                else 
                    index.push(lines[i]);
            }
            else 
                indText += lines[i].lengthChar;
        }
        let cInd = i;
        for (; i < lines.length; i++) {
            if (lines[i].typ === lines[0].typ) 
                content.push(lines[i]);
            else 
                conText += lines[i].lengthChar;
        }
        if (index.length === content.length && index.length > 2) {
            if ((indText * 10) < conText) {
                lines[0] = InstrToken1._new2246(lines[0].beginToken, lines[cInd - 1].endToken, true, InstrToken1Types.INDEX);
                lines.splice(1, cInd - 1);
            }
        }
    }
    
    static _canBeEquals(i1, i2) {
        if (i1.typ !== i2.typ) 
            return false;
        if (i1.numbers.length > 0 && i2.numbers.length > 0) {
            if (i1.numbers.length !== i2.numbers.length) 
                return false;
            for (let i = 0; i < i1.numbers.length; i++) {
                if (i1.numbers[i] !== i2.numbers[i]) 
                    return false;
            }
        }
        if (!MiscHelper.canBeEqualsEx(i1.value, i2.value, CanBeEqualsAttr.of((CanBeEqualsAttr.IGNORENONLETTERS.value()) | (CanBeEqualsAttr.IGNOREUPPERCASE.value())))) 
            return false;
        return true;
    }
}


ListHelper.LineToken = class  extends MetaToken {
    
    constructor(b, e) {
        super(b, e, null);
        this.isListItem = false;
        this.isListHead = false;
        this.number = 0;
    }
    
    correctBeginToken() {
        if (!this.isListItem) 
            return;
        if (this.beginToken.isHiphen && this.beginToken.next !== null && (this.beginToken.next.endChar < this.endChar)) 
            this.beginToken = this.beginToken.next;
        else if ((this.number > 0 && this.beginToken.next !== null && this.beginToken.next.isChar(')')) && this.beginToken.next.next !== null && (this.beginToken.next.next.endChar < this.endChar)) 
            this.beginToken = this.beginToken.next.next;
    }
    
    toString() {
        return ((this.isListItem ? "LISTITEM" : "TEXT") + ": " + this.getSourceText());
    }
    
    static parse(t, maxChar, prev) {
        const LanguageHelper = require("./../../../morph/LanguageHelper");
        const NumberToken = require("./../../NumberToken");
        const TextToken = require("./../../TextToken");
        const BracketHelper = require("./../../core/BracketHelper");
        const BracketParseAttr = require("./../../core/BracketParseAttr");
        const DecreeReferent = require("./../../decree/DecreeReferent");
        if (t === null || t.endChar > maxChar) 
            return null;
        let res = new ListHelper.LineToken(t, t);
        for (; t !== null && t.endChar <= maxChar; t = t.next) {
            if (t.isChar(':')) {
                if (res.isNewlineBefore && res.beginToken.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК")) 
                    res.isListHead = true;
                res.endToken = t;
                break;
            }
            if (t.isChar(';')) {
                if (!t.isWhitespaceAfter) {
                }
                if (t.previous !== null && (t.previous.getReferent() instanceof DecreeReferent)) {
                    if (!t.isWhitespaceAfter) 
                        continue;
                    if (t.next !== null && (t.next.getReferent() instanceof DecreeReferent)) 
                        continue;
                }
                res.isListItem = true;
                res.endToken = t;
                break;
            }
            if (t.isChar('(')) {
                let br = BracketHelper.tryParse(t, BracketParseAttr.NO, 100);
                if (br !== null) {
                    res.endToken = (t = br.endToken);
                    continue;
                }
            }
            if (t.isNewlineBefore && t !== res.beginToken) {
                let _next = true;
                if (t.previous.isComma || t.previous.isAnd || t.isCharOf("(")) 
                    _next = false;
                else if (t.chars.isLetter || (t instanceof NumberToken)) {
                    if (t.chars.isAllLower) 
                        _next = false;
                    else if (t.previous.chars.isLetter) 
                        _next = false;
                }
                if (_next) 
                    break;
            }
            res.endToken = t;
        }
        if (res.beginToken.isHiphen) 
            res.isListItem = res.beginToken.next !== null && !res.beginToken.next.isHiphen;
        else if (res.beginToken.isCharOf("·")) {
            res.isListItem = true;
            res.beginToken = res.beginToken.next;
        }
        else if (res.beginToken.next !== null && ((res.beginToken.next.isChar(')') || ((prev !== null && ((prev.isListItem || prev.isListHead))))))) {
            if (res.beginToken.lengthChar === 1 || (res.beginToken instanceof NumberToken)) {
                res.isListItem = true;
                if ((res.beginToken instanceof NumberToken) && res.beginToken.intValue !== null) 
                    res.number = res.beginToken.intValue;
                else if ((res.beginToken instanceof TextToken) && res.beginToken.lengthChar === 1) {
                    let te = res.beginToken.term;
                    if (LanguageHelper.isCyrillicChar(te[0])) 
                        res.number = (te.charCodeAt(0)) - ('А'.charCodeAt(0));
                    else if (LanguageHelper.isLatinChar(te[0])) 
                        res.number = (te.charCodeAt(0)) - ('A'.charCodeAt(0));
                }
            }
        }
        return res;
    }
    
    static parseList(t, maxChar, prev) {
        let lt = ListHelper.LineToken.parse(t, maxChar, prev);
        if (lt === null) 
            return null;
        let res = new Array();
        res.push(lt);
        let ss = lt.toString();
        for (t = lt.endToken.next; t !== null; t = t.next) {
            let lt0 = ListHelper.LineToken.parse(t, maxChar, lt);
            if (lt0 === null) 
                break;
            res.push((lt = lt0));
            t = lt0.endToken;
        }
        if ((res.length < 2) && !res[0].isListItem) {
            if ((prev !== null && prev.isListItem && res[0].endToken.isChar('.')) && !res[0].beginToken.chars.isCapitalUpper) {
                res[0].isListItem = true;
                return res;
            }
            return null;
        }
        let i = 0;
        for (i = 0; i < res.length; i++) {
            if (res[i].isListItem) 
                break;
        }
        if (i >= res.length) 
            return null;
        let j = 0;
        let cou = 0;
        for (j = i; j < res.length; j++) {
            if (!res[j].isListItem) {
                if (res[j - 1].isListItem && res[j].endToken.isChar('.')) {
                    if (res[j].beginToken.getSourceText() === res[i].beginToken.getSourceText() || res[j].beginToken.chars.isAllLower) {
                        res[j].isListItem = true;
                        j++;
                        cou++;
                    }
                }
            }
            else 
                cou++;
        }
        return res;
    }
}


module.exports = ListHelper