22 if(a.begin != b.begin)
23 return a.begin < b.begin;
31 MyLexer::MyLexer(QObject *parent)
32 : QsciLexerCustom(parent)
34 qDebug() << __FUNCTION__;
41 const char* MyLexer::language()
const
46 QString MyLexer::description(
int style)
const
59 void MyLexer::styleText(
int start,
int end)
62 qDebug() << __FUNCTION__
69 char *chars = (
char *) malloc ((end - start) *
sizeof(char) + 1);
70 editor()->SendScintilla(QsciScintilla::SCI_GETTEXTRANGE, start, end, chars);
71 source = QString(chars);
73 qDebug() <<
"source =" << source;
74 startStyling(start, 0x1f);
76 vector <text_partition> parts = makePartitions (chars, 0, source.length());
77 sort(parts.begin(), parts.end(), text_partition_cmp);
79 for (
unsigned int i = 0; i < parts.size(); i++) {
80 qDebug() <<
"partition id=" << parts[i].id <<
" begin=" << parts[i].begin <<
" end=" << parts[i].end;
81 setStyling(parts[i].begin-lastIndex, getStyle(Default));
82 setStyling(parts[i].end-parts[i].begin, partition_style[parts[i].
id]);
83 lastIndex = parts[i].end;
86 if (source.length()-lastIndex > 0) {
87 setStyling(source.length()-lastIndex, getStyle(Default));
92 QColor MyLexer::defaultColor(
int style)
96 return QColor(0x00, 0x0, 0x0);
98 return QColor(0x0, 0xe0, 0x0);
100 return QsciLexer::defaultColor(style);
103 QFont MyLexer::defaultFont(
int style)
105 return QFont(
"Courier New", 10);
108 QColor MyLexer::defaultPaper(
int style)
110 return QsciLexer::defaultPaper(style);
113 QsciStyle MyLexer::getStyle(
int style)
115 if (style < MaxStyle) {
116 return QsciStyle(style, description(style), defaultColor(style),
117 defaultPaper(style), defaultFont(style));
119 return QsciStyle(style);
123 bool MyLexer::addTextPartition (
int partition_id,
const QRegExp ®ex,
124 const QsciStyle &style) {
126 partition_regex.insert(partition_id, regex);
127 partition_style.insert(partition_id, style);
132 vector <text_partition > MyLexer::makePartitions (
char *chars,
int begin,
int end){
133 vector <text_partition> partitions;
135 int PARTITION_ID = -1;
137 QMap <int, QRegExp>::const_iterator i = partition_regex.constBegin();
139 int lastIndex = begin;
140 while(i != partition_regex.constEnd()) {
141 PARTITION_ID = i.key();
144 if(PARTITION_ID == -1)
150 int index = regex.indexIn(chars, lastIndex);
152 if (index + regex.matchedLength() > end)
155 part.id = PARTITION_ID;
157 part.end = index + regex.matchedLength();
158 partitions.push_back (part);
160 lastIndex = (index + regex.matchedLength());
161 index = regex.indexIn(chars, lastIndex);