2
* Copyright (C) 2003 Oliver Kellogg
3
* okellogg@users.sourceforge.net
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
#include "ada_colorizer.h"
12
#include "paragdata.h"
15
#include <qapplication.h>
16
#include <qsettings.h>
17
#include <private/qrichtext_p.h>
20
static const char *ada_keywords[] = {
87
AdaColorizer::AdaColorizer (QEditor * editor)
88
: QSourceColorizer (editor)
91
HLItemCollection* context0 = new HLItemCollection (0);
92
context0->appendChild (new StartsWithHLItem ("--", Comment, 0));
93
context0->appendChild (new KeywordsHLItem (ada_keywords, Keyword, Normal, 0));
94
context0->appendChild (new WhiteSpacesHLItem (Normal, 0));
95
context0->appendChild (new StringHLItem ("\"", String, 1));
96
context0->appendChild (new NumberHLItem (Constant, 0));
97
context0->appendChild (new RegExpHLItem ("[0-9][0-9]*#[A-Fa-f0-9]*#", Constant, 0));
99
HLItemCollection* context1 = new HLItemCollection (String);
100
context1->appendChild (new StringHLItem ("\"", String, 0));
102
m_items.append (context0);
103
m_items.append (context1);
106
AdaColorizer::~AdaColorizer ()
110
int AdaColorizer::computeLevel (QTextParagraph* parag, int startLevel)
112
int level = startLevel;
114
QString s = editor ()->text (parag->paragId ());
115
ParagData* data = (ParagData*) parag->extraData ();
116
if (!data || s.isEmpty ()) {
117
kdDebug() << "AdaColorizer::computeLevel: early return" << endl;
121
data->setBlockStart (false);
123
// Level starters for Ada: begin, case, do, if, loop, select, while
124
QRegExp startRx ("^\\s*(begin|case|if|loop|select|while)\\b", false);
126
// We need another regexp for loops such as "for I in 1 .. 2 loop" because
127
// the keyword does not appear at the start of the line.
128
// We do not use the keyword "for" here because its meaning is overloaded.
129
// We must also guard against matching the statement "end loop".
130
QRegExp startLoopRx ("\\bloop\\s*(--.*)?$", false);
132
// Level terminators for Ada: end
133
QRegExp endRx ("^\\s*end\\b", false);
135
if (startRx.search (s) != -1 || startLoopRx.search (s) != -1)
137
else if (endRx.search (s) != -1)
140
if (level > startLevel) {
141
data->setBlockStart (true);
144
kdDebug() << "AdaColorizer::computeLevel called, startLevel="
145
<< startLevel << ", text: '" << s
146
<< "', level=" << level << endl;