00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "ada_colorizer.h"
00011 #include "qeditor.h"
00012 #include "paragdata.h"
00013
00014 #include <qfont.h>
00015 #include <qapplication.h>
00016 #include <qsettings.h>
00017 #include <private/qrichtext_p.h>
00018 #include <kdebug.h>
00019
00020 static const char *ada_keywords[] = {
00021 "abort",
00022 "abs",
00023 "accept",
00024 "access",
00025 "all",
00026 "and",
00027 "array",
00028 "at",
00029 "begin",
00030 "body",
00031 "case",
00032 "constant",
00033 "declare",
00034 "delay",
00035 "delta",
00036 "digits",
00037 "do",
00038 "else",
00039 "elsif",
00040 "end",
00041 "entry",
00042 "exception",
00043 "exit",
00044 "for",
00045 "function",
00046 "generic",
00047 "goto",
00048 "if",
00049 "in",
00050 "is",
00051 "limited",
00052 "loop",
00053 "mod",
00054 "new",
00055 "not",
00056 "null",
00057 "of",
00058 "or",
00059 "others",
00060 "out",
00061 "package",
00062 "pragma",
00063 "private",
00064 "procedure",
00065 "raise",
00066 "range",
00067 "record",
00068 "rem",
00069 "renames",
00070 "return",
00071 "reverse",
00072 "select",
00073 "separate",
00074 "subtype",
00075 "task",
00076 "terminate",
00077 "then",
00078 "type",
00079 "use",
00080 "when",
00081 "while",
00082 "with",
00083 "xor",
00084 0
00085 };
00086
00087 AdaColorizer::AdaColorizer (QEditor * editor)
00088 : QSourceColorizer (editor)
00089 {
00090
00091 HLItemCollection* context0 = new HLItemCollection (0);
00092 context0->appendChild (new StartsWithHLItem ("--", Comment, 0));
00093 context0->appendChild (new KeywordsHLItem (ada_keywords, Keyword, Normal, 0));
00094 context0->appendChild (new WhiteSpacesHLItem (Normal, 0));
00095 context0->appendChild (new StringHLItem ("\"", String, 1));
00096 context0->appendChild (new NumberHLItem (Constant, 0));
00097 context0->appendChild (new RegExpHLItem ("[0-9][0-9]*#[A-Fa-f0-9]*#", Constant, 0));
00098
00099 HLItemCollection* context1 = new HLItemCollection (String);
00100 context1->appendChild (new StringHLItem ("\"", String, 0));
00101
00102 m_items.append (context0);
00103 m_items.append (context1);
00104 }
00105
00106 AdaColorizer::~AdaColorizer ()
00107 {
00108 }
00109
00110 int AdaColorizer::computeLevel (QTextParagraph* parag, int startLevel)
00111 {
00112 int level = startLevel;
00113
00114 QString s = editor ()->text (parag->paragId ());
00115 ParagData* data = (ParagData*) parag->extraData ();
00116 if (!data || s.isEmpty ()) {
00117 kdDebug() << "AdaColorizer::computeLevel: early return" << endl;
00118 return startLevel;
00119 }
00120
00121 data->setBlockStart (false);
00122
00123
00124 QRegExp startRx ("^\\s*(begin|case|if|loop|select|while)\\b", false);
00125
00126
00127
00128
00129
00130 QRegExp startLoopRx ("\\bloop\\s*(--.*)?$", false);
00131
00132
00133 QRegExp endRx ("^\\s*end\\b", false);
00134
00135 if (startRx.search (s) != -1 || startLoopRx.search (s) != -1)
00136 ++level;
00137 else if (endRx.search (s) != -1)
00138 --level;
00139
00140 if (level > startLevel) {
00141 data->setBlockStart (true);
00142 }
00143
00144 kdDebug() << "AdaColorizer::computeLevel called, startLevel="
00145 << startLevel << ", text: '" << s
00146 << "', level=" << level << endl;
00147 return level;
00148 }
00149