1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-23 02:23:54 +00:00
openmw/apps/opencs/view/world/scripthighlighter.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
2.9 KiB
C++
Raw Normal View History

#ifndef CSV_WORLD_SCRIPTHIGHLIGHTER_H
#define CSV_WORLD_SCRIPTHIGHLIGHTER_H
#include <map>
#include <string>
2022-10-19 17:02:00 +00:00
#include <QString>
#include <QSyntaxHighlighter>
2022-10-19 17:02:00 +00:00
#include <QTextCharFormat>
#include <components/compiler/extensions.hpp>
#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;
}
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_Highlight = 6,
Type_Id = 7
};
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
private:
Compiler::NullErrorHandler mErrorHandler;
Compiler::Extensions mExtensions;
CSMWorld::ScriptContext mContext;
std::map<Type, QTextCharFormat> mScheme;
2014-08-24 15:56:20 +00:00
Mode mMode;
bool mMarkOccurrences;
std::string mMarkedWord;
2022-09-22 18:26:05 +00:00
private:
bool parseInt(int value, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
2022-09-22 18:26:05 +00:00
bool parseFloat(float value, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
///< Handle a float token.
/// \return fetch another token?
2022-09-22 18:26:05 +00:00
bool parseName(const std::string& name, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
2022-09-22 18:26:05 +00:00
bool parseKeyword(int keyword, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
2022-09-22 18:26:05 +00:00
bool parseSpecial(int code, const Compiler::TokenLoc& loc, Compiler::Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
2022-09-22 18:26:05 +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.
/// \return fetch another token?
2022-09-22 18:26:05 +00:00
void parseEOF(Compiler::Scanner& scanner) override;
///< Handle EOF token.
2022-09-22 18:26:05 +00:00
void highlight(const Compiler::TokenLoc& loc, Type type);
2022-09-22 18:26:05 +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
void highlightBlock(const QString& text) override;
2022-09-22 18:26:05 +00:00
void setMarkOccurrences(bool);
2022-09-22 18:26:05 +00:00
void setMarkedWord(const std::string& name);
2022-09-22 18:26:05 +00:00
void invalidateIds();
2022-09-22 18:26:05 +00:00
bool settingChanged(const CSMPrefs::Setting* setting);
};
}
#endif