1
#include "qalgebrahighlighter.h"
3
QAlgebraHighlighter::QAlgebraHighlighter(QTextEdit *textEdit) : QSyntaxHighlighter(textEdit), m_mode(Autodetect){}
6
int QAlgebraHighlighter::highlightParagraph(const QString &text, int endStateOfLastPara) {
7
setFormat( 0, text.length(), Qt::black);
8
if(!m_mode==Expression && !(m_mode==Autodetect && text[0]=='<'))
10
QString op=text.stripWhiteSpace();
11
unsigned int pos=0, len=0;
16
while(pos < text.length()-1 || t.tipus!=tEof){
17
if(t.tipus==tVal) setFormat( pos, len, QColor(0,0,200));
18
else if(t.tipus==tFunc) setFormat( pos, len, QColor(0,50,0));
19
else if(t.tipus==tVar) setFormat( pos, len, QColor(100,0,0));
20
else setFormat( pos, len, QFont(this->textEdit()->currentFont().family(),
21
this->textEdit()->currentFont().pointSize(),
22
QFont::DemiBold, false));
27
return endStateOfLastPara;
30
TOKEN QAlgebraHighlighter::getToken(QString &a, unsigned int &l){
33
a = a.stripWhiteSpace();
34
// printf("%s\n", a.ascii());
41
else if(a[0].isDigit()) {//es un numero
44
for(i=1; a[i].isDigit() || a[i]=='.'; i++){
47
if(a[i] == '(' || a[i].isLetter()) a = " *" +a;
49
} else if(a[0].isLetter()) {//es una variable o func
51
for(i=1; a[i].isLetter(); i++) a[i]=' ';
56
} else if(a[0]=='-' && a[1] == '>') {
59
} else if(a[0]==':' && a[1] == '=') {
65
ret.tipus = (antnum == tVal || antnum==tRpr) ? tSub : tUmi;
70
else if(a[0]=='*' && a[1] == '*') {
85
a=a.stripWhiteSpace();
88
// qDebug("%d------------", a.length());