1 #ifndef CSV_WORLD_SCRIPTHIGHLIGHTER_H
2 #define CSV_WORLD_SCRIPTHIGHLIGHTER_H
3 
4 #include <map>
5 #include <string>
6 
7 #include <QSyntaxHighlighter>
8 
9 #include <components/compiler/nullerrorhandler.hpp>
10 #include <components/compiler/parser.hpp>
11 #include <components/compiler/extensions.hpp>
12 
13 #include "../../model/world/scriptcontext.hpp"
14 
15 namespace CSMPrefs
16 {
17     class Setting;
18 }
19 
20 namespace CSVWorld
21 {
22     class ScriptHighlighter : public QSyntaxHighlighter, private Compiler::Parser
23     {
24         public:
25 
26             enum Type
27             {
28                 Type_Int = 0,
29                 Type_Float = 1,
30                 Type_Name = 2,
31                 Type_Keyword = 3,
32                 Type_Special = 4,
33                 Type_Comment = 5,
34                 Type_Highlight = 6,
35                 Type_Id = 7
36             };
37 
38             enum Mode
39             {
40                 Mode_General,
41                 Mode_Console,
42                 Mode_Dialogue
43             };
44 
45         private:
46 
47             Compiler::NullErrorHandler mErrorHandler;
48             Compiler::Extensions mExtensions;
49             CSMWorld::ScriptContext mContext;
50             std::map<Type, QTextCharFormat> mScheme;
51             Mode mMode;
52             bool mMarkOccurrences;
53             std::string mMarkedWord;
54 
55         private:
56 
57             bool parseInt (int value, const Compiler::TokenLoc& loc,
58                 Compiler::Scanner& scanner) override;
59             ///< Handle an int token.
60             /// \return fetch another token?
61 
62             bool parseFloat (float value, const Compiler::TokenLoc& loc,
63                 Compiler::Scanner& scanner) override;
64             ///< Handle a float token.
65             /// \return fetch another token?
66 
67             bool parseName (const std::string& name,
68                 const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
69             ///< Handle a name token.
70             /// \return fetch another token?
71 
72             bool parseKeyword (int keyword, const Compiler::TokenLoc& loc,
73                 Compiler::Scanner& scanner) override;
74             ///< Handle a keyword token.
75             /// \return fetch another token?
76 
77             bool parseSpecial (int code, const Compiler::TokenLoc& loc,
78                 Compiler::Scanner& scanner) override;
79             ///< Handle a special character token.
80             /// \return fetch another token?
81 
82             bool parseComment (const std::string& comment, const Compiler::TokenLoc& loc,
83                 Compiler::Scanner& scanner) override;
84             ///< Handle comment token.
85             /// \return fetch another token?
86 
87             void parseEOF (Compiler::Scanner& scanner) override;
88             ///< Handle EOF token.
89 
90             void highlight (const Compiler::TokenLoc& loc, Type type);
91 
92         public:
93 
94             ScriptHighlighter (const CSMWorld::Data& data, Mode mode, QTextDocument *parent);
95 
96             void highlightBlock (const QString& text) override;
97 
98             void setMarkOccurrences(bool);
99 
100             void setMarkedWord(const std::string& name);
101 
102             void invalidateIds();
103 
104             bool settingChanged (const CSMPrefs::Setting *setting);
105     };
106 }
107 
108 #endif
109