class QsciLexerASM : public QsciLexerCustom { Q_OBJECT public: explicit QsciLexerASM(QObject *parent = 0); ~QsciLexerASM(); //! ( ) void styleText(int start, int end); //! ( styleText()) void paintKeywords(const QString &source, int start); void paintComments(const QString &source, int start); //! ( ASM const char * language() const; //! QColor defaultColor(int style) const; //! QString description(int style) const; //! enum { Default = 0, Comment = 1, Keyword = 2 }; private: QsciLexerASM(const QsciLexerASM &); QsciLexerASM &operator=(const QsciLexerASM &); QStringList keywordsList; };
QString QsciLexerASM::description(int style) const { switch(style) { case Default: return "Default"; case Comment: return "Comment"; case Keyword: return "Keyword"; } return QString(style); } const char * QsciLexerASM::language() { return "ASM"; }
QColor QsciLexerASM::defaultColor(int style) const { switch(style) { case Comment: return Qt::darkGreen; case Keyword: return Qt::blue; } return Qt::black; }
QsciLexerASM::QsciLexerASM(QObject *parent) : QsciLexerCustom(parent) { keywordsList << "mov" << "add" << "sub" << "imul" << "or" << "and" << "xor" << "shr" << "jmp" << "loop" << "ret" << "int"; }
void QsciLexerASM::styleText(int start, int end) { if(!editor()) return; // char * data = new char[end - start + 1]; // Scintilla editor()->SendScintilla(QsciScintilla::SCI_GETTEXTRANGE, start, end, data); QString source(data); delete [] data; if(source.isEmpty()) return; // ! paintKeywords(source, start); paintComments(source, start); }
void QsciLexerASM::paintKeywords(const QString &source, int start) { foreach(QString word, keywordsList) { // if(source.contains(word)) { int p = source.count(word); // int index = 0; // c 0 while(p != 0) { int begin = source.indexOf(word, index); // index = begin+1; // startStyling(start + begin); // setStyling(word.length(), Keyword); // word.length Keyword startStyling(start + begin); // p--; } } } } void QsciLexerASM::paintComments(const QString &source, int start) { int p = source.count(";"); // if(p == 0) return; int index = 0; // ";" 0 while(p != 0) { int begin = source.indexOf(";", index); // int length=0; // index = begin+1; // for(int k = begin; source[k] != '\n'; k++) // source length++; startStyling(start + begin); // setStyling(length, Comment); // length Comment startStyling(start + begin); // p--; } }
Source: https://habr.com/ru/post/144714/
All Articles