1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "contextswitch_p.h"
8#include "definition.h"
9#include "definition_p.h"
10#include "highlightingdata_p.hpp"
11#include "ksyntaxhighlighting_logging.h"
12#include "repository.h"
13
14using namespace KSyntaxHighlighting;
15
16void ContextSwitch::resolve(DefinitionData &def, QStringView contextInstr)
17{
18 HighlightingContextData::ContextSwitch ctx(contextInstr);
19
20 m_popCount = ctx.popCount();
21 m_isStay = !m_popCount;
22
23 auto contextName = ctx.contextName();
24 auto defName = ctx.defName();
25
26 if (contextName.isEmpty() && defName.isEmpty()) {
27 return;
28 }
29
30 if (defName.isEmpty()) {
31 m_context = def.contextByName(name: contextName);
32 } else {
33 auto d = def.repo->definitionForName(defName: defName.toString());
34 if (d.isValid()) {
35 auto data = DefinitionData::get(def: d);
36 def.addImmediateIncludedDefinition(def: d);
37 data->load();
38 if (contextName.isEmpty()) {
39 m_context = data->initialContext();
40 } else {
41 m_context = data->contextByName(name: contextName);
42 }
43 }
44 }
45
46 if (!m_context) {
47 qCWarning(Log) << "cannot find context" << contextName << "in" << def.name;
48 } else {
49 m_isStay = false;
50 }
51}
52

source code of syntax-highlighting/src/lib/contextswitch.cpp