/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef SYNEDITCPPHIGHLIGHTER_H
#define SYNEDITCPPHIGHLIGHTER_H
#include "base.h"
#include
class SynEditCppHighlighter: public SynHighlighter
{
enum TokenKind {
Asm = 1,
Comment,
Directive,
Identifier,
Key,
Null,
Number,
Space,
String,
StringEscapeSeq,
Symbol,
Unknown,
Char,
Float,
Hex,
HexFloat,
Octal,
RawString
};
enum class ExtTokenKind {
Add, AddAssign, And, AndAssign, Arrow, Assign,
BitComplement, BraceClose, BraceOpen, Colon, Comma,
Decrement, Divide, DivideAssign, Ellipse, GreaterThan,
GreaterThanEqual, IncOr, IncOrAssign, Increment, LessThan,
LessThanEqual, LogAnd, LogComplement, LogEqual, LogOr,
Mod, ModAssign, MultiplyAssign, NotEqual, Point, PointerToMemberOfObject,
PointerToMemberOfPointer,Question,
RoundClose, RoundOpen, ScopeResolution, SemiColon, ShiftLeft,
ShiftLeftAssign, ShiftRight, ShiftRightAssign, SquareClose,
SquareOpen, Star, Subtract, SubtractAssign, Xor,
XorAssign, BackSlash
};
enum RangeState {
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
rsMultiLineString, rsMultiLineDirective, rsCppComment,
rsStringEscapeSeq, rsMultiLineStringEscapeSeq,
rsRawString, rsSpace,rsRawStringEscaping,rsRawStringNotEscaping,rsChar,
rsCppCommentEnded
};
public:
explicit SynEditCppHighlighter();
PSynHighlighterAttribute asmAttribute() const;
PSynHighlighterAttribute preprocessorAttribute() const;
PSynHighlighterAttribute invalidAttribute() const;
PSynHighlighterAttribute numberAttribute() const;
PSynHighlighterAttribute floatAttribute() const;
PSynHighlighterAttribute hexAttribute() const;
PSynHighlighterAttribute octAttribute() const;
PSynHighlighterAttribute stringEscapeSequenceAttribute() const;
PSynHighlighterAttribute charAttribute() const;
PSynHighlighterAttribute variableAttribute() const;
PSynHighlighterAttribute functionAttribute() const;
PSynHighlighterAttribute classAttribute() const;
PSynHighlighterAttribute globalVarAttribute() const;
PSynHighlighterAttribute localVarAttribute() const;
static const QSet Keywords;
ExtTokenKind getExtTokenId();
SynTokenKind getTokenId();
private:
void andSymbolProc();
void ansiCppProc();
void ansiCProc();
void asciiCharProc();
void atSymbolProc();
void braceCloseProc();
void braceOpenProc();
void colonProc();
void commaProc();
void directiveProc();
void directiveEndProc();
void equalProc();
void greaterProc();
void identProc();
void lowerProc();
void minusProc();
void modSymbolProc();
void notSymbolProc();
void nullProc();
void numberProc();
void orSymbolProc();
void plusProc();
void pointProc();
void questionProc();
void rawStringProc();
void roundCloseProc();
void roundOpenProc();
void semiColonProc();
void slashProc();
void backSlashProc();
void spaceProc();
void squareCloseProc();
void squareOpenProc();
void starProc();
void stringEndProc();
void stringEscapeSeqProc();
void stringProc();
void stringStartProc();
void tildeProc();
void unknownProc();
void xorSymbolProc();
void processChar();
void popIndents(int indentType);
void pushIndents(int indentType);
private:
bool mAsmStart;
SynRangeState mRange;
// SynRangeState mSpaceRange;
QString mLineString;
QChar* mLine;
int mLineSize;
int mRun;
int mStringLen;
int mToIdent;
int mTokenPos;
int mTokenId;
ExtTokenKind mExtTokenId;
int mLineNumber;
int mLeftBraces;
int mRightBraces;
PSynHighlighterAttribute mAsmAttribute;
PSynHighlighterAttribute mPreprocessorAttribute;
PSynHighlighterAttribute mInvalidAttribute;
PSynHighlighterAttribute mNumberAttribute;
PSynHighlighterAttribute mFloatAttribute;
PSynHighlighterAttribute mHexAttribute;
PSynHighlighterAttribute mOctAttribute;
PSynHighlighterAttribute mStringEscapeSequenceAttribute;
PSynHighlighterAttribute mCharAttribute;
PSynHighlighterAttribute mVariableAttribute;
PSynHighlighterAttribute mFunctionAttribute;
PSynHighlighterAttribute mClassAttribute;
PSynHighlighterAttribute mGlobalVarAttribute;
PSynHighlighterAttribute mLocalVarAttribute;
// SynHighligterBase interface
public:
bool getTokenFinished() const override;
bool isLastLineCommentNotFinished(int state) const override;
bool isLastLineStringNotFinished(int state) const override;
bool eol() const override;
QString getToken() const override;
PSynHighlighterAttribute getTokenAttribute() const override;
SynTokenKind getTokenKind() override;
int getTokenPos() override;
void next() override;
void setLine(const QString &newLine, int lineNumber) override;
bool isKeyword(const QString &word) override;
SynHighlighterTokenType getTokenType() override;
void setState(const SynRangeState& rangeState) override;
void resetState() override;
SynHighlighterClass getClass() const override;
QString getName() const override;
QString languageName() override;
SynHighlighterLanguage language() override;
// SynHighlighter interface
public:
SynRangeState getRangeState() const override;
// SynHighlighter interface
public:
bool isIdentChar(const QChar &ch) const override;
// SynHighlighter interface
public:
QSet keywords() const override;
};
#endif // SYNEDITCPPHIGHLIGHTER_H