You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.9 KiB
C++
101 lines
2.9 KiB
C++
#ifndef CSV_WORLD_SCRIPTHIGHLIGHTER_H
|
|
#define CSV_WORLD_SCRIPTHIGHLIGHTER_H
|
|
|
|
#include <map>
|
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
#include <components/compiler/nullerrorhandler.hpp>
|
|
#include <components/compiler/parser.hpp>
|
|
#include <components/compiler/extensions.hpp>
|
|
|
|
#include "../../model/world/scriptcontext.hpp"
|
|
|
|
namespace CSMPrefs
|
|
{
|
|
class Setting;
|
|
}
|
|
|
|
namespace CSVWorld
|
|
{
|
|
class ScriptHighlighter : public QSyntaxHighlighter, private Compiler::Parser
|
|
{
|
|
public:
|
|
|
|
enum Type
|
|
{
|
|
Type_Int = 0,
|
|
Type_Float = 1,
|
|
Type_Name = 2,
|
|
Type_Keyword = 3,
|
|
Type_Special = 4,
|
|
Type_Comment = 5,
|
|
Type_Id = 6
|
|
};
|
|
|
|
enum Mode
|
|
{
|
|
Mode_General,
|
|
Mode_Console,
|
|
Mode_Dialogue
|
|
};
|
|
|
|
private:
|
|
|
|
Compiler::NullErrorHandler mErrorHandler;
|
|
Compiler::Extensions mExtensions;
|
|
CSMWorld::ScriptContext mContext;
|
|
std::map<Type, QTextCharFormat> mScheme;
|
|
Mode mMode;
|
|
|
|
private:
|
|
|
|
virtual bool parseInt (int value, const Compiler::TokenLoc& loc,
|
|
Compiler::Scanner& scanner);
|
|
///< Handle an int token.
|
|
/// \return fetch another token?
|
|
|
|
virtual bool parseFloat (float value, const Compiler::TokenLoc& loc,
|
|
Compiler::Scanner& scanner);
|
|
///< Handle a float token.
|
|
/// \return fetch another token?
|
|
|
|
virtual bool parseName (const std::string& name,
|
|
const Compiler::TokenLoc& loc, Compiler::Scanner& scanner);
|
|
///< Handle a name token.
|
|
/// \return fetch another token?
|
|
|
|
virtual bool parseKeyword (int keyword, const Compiler::TokenLoc& loc,
|
|
Compiler::Scanner& scanner);
|
|
///< Handle a keyword token.
|
|
/// \return fetch another token?
|
|
|
|
virtual bool parseSpecial (int code, const Compiler::TokenLoc& loc,
|
|
Compiler::Scanner& scanner);
|
|
///< Handle a special character token.
|
|
/// \return fetch another token?
|
|
|
|
virtual bool parseComment (const std::string& comment, const Compiler::TokenLoc& loc,
|
|
Compiler::Scanner& scanner);
|
|
///< Handle comment token.
|
|
/// \return fetch another token?
|
|
|
|
virtual void parseEOF (Compiler::Scanner& scanner);
|
|
///< Handle EOF token.
|
|
|
|
void highlight (const Compiler::TokenLoc& loc, Type type);
|
|
|
|
public:
|
|
|
|
ScriptHighlighter (const CSMWorld::Data& data, Mode mode, QTextDocument *parent);
|
|
|
|
virtual void highlightBlock (const QString& text);
|
|
|
|
void invalidateIds();
|
|
|
|
bool settingChanged (const CSMPrefs::Setting *setting);
|
|
};
|
|
}
|
|
|
|
#endif
|