RedPanda-CPP/RedPandaIDE/qsynedit/highlighter/base.h

145 lines
3.8 KiB
C
Raw Normal View History

2021-05-14 23:56:43 +08:00
#ifndef SYNHIGHLIGTERBASE_H
#define SYNHIGHLIGTERBASE_H
#include <QColor>
#include <QObject>
#include <memory>
#include <QMap>
#include <QSet>
#include <QVector>
#include <QVector>
#include "../Types.h"
struct SynRangeState {
2021-05-14 23:56:43 +08:00
int state;
int spaceState;
int braceLevel;
int bracketLevel;
int parenthesisLevel;
int leftBraces;
int rightBraces;
bool operator==(const SynRangeState& s2);
};
2021-05-14 23:56:43 +08:00
typedef int SynTokenKind;
enum class SynHighlighterTokenType {
Default, Space, Comment,
PreprocessDirective, String, StringEscapeSequence,
Identifier, Symbol,
Character, Keyword, Number};
enum class SynHighlighterClass {
Composition,
CppHighlighter,
2021-07-01 22:29:51 +08:00
AsmHighlighter
2021-05-14 23:56:43 +08:00
};
2021-05-26 00:04:20 +08:00
enum class SynHighlighterLanguage {
2021-07-01 22:23:24 +08:00
Asssembly,
Cpp,
2021-05-26 00:04:20 +08:00
};
2021-05-14 23:56:43 +08:00
2021-05-26 00:04:20 +08:00
class SynHighlighterAttribute {
public:
explicit SynHighlighterAttribute(const QString& name);
2021-05-14 23:56:43 +08:00
QString name() const;
void setName(const QString &name);
SynFontStyles styles() const;
void setStyles(const SynFontStyles &styles);
2021-05-26 00:04:20 +08:00
QColor foreground() const;
void setForeground(const QColor &color);
QColor background() const;
void setBackground(const QColor &background);
2021-05-14 23:56:43 +08:00
private:
QColor mForeground;
2021-05-26 00:04:20 +08:00
QColor mBackground;
2021-05-14 23:56:43 +08:00
QString mName;
SynFontStyles mStyles;
};
typedef std::shared_ptr<SynHighlighterAttribute> PSynHighlighterAttribute;
using SynHighlighterAttributeList = QVector<PSynHighlighterAttribute>;
2021-05-26 00:04:20 +08:00
class SynHighlighter {
2021-05-14 23:56:43 +08:00
public:
2021-05-26 00:04:20 +08:00
explicit SynHighlighter();
2021-05-14 23:56:43 +08:00
const QMap<QString, PSynHighlighterAttribute>& attributes() const;
const QSet<QChar>& wordBreakChars() const;
PSynHighlighterAttribute commentAttribute() const;
PSynHighlighterAttribute identifierAttribute() const;
PSynHighlighterAttribute keywordAttribute() const;
PSynHighlighterAttribute stringAttribute() const;
PSynHighlighterAttribute whitespaceAttribute() const;
PSynHighlighterAttribute symbolAttribute() const;
virtual bool isIdentChar(const QChar& ch) const;
virtual SynHighlighterClass getClass() const = 0;
virtual QString getName() const = 0;
virtual bool getTokenFinished() const = 0;
virtual bool isLastLineCommentNotFinished(int state) const = 0;
virtual bool isLastLineStringNotFinished(int state) const = 0;
virtual bool eol() const = 0;
2021-05-26 18:32:17 +08:00
virtual SynRangeState getRangeState() const = 0;
2021-05-14 23:56:43 +08:00
virtual QString getToken() const=0;
virtual PSynHighlighterAttribute getTokenAttribute() const=0;
virtual SynHighlighterTokenType getTokenType();
virtual SynTokenKind getTokenKind() = 0;
virtual int getTokenPos() = 0;
virtual bool isKeyword(const QString& word);
virtual void next() = 0;
virtual void nextToEol();
virtual void setState(const SynRangeState& rangeState) = 0;
2021-05-14 23:56:43 +08:00
virtual void setLine(const QString& newLine, int lineNumber) = 0;
virtual void resetState() = 0;
2021-05-24 00:41:00 +08:00
virtual QString languageName() = 0;
2021-05-26 00:04:20 +08:00
virtual SynHighlighterLanguage language() = 0;
2021-05-14 23:56:43 +08:00
2021-06-22 23:00:34 +08:00
virtual bool isSpaceChar(const QChar& ch);
virtual bool isWordBreakChar(const QChar& ch);
2021-05-18 15:49:58 +08:00
bool enabled() const;
void setEnabled(bool value);
2021-05-14 23:56:43 +08:00
protected:
PSynHighlighterAttribute mCommentAttribute;
PSynHighlighterAttribute mIdentifierAttribute;
PSynHighlighterAttribute mKeywordAttribute;
PSynHighlighterAttribute mStringAttribute;
PSynHighlighterAttribute mWhitespaceAttribute;
PSynHighlighterAttribute mSymbolAttribute;
void addAttribute(PSynHighlighterAttribute attribute);
void clearAttributes();
virtual int attributesCount() const;
virtual PSynHighlighterAttribute getAttribute(const QString& name) const;
private:
QMap<QString,PSynHighlighterAttribute> mAttributes;
bool mEnabled;
QSet<QChar> mWordBreakChars;
};
using PSynHighlighter = std::shared_ptr<SynHighlighter>;
using SynHighlighterList = QVector<PSynHighlighter>;
#endif // SYNHIGHLIGTERBASE_H