1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3 SPDX-FileCopyrightText: 2020 Jonathan Poelen <jonathan.poelen@gmail.com>
4
5 SPDX-License-Identifier: MIT
6*/
7
8#ifndef KSYNTAXHIGHLIGHTING_DEFINITION_P_H
9#define KSYNTAXHIGHLIGHTING_DEFINITION_P_H
10
11#include "definition.h"
12#include "highlightingdata_p.hpp"
13#include "state.h"
14#include "worddelimiters_p.h"
15
16#include <QHash>
17#include <QList>
18#include <QSet>
19#include <QString>
20#include <QVarLengthArray>
21
22#include <vector>
23
24QT_BEGIN_NAMESPACE
25class QCborMap;
26class QXmlStreamReader;
27QT_END_NAMESPACE
28
29namespace KSyntaxHighlighting
30{
31class Repository;
32
33class DefinitionData
34{
35public:
36 DefinitionData();
37 ~DefinitionData();
38
39 DefinitionData(const DefinitionData &) = delete;
40 DefinitionData &operator=(const DefinitionData &) = delete;
41
42 static DefinitionData *get(const Definition &def)
43 {
44 return def.d.get();
45 }
46
47 bool isLoaded() const;
48 bool loadMetaData(const QString &definitionFileName);
49 bool loadMetaData(const QString &fileName, const QCborMap &obj);
50
51 void clear();
52
53 enum class OnlyKeywords : bool;
54
55 bool load(OnlyKeywords onlyKeywords = OnlyKeywords(false));
56 bool loadLanguage(QXmlStreamReader &reader);
57 void loadHighlighting(QXmlStreamReader &reader, OnlyKeywords onlyKeywords);
58 void loadContexts(QXmlStreamReader &reader);
59 void loadItemData(QXmlStreamReader &reader);
60 void loadGeneral(QXmlStreamReader &reader);
61 void loadComments(QXmlStreamReader &reader);
62 void loadFoldingIgnoreList(QXmlStreamReader &reader);
63 void loadSpellchecking(QXmlStreamReader &reader);
64 bool checkKateVersion(QStringView verStr);
65
66 void resolveContexts();
67
68 void resolveIncludeKeywords();
69
70 KeywordList *keywordList(const QString &name);
71
72 Context *initialContext();
73 Context *contextByName(QStringView name);
74
75 Format formatByName(QStringView name) const;
76
77 quint16 foldingRegionId(const QString &foldName);
78
79 struct ResolvedContext {
80 DefinitionData *def;
81 Context *context;
82 };
83
84 ResolvedContext resolveIncludedContext(QStringView defName, QStringView contextName);
85
86 enum class FoldingRegionsState : uint8_t {
87 Undetermined,
88 ContainsFoldingRegions,
89 NoFoldingRegions,
90 };
91
92 std::weak_ptr<DefinitionData> q;
93 uint64_t id = 0;
94
95 Repository *repo = nullptr;
96 QHash<QString, KeywordList> keywordLists;
97 std::vector<Context> contexts;
98 QHash<QStringView, Format> formats;
99 // data loaded from xml file and emptied after loading contexts
100 std::vector<HighlightingContextData> contextDatas;
101 // Definition referenced by IncludeRules and ContextSwitch
102 QVarLengthArray<const DefinitionData *, 4> immediateIncludedDefinitions;
103 WordDelimiters wordDelimiters;
104 WordDelimiters wordWrapDelimiters;
105 bool keywordIsLoaded = false;
106 FoldingRegionsState foldingRegionsState = FoldingRegionsState::Undetermined;
107 bool indentationBasedFolding = false;
108 QStringList foldingIgnoreList;
109 QString singleLineCommentMarker;
110 CommentPosition singleLineCommentPosition = CommentPosition::StartOfLine;
111 QString multiLineCommentStartMarker;
112 QString multiLineCommentEndMarker;
113 QList<QPair<QChar, QString>> characterEncodings;
114
115 QString fileName;
116 QString name = QStringLiteral(QT_TRANSLATE_NOOP("Language", "None"));
117 QStringList alternativeNames;
118 QByteArray nameUtf8;
119 mutable QString translatedName;
120 QString section;
121 QByteArray sectionUtf8;
122 mutable QString translatedSection;
123 QString style;
124 QString indenter;
125 QString author;
126 QString license;
127 QList<QString> mimetypes;
128 QList<QString> extensions;
129 Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive;
130 int version = 0;
131 int priority = 0;
132 bool hidden = false;
133
134 // cache that is used to unify states in AbstractHighlighter::highlightLine
135 mutable QSet<State> unify;
136};
137}
138
139#endif
140

source code of syntax-highlighting/src/lib/definition_p.h