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