File indexing completed on 2024-05-12 15:50:03

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 QT_BEGIN_NAMESPACE
0020 class QXmlStreamReader;
0021 QT_END_NAMESPACE
0022 
0023 namespace KSyntaxHighlighting
0024 {
0025 class DefinitionData;
0026 
0027 class Context
0028 {
0029 public:
0030     Q_DISABLE_COPY(Context)
0031 
0032     Context(Context &&) = default;
0033     Context &operator=(Context &&) = default;
0034 
0035     Context(const DefinitionData &def, const HighlightingContextData &data);
0036     ~Context() = default;
0037 
0038     const QString &name() const
0039     {
0040         return m_name;
0041     }
0042 
0043     const ContextSwitch &lineEndContext() const
0044     {
0045         return m_lineEndContext;
0046     }
0047 
0048     const ContextSwitch &lineEmptyContext() const
0049     {
0050         return m_lineEmptyContext;
0051     }
0052 
0053     bool fallthrough() const
0054     {
0055         return m_fallthrough;
0056     }
0057 
0058     const ContextSwitch &fallthroughContext() const
0059     {
0060         return m_fallthroughContext;
0061     }
0062 
0063     const Format &attributeFormat() const
0064     {
0065         return m_attributeFormat;
0066     }
0067 
0068     const std::vector<Rule::Ptr> &rules() const
0069     {
0070         return m_rules;
0071     }
0072 
0073     /**
0074      * Returns @c true, when indentationBasedFolding is enabled for the
0075      * associated Definition and when "noIndentationBasedFolding" is NOT set.
0076      */
0077     bool indentationBasedFoldingEnabled() const;
0078 
0079     void resolveContexts(DefinitionData &def, const HighlightingContextData &data);
0080     void resolveIncludes(DefinitionData &def);
0081 
0082 private:
0083     enum ResolveState : quint8 { Unresolved, Resolving, Resolved };
0084 
0085     std::vector<Rule::Ptr> m_rules;
0086 
0087     QString m_name;
0088 
0089     ContextSwitch m_lineEndContext;
0090     ContextSwitch m_lineEmptyContext;
0091     ContextSwitch m_fallthroughContext;
0092 
0093     /**
0094      * resolved format for our attribute, done in constructor and resolveIncludes
0095      */
0096     Format m_attributeFormat;
0097 
0098     ResolveState m_resolveState = Unresolved;
0099     bool m_fallthrough = false;
0100     bool m_indentationBasedFolding;
0101 };
0102 }
0103 
0104 #endif // KSYNTAXHIGHLIGHTING_CONTEXT_P_H