File indexing completed on 2024-05-12 04:02:17
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef KSYNTAXHIGHLIGHTING_CONTEXT_P_H 0008 #define KSYNTAXHIGHLIGHTING_CONTEXT_P_H 0009 0010 #include "contextswitch_p.h" 0011 #include "format.h" 0012 #include "highlightingdata_p.hpp" 0013 #include "rule_p.h" 0014 0015 #include <QString> 0016 0017 #include <vector> 0018 0019 namespace KSyntaxHighlighting 0020 { 0021 class DefinitionData; 0022 0023 class Context 0024 { 0025 public: 0026 Q_DISABLE_COPY(Context) 0027 0028 Context(Context &&) = default; 0029 Context &operator=(Context &&) = default; 0030 0031 Context(const DefinitionData &def, const HighlightingContextData &data); 0032 ~Context() = default; 0033 0034 const QString &name() const 0035 { 0036 return m_name; 0037 } 0038 0039 const ContextSwitch &lineEndContext() const 0040 { 0041 return m_lineEndContext; 0042 } 0043 0044 const ContextSwitch &lineEmptyContext() const 0045 { 0046 return m_lineEmptyContext; 0047 } 0048 0049 bool fallthrough() const 0050 { 0051 return !m_fallthroughContext.isStay(); 0052 } 0053 0054 bool hasDynamicRule() const 0055 { 0056 return m_hasDynamicRule; 0057 } 0058 0059 bool stopEmptyLineContextSwitchLoop() const 0060 { 0061 return m_stopEmptyLineContextSwitchLoop; 0062 } 0063 0064 const ContextSwitch &fallthroughContext() const 0065 { 0066 return m_fallthroughContext; 0067 } 0068 0069 const Format &attributeFormat() const 0070 { 0071 return m_attributeFormat; 0072 } 0073 0074 const std::vector<Rule::Ptr> &rules() const 0075 { 0076 return m_rules; 0077 } 0078 0079 /** 0080 * Returns @c true, when indentationBasedFolding is enabled for the 0081 * associated Definition and when "noIndentationBasedFolding" is NOT set. 0082 */ 0083 bool indentationBasedFoldingEnabled() const; 0084 0085 void resolveContexts(DefinitionData &def, const HighlightingContextData &data); 0086 void resolveIncludes(DefinitionData &def); 0087 0088 private: 0089 enum ResolveState : quint8 { Unresolved, Resolving, Resolved }; 0090 0091 std::vector<Rule::Ptr> m_rules; 0092 0093 QString m_name; 0094 0095 ContextSwitch m_lineEndContext; 0096 ContextSwitch m_lineEmptyContext; 0097 ContextSwitch m_fallthroughContext; 0098 0099 /** 0100 * resolved format for our attribute, done in constructor and resolveIncludes 0101 */ 0102 Format m_attributeFormat; 0103 0104 ResolveState m_resolveState = Unresolved; 0105 bool m_hasDynamicRule = false; 0106 bool m_stopEmptyLineContextSwitchLoop = true; 0107 bool m_indentationBasedFolding; 0108 }; 0109 } 0110 0111 #endif // KSYNTAXHIGHLIGHTING_CONTEXT_P_H