1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef KSYNTAXHIGHLIGHTING_CONTEXT_P_H
8#define KSYNTAXHIGHLIGHTING_CONTEXT_P_H
9
10#include "contextswitch_p.h"
11#include "format.h"
12#include "highlightingdata_p.hpp"
13#include "rule_p.h"
14
15#include <QString>
16
17#include <vector>
18
19QT_BEGIN_NAMESPACE
20class QXmlStreamReader;
21QT_END_NAMESPACE
22
23namespace KSyntaxHighlighting
24{
25class DefinitionData;
26
27class Context
28{
29public:
30 Q_DISABLE_COPY(Context)
31
32 Context(Context &&) = default;
33 Context &operator=(Context &&) = default;
34
35 Context(const DefinitionData &def, const HighlightingContextData &data);
36 ~Context() = default;
37
38 const QString &name() const
39 {
40 return m_name;
41 }
42
43 const ContextSwitch &lineEndContext() const
44 {
45 return m_lineEndContext;
46 }
47
48 const ContextSwitch &lineEmptyContext() const
49 {
50 return m_lineEmptyContext;
51 }
52
53 bool fallthrough() const
54 {
55 return !m_fallthroughContext.isStay();
56 }
57
58 bool hasDynamicRule() const
59 {
60 return m_hasDynamicRule;
61 }
62
63 bool stopEmptyLineContextSwitchLoop() const
64 {
65 return m_stopEmptyLineContextSwitchLoop;
66 }
67
68 const ContextSwitch &fallthroughContext() const
69 {
70 return m_fallthroughContext;
71 }
72
73 const Format &attributeFormat() const
74 {
75 return m_attributeFormat;
76 }
77
78 const std::vector<Rule::Ptr> &rules() const
79 {
80 return m_rules;
81 }
82
83 /**
84 * Returns @c true, when indentationBasedFolding is enabled for the
85 * associated Definition and when "noIndentationBasedFolding" is NOT set.
86 */
87 bool indentationBasedFoldingEnabled() const;
88
89 void resolveContexts(DefinitionData &def, const HighlightingContextData &data);
90 void resolveIncludes(DefinitionData &def);
91
92private:
93 enum ResolveState : quint8 { Unresolved, Resolving, Resolved };
94
95 std::vector<Rule::Ptr> m_rules;
96
97 QString m_name;
98
99 ContextSwitch m_lineEndContext;
100 ContextSwitch m_lineEmptyContext;
101 ContextSwitch m_fallthroughContext;
102
103 /**
104 * resolved format for our attribute, done in constructor and resolveIncludes
105 */
106 Format m_attributeFormat;
107
108 ResolveState m_resolveState = Unresolved;
109 bool m_hasDynamicRule = false;
110 bool m_stopEmptyLineContextSwitchLoop = true;
111 bool m_indentationBasedFolding;
112};
113}
114
115#endif // KSYNTAXHIGHLIGHTING_CONTEXT_P_H
116

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