static extractFileContent()

in parsers/LU/JS/packages/lu/src/parser/lufile/luParser.js [51:161]


    static extractFileContent(fileContent, content, errors, sectionEnabled) {
        let sections = [];
        try {
            let modelInfoSections = this.extractModelInfoSections(fileContent);
            modelInfoSections.forEach(section => errors = errors.concat(section.Errors));
            sections = sections.concat(modelInfoSections);
        } catch (err) {
            errors.push(BuildDiagnostic({
                message: `Error happened when parsing model information: ${err.message}`
            }))
        }

        try {
            let isSectionEnabled = sectionEnabled === undefined ?  this.isSectionEnabled(sections) : sectionEnabled;

            let nestedIntentSections = this.extractNestedIntentSections(fileContent, content);
            nestedIntentSections.forEach(section => errors = errors.concat(section.Errors));
            if (isSectionEnabled) {
                sections = sections.concat(nestedIntentSections);
            } else {
                nestedIntentSections.forEach(section => {
                    let emptyIntentSection = new SimpleIntentSection();
                    emptyIntentSection.Name = section.Name;
                    emptyIntentSection.Id = `${emptyIntentSection.SectionType}_${emptyIntentSection.Name}`
                    
                    // get the end character index
                    // this is default value
                    // it will be reset in function extractSectionBody()
                    let endCharacter = section.Name.length + 2;
                   
                    const range = new Range(section.Range.Start, new Position(section.Range.Start.Line, endCharacter))
                    emptyIntentSection.Range = range;
                    let errorMsg = `no utterances found for intent definition: "# ${emptyIntentSection.Name}"`
                    let error = BuildDiagnostic({
                        message: errorMsg,
                        range: emptyIntentSection.Range,
                        severity: DiagnosticSeverity.WARN
                    })

                    errors.push(error);
                    sections.push(emptyIntentSection);

                    section.SimpleIntentSections.forEach(subSection => {
                        sections.push(subSection);
                        errors = errors.concat(subSection.Errors);
                    })
                });
            }
        } catch (err) {
            errors.push(BuildDiagnostic({
                message: `Error happened when parsing nested intent section: ${err.message}`
            }))
        }

        try {
            let simpleIntentSections = this.extractSimpleIntentSections(fileContent, content);
            simpleIntentSections.forEach(section => errors = errors.concat(section.Errors));
            sections = sections.concat(simpleIntentSections);
        } catch (err) {
            errors.push(BuildDiagnostic({
                message: `Error happened when parsing simple intent section: ${err.message}`
            }))
        }

        try {
            let entitySections = this.extractEntitiesSections(fileContent);
            entitySections.forEach(section => errors = errors.concat(section.Errors));
            sections = sections.concat(entitySections);
        } catch (err) {
            errors.push(BuildDiagnostic({
                message: `Error happened when parsing entities: ${err.message}`
            }))
        }

        try {
            let newEntitySections = this.extractNewEntitiesSections(fileContent);
            newEntitySections.forEach(section => errors = errors.concat(section.Errors));
            sections = sections.concat(newEntitySections);
        } catch (err) {
            errors.push(BuildDiagnostic({
                message: `Error happened when parsing new entities: ${err.message}`
            }))
        }

        try {
            let importSections = this.extractImportSections(fileContent);
            importSections.forEach(section => errors = errors.concat(section.Errors));
            sections = sections.concat(importSections);
        } catch (err) {
            errors.push(BuildDiagnostic({
                message: `Error happened when parsing import section: ${err.message}`
            }))
        }

        try {
            let qnaSections = this.extractQnaSections(fileContent);
            qnaSections.forEach(section => errors = errors.concat(section.Errors));
            sections = sections.concat(qnaSections);
        } catch (err) {
            errors.push(BuildDiagnostic({
                message: `Error happened when parsing qna section: ${err.message}`
            }))
        }

        sections = this.reconstractIntentSections(sections)

        this.extractSectionBody(sections, content)
        console.log(JSON.stringify({sections, content, errors}))

        return new LUResource(sections, content, errors);
    }