KDevelop API Documentation

ada_colorizer.cpp

Go to the documentation of this file.
00001 /* $Id: ada_colorizer.cpp,v 1.3 2003/06/03 03:16:31 okellogg Exp $
00002  * Copyright (C) 2003 Oliver Kellogg
00003  * okellogg@users.sourceforge.net
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
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     //default context
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     // Level starters for Ada:  begin, case, do, if, loop, select, while
00124     QRegExp startRx ("^\\s*(begin|case|if|loop|select|while)\\b", false);
00125     
00126     // We need another regexp for loops such as "for I in 1 .. 2 loop" because
00127     // the keyword does not appear at the start of the line.
00128     // We do not use the keyword "for" here because its meaning is overloaded.
00129     // We must also guard against matching the statement "end loop".
00130     QRegExp startLoopRx ("\\bloop\\s*(--.*)?$", false);
00131 
00132     // Level terminators for Ada: end
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 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003