File indexing completed on 2024-05-12 15:50:03

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include "contextswitch_p.h"
0008 #include "definition.h"
0009 #include "definition_p.h"
0010 #include "highlightingdata_p.hpp"
0011 #include "ksyntaxhighlighting_logging.h"
0012 #include "repository.h"
0013 
0014 using namespace KSyntaxHighlighting;
0015 
0016 void ContextSwitch::resolve(DefinitionData &def, QStringView contextInstr)
0017 {
0018     HighlightingContextData::ContextSwitch ctx(contextInstr);
0019 
0020     m_popCount = ctx.popCount();
0021     m_isStay = !m_popCount;
0022 
0023     auto contextName = ctx.contextName();
0024     auto defName = ctx.defName();
0025 
0026     if (contextName.isEmpty() && defName.isEmpty()) {
0027         return;
0028     }
0029 
0030     if (defName.isEmpty()) {
0031         m_context = def.contextByName(contextName);
0032     } else {
0033         auto d = def.repo->definitionForName(defName.toString());
0034         if (d.isValid()) {
0035             auto data = DefinitionData::get(d);
0036             def.addImmediateIncludedDefinition(d);
0037             data->load();
0038             if (contextName.isEmpty()) {
0039                 m_context = data->initialContext();
0040             } else {
0041                 m_context = data->contextByName(contextName);
0042             }
0043         }
0044     }
0045 
0046     if (!m_context) {
0047         qCWarning(Log) << "cannot find context" << contextName << "in" << def.name;
0048     } else {
0049         m_isStay = false;
0050     }
0051 }