aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/syntax-highlighting/src/lib/highlightingdata_p.hpp
blob: f49227dbf9679298c4a4b412e44277ebc45e95ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
    SPDX-FileCopyrightText: 2021 Jonathan Poelen <jonathan.poelen@gmail.com>

    SPDX-License-Identifier: MIT
*/

#ifndef KSYNTAXHIGHLIGHTING_HIGHLIGHTING_DATA_P_H
#define KSYNTAXHIGHLIGHTING_HIGHLIGHTING_DATA_P_H

#include <QString>
#include <QStringList>

#include <vector>

QT_BEGIN_NAMESPACE
class QXmlStreamReader;
QT_END_NAMESPACE

namespace KSyntaxHighlighting
{
/**
 * Represents the raw xml data of a context and its rules.
 * After resolving contexts, members of this class are no longer
 * use and the instance can be freed to recover used memory.
 */
class HighlightingContextData
{
public:
    void load(const QString &defName, QXmlStreamReader &reader);

    struct ContextSwitch {
        ContextSwitch() = default;
        ContextSwitch(QStringView str);

        QStringView contextName() const;
        QStringView defName() const;

        bool isStay() const;

        int popCount() const
        {
            return m_popCount;
        }

    private:
        int m_popCount = 0;
        int m_defNameIndex = -1;
        QString m_contextAndDefName;
    };

    struct Rule {
        enum class Type : quint8 {
            Unknown,
            AnyChar,
            Detect2Chars,
            DetectChar,
            HlCOct,
            IncludeRules,
            Int,
            Keyword,
            LineContinue,
            RangeDetect,
            RegExpr,
            StringDetect,
            WordDetect,
            Float,
            HlCStringChar,
            DetectIdentifier,
            DetectSpaces,
            HlCChar,
            HlCHex,
        };

        struct AnyChar {
            QString chars;
        };

        struct Detect2Chars {
            QChar char1;
            QChar char2;
        };

        struct DetectChar {
            QChar char1;
            bool dynamic;
        };

        struct WordDelimiters {
            QString additionalDeliminator;
            QString weakDeliminator;
        };

        struct Float {
            WordDelimiters wordDelimiters;
        };

        struct HlCHex {
            WordDelimiters wordDelimiters;
        };

        struct HlCOct {
            WordDelimiters wordDelimiters;
        };

        struct IncludeRules {
            QString contextName;
            bool includeAttribute;
        };

        struct Int {
            WordDelimiters wordDelimiters;
        };

        struct Keyword {
            QString name;
            WordDelimiters wordDelimiters;
            Qt::CaseSensitivity caseSensitivityOverride;
            bool hasCaseSensitivityOverride;
        };

        struct LineContinue {
            QChar char1;
        };

        struct RangeDetect {
            QChar begin;
            QChar end;
        };

        struct RegExpr {
            QString pattern;
            Qt::CaseSensitivity caseSensitivity;
            bool isMinimal;
            bool dynamic;
        };

        struct StringDetect {
            QString string;
            Qt::CaseSensitivity caseSensitivity;
            bool dynamic;
        };

        struct WordDetect {
            QString word;
            WordDelimiters wordDelimiters;
            Qt::CaseSensitivity caseSensitivity;
        };

        union Data {
            AnyChar anyChar;
            Detect2Chars detect2Chars;
            DetectChar detectChar;
            HlCOct hlCOct;
            IncludeRules includeRules;
            Int detectInt;
            Keyword keyword;
            LineContinue lineContinue;
            RangeDetect rangeDetect;
            RegExpr regExpr;
            StringDetect stringDetect;
            WordDetect wordDetect;
            Float detectFloat;
            HlCHex hlCHex;

            Data() noexcept
            {
            }

            ~Data()
            {
            }
        };

        struct Common {
            QString contextName;
            QString attributeName;
            QString beginRegionName;
            QString endRegionName;
            int column = -1;
            bool firstNonSpace = false;
            bool lookAhead = false;
        };

        Type type = Type::Unknown;
        Common common;
        Data data;

        Rule() noexcept;
        Rule(Rule &&other) noexcept;
        Rule(const Rule &other);
        ~Rule();

        // since nothing is deleted in the rules vector, these functions do not need to be implemented
        Rule &operator=(Rule &&other) = delete;
        Rule &operator=(const Rule &other) = delete;
    };

    QString name;

    /**
     * attribute name, to lookup our format
     */
    QString attribute;

    QString lineEndContext;
    QString lineEmptyContext;
    QString fallthroughContext;

    std::vector<Rule> rules;

    bool stopEmptyLineContextSwitchLoop = false;
    bool noIndentationBasedFolding = false;
};
}

#endif