KSyntaxHighlighting

contextswitch.cpp
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(contextName);
32 } else {
33 auto d = def.repo->definitionForName(defName.toString());
34 if (d.isValid()) {
35 auto data = DefinitionData::get(d);
36 def.addImmediateIncludedDefinition(d);
37 data->load();
38 if (contextName.isEmpty()) {
39 m_context = data->initialContext();
40 } else {
41 m_context = data->contextByName(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}
Syntax highlighting engine for Kate syntax definitions.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:29 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.