2013-04-10 20:49:22 +00:00
|
|
|
#ifndef CSV_WORLD_SCRIPTHIGHLIGHTER_H
|
|
|
|
#define CSV_WORLD_SCRIPTHIGHLIGHTER_H
|
|
|
|
|
|
|
|
#include <map>
|
2017-04-28 07:28:05 +00:00
|
|
|
#include <string>
|
2013-04-10 20:49:22 +00:00
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <QString>
|
2013-04-10 20:49:22 +00:00
|
|
|
#include <QSyntaxHighlighter>
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <QTextCharFormat>
|
2013-04-10 20:49:22 +00:00
|
|
|
|
2013-09-19 06:58:27 +00:00
|
|
|
#include <components/compiler/extensions.hpp>
|
2013-04-10 20:49:22 +00:00
|
|
|
#include <components/compiler/nullerrorhandler.hpp>
|
|
|
|
#include <components/compiler/parser.hpp>
|
|
|
|
|
|
|
|
#include "../../model/world/scriptcontext.hpp"
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
class QTextDocument;
|
|
|
|
|
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
class Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
{
|
|
|
|
class Scanner;
|
|
|
|
struct TokenLoc;
|
|
|
|
}
|
|
|
|
|
2015-12-12 13:49:16 +00:00
|
|
|
namespace CSMPrefs
|
|
|
|
{
|
|
|
|
class Setting;
|
|
|
|
}
|
|
|
|
|
2013-04-10 20:49:22 +00:00
|
|
|
namespace CSVWorld
|
|
|
|
{
|
|
|
|
class ScriptHighlighter : public QSyntaxHighlighter, private Compiler::Parser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Type
|
|
|
|
{
|
2015-12-12 13:49:16 +00:00
|
|
|
Type_Int = 0,
|
|
|
|
Type_Float = 1,
|
|
|
|
Type_Name = 2,
|
|
|
|
Type_Keyword = 3,
|
|
|
|
Type_Special = 4,
|
|
|
|
Type_Comment = 5,
|
2017-04-28 07:28:05 +00:00
|
|
|
Type_Highlight = 6,
|
|
|
|
Type_Id = 7
|
2013-04-10 20:49:22 +00:00
|
|
|
};
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2014-08-24 15:56:20 +00:00
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
Mode_General,
|
|
|
|
Mode_Console,
|
|
|
|
Mode_Dialogue
|
|
|
|
};
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2013-04-10 20:49:22 +00:00
|
|
|
private:
|
|
|
|
Compiler::NullErrorHandler mErrorHandler;
|
2013-09-19 06:58:27 +00:00
|
|
|
Compiler::Extensions mExtensions;
|
2013-04-10 20:49:22 +00:00
|
|
|
CSMWorld::ScriptContext mContext;
|
|
|
|
std::map<Type, QTextCharFormat> mScheme;
|
2014-08-24 15:56:20 +00:00
|
|
|
Mode mMode;
|
2017-04-28 07:57:49 +00:00
|
|
|
bool mMarkOccurrences;
|
2017-04-28 07:28:05 +00:00
|
|
|
std::string mMarkedWord;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2013-04-10 20:49:22 +00:00
|
|
|
private:
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseInt(int value, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
|
2013-04-10 20:49:22 +00:00
|
|
|
///< Handle an int token.
|
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseFloat(float value, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
|
2013-04-10 20:49:22 +00:00
|
|
|
///< Handle a float token.
|
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseName(const std::string& name, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
|
2013-04-10 20:49:22 +00:00
|
|
|
///< Handle a name token.
|
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseKeyword(int keyword, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
|
2013-04-10 20:49:22 +00:00
|
|
|
///< Handle a keyword token.
|
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseSpecial(int code, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
|
2013-04-10 20:49:22 +00:00
|
|
|
///< Handle a special character token.
|
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseComment(
|
|
|
|
const std::string& comment, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
|
2013-04-11 08:50:35 +00:00
|
|
|
///< Handle comment token.
|
2013-04-10 20:49:22 +00:00
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void parseEOF(Compiler::Scanner& scanner) override;
|
2013-04-10 20:49:22 +00:00
|
|
|
///< Handle EOF token.
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2013-04-10 20:49:22 +00:00
|
|
|
void highlight(const Compiler::TokenLoc& loc, Type type);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2013-04-10 20:49:22 +00:00
|
|
|
public:
|
2014-08-24 15:56:20 +00:00
|
|
|
ScriptHighlighter(const CSMWorld::Data& data, Mode mode, QTextDocument* parent);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void highlightBlock(const QString& text) override;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2017-04-28 07:57:49 +00:00
|
|
|
void setMarkOccurrences(bool);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2017-04-28 07:28:05 +00:00
|
|
|
void setMarkedWord(const std::string& name);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2013-09-19 12:26:09 +00:00
|
|
|
void invalidateIds();
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2015-12-12 13:49:16 +00:00
|
|
|
bool settingChanged(const CSMPrefs::Setting* setting);
|
2013-04-10 20:49:22 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|