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 "definitionref_p.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 | |
21 | #include <vector> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | class QCborMap; |
25 | class QXmlStreamReader; |
26 | QT_END_NAMESPACE |
27 | |
28 | namespace KSyntaxHighlighting |
29 | { |
30 | class Repository; |
31 | |
32 | class DefinitionData |
33 | { |
34 | public: |
35 | DefinitionData(); |
36 | ~DefinitionData(); |
37 | |
38 | DefinitionData(const DefinitionData &) = delete; |
39 | DefinitionData &operator=(const DefinitionData &) = delete; |
40 | |
41 | static DefinitionData *get(const Definition &def) |
42 | { |
43 | return def.d.get(); |
44 | } |
45 | |
46 | bool isLoaded() const; |
47 | bool loadMetaData(const QString &definitionFileName); |
48 | bool loadMetaData(const QString &fileName, const QCborMap &obj); |
49 | |
50 | void clear(); |
51 | |
52 | enum class OnlyKeywords : bool; |
53 | |
54 | bool load(OnlyKeywords onlyKeywords = OnlyKeywords(false)); |
55 | bool loadLanguage(QXmlStreamReader &reader); |
56 | void loadHighlighting(QXmlStreamReader &reader, OnlyKeywords onlyKeywords); |
57 | void loadContexts(QXmlStreamReader &reader); |
58 | void loadItemData(QXmlStreamReader &reader); |
59 | void loadGeneral(QXmlStreamReader &reader); |
60 | void (QXmlStreamReader &reader); |
61 | void loadFoldingIgnoreList(QXmlStreamReader &reader); |
62 | void loadSpellchecking(QXmlStreamReader &reader); |
63 | bool checkKateVersion(QStringView verStr); |
64 | |
65 | void resolveContexts(); |
66 | |
67 | void resolveIncludeKeywords(); |
68 | |
69 | KeywordList *keywordList(const QString &name); |
70 | |
71 | Context *initialContext(); |
72 | Context *contextByName(QStringView name); |
73 | |
74 | Format formatByName(const QString &name) const; |
75 | |
76 | quint16 foldingRegionId(const QString &foldName); |
77 | |
78 | void addImmediateIncludedDefinition(const Definition &def); |
79 | |
80 | DefinitionRef q; |
81 | uint64_t id = 0; |
82 | |
83 | Repository *repo = nullptr; |
84 | QHash<QString, KeywordList> keywordLists; |
85 | std::vector<Context> contexts; |
86 | QHash<QString, Format> formats; |
87 | // data loaded from xml file and emptied after loading contexts |
88 | QList<HighlightingContextData> contextDatas; |
89 | // Definition referenced by IncludeRules and ContextSwitch |
90 | QList<DefinitionRef> immediateIncludedDefinitions; |
91 | WordDelimiters wordDelimiters; |
92 | WordDelimiters wordWrapDelimiters; |
93 | bool keywordIsLoaded = false; |
94 | bool hasFoldingRegions = false; |
95 | bool indentationBasedFolding = false; |
96 | QStringList foldingIgnoreList; |
97 | QString ; |
98 | CommentPosition = CommentPosition::StartOfLine; |
99 | QString ; |
100 | QString ; |
101 | QList<QPair<QChar, QString>> characterEncodings; |
102 | |
103 | QString fileName; |
104 | QString name = QStringLiteral(QT_TRANSLATE_NOOP("Language" , "None" )); |
105 | QStringList alternativeNames; |
106 | QByteArray nameUtf8; |
107 | mutable QString translatedName; |
108 | QString section; |
109 | QByteArray sectionUtf8; |
110 | mutable QString translatedSection; |
111 | QString style; |
112 | QString indenter; |
113 | QString author; |
114 | QString license; |
115 | QList<QString> mimetypes; |
116 | QList<QString> extensions; |
117 | Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive; |
118 | int version = 0; |
119 | int priority = 0; |
120 | bool hidden = false; |
121 | |
122 | // cache that is used to unify states in AbstractHighlighter::highlightLine |
123 | mutable QSet<State> unify; |
124 | }; |
125 | } |
126 | |
127 | #endif |
128 | |