KDevelop API Documentation

cs_colorizer.cpp

Go to the documentation of this file.
00001 /* $Id: cs_colorizer.cpp,v 1.6 2002/12/19 22:02:39 raggi Exp $
00002  *
00003  *  This file is part of Klint
00004  *  Copyright (C) 2001 Roberto Raggi (roberto@kdevelop.org)
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; see the file COPYING.  If not, write to
00018  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  *  Boston, MA 02111-1307, USA.
00020  *
00021  */
00022 
00023 
00024 #include "cs_colorizer.h"
00025 #include "qeditor_part.h"
00026 #include "paragdata.h"
00027 
00028 #include <qfont.h>
00029 #include <private/qrichtext_p.h>
00030 
00031 #include <kapplication.h>
00032 #include <kdebug.h>
00033 #include <kconfig.h>
00034 
00035 
00036 static const char *cs_keywords[] = {
00037     "abstract",
00038     "as",
00039     "base",
00040     "bool",
00041     "break",
00042     "byte",
00043     "case",
00044     "catch",
00045     "char",
00046     "checked",
00047     "class",
00048     "const",
00049     "continue",
00050     "decimal",
00051     "default",
00052     "delegate",
00053     "do",
00054     "double",
00055     "else",
00056     "enum",
00057     "event",
00058     "explicit",
00059     "extern",
00060     "false",
00061     "finally",
00062     "fixed",
00063     "float",
00064     "for",
00065     "foreach",
00066     "goto",
00067     "if",
00068     "implicit",
00069     "in",
00070     "int",
00071     "interface",
00072     "internal",
00073     "is",
00074     "lock",
00075     "long",
00076     "namespace",
00077     "new",
00078     "null",
00079     "object",
00080     "operator",
00081     "out",
00082     "override",
00083     "params",
00084     "private",
00085     "protected",
00086     "public",
00087     "readonly",
00088     "ref",
00089     "return",
00090     "sbyte",
00091     "sealed",
00092     "short",
00093     "sizeof",
00094     "stackalloc",
00095     "static",
00096     "string",
00097     "struct",
00098     "switch",
00099     "this",
00100     "throw",
00101     "true",
00102     "try",
00103     "typeof",
00104     "uint",
00105     "ulong",
00106     "unchecked"
00107     "unsafe",
00108     "ushort",
00109     "using",
00110     "virtual",
00111     "void",
00112     "volatile",
00113     "while",
00114     0
00115 };
00116 
00117 using namespace std;
00118 
00119 CSharpColorizer::CSharpColorizer( QEditor* editor )
00120     : QSourceColorizer( editor )
00121 {
00122     // default context
00123     HLItemCollection* context0 = new HLItemCollection( 0 );
00124 
00125     context0->appendChild( new RegExpHLItem( "^\\s*#", PreProcessor, 4 ) );
00126     context0->appendChild( new WhiteSpacesHLItem( Normal, 0 ) );
00127     context0->appendChild( new StringHLItem( "'", String, 1 ) );
00128     context0->appendChild( new StringHLItem( "\"", String, 2 ) );
00129     context0->appendChild( new StringHLItem( "/*", Comment, 3 ) );
00130     context0->appendChild( new StartsWithHLItem( "//", Comment, 0 ) );
00131     context0->appendChild( new KeywordsHLItem( cs_keywords, Keyword, Normal, 0 ) );
00132     context0->appendChild( new HexHLItem( Constant, 0 ) );
00133     context0->appendChild( new NumberHLItem( Constant, 0 ) );
00134     context0->appendChild( new RegExpHLItem("@[_\\w]+", Normal, 0) );
00135 
00136     HLItemCollection* context1 = new HLItemCollection( String );
00137     context1->appendChild( new StringHLItem( "\\\\", String, 1 ) );
00138     context1->appendChild( new StringHLItem( "\\'", String, 1 ) );
00139     context1->appendChild( new StringHLItem( "'", String, 0 ) );
00140 
00141     HLItemCollection* context2 = new HLItemCollection( String );
00142     context2->appendChild( new StringHLItem( "\\\\", String, 2 ) );
00143     context2->appendChild( new StringHLItem( "\\\"", String, 2 ) );
00144     context2->appendChild( new StringHLItem( "\"", String, 0 ) );
00145 
00146     HLItemCollection* context3 = new HLItemCollection( Comment );
00147     context3->appendChild( new StringHLItem( "*/", Comment, 0 ) );
00148 
00149     HLItemCollection* context4 = new HLItemCollection( PreProcessor );
00150     context4->appendChild( new RegExpHLItem( ".*\\\\\\s*$", PreProcessor, 4 ) );
00151     context4->appendChild( new StartsWithHLItem( "", PreProcessor, 0 ) );
00152 
00153 
00154     m_items.append( context0 );
00155     m_items.append( context1 );
00156     m_items.append( context2 );
00157     m_items.append( context3 );
00158     m_items.append( context4 );
00159 }
00160 
00161 CSharpColorizer::~CSharpColorizer()
00162 {
00163 }
00164 
00165 int CSharpColorizer::computeLevel( QTextParagraph* parag, int startLevel )
00166 {
00167     int level = startLevel;
00168 
00169     ParagData* data = (ParagData*) parag->extraData();
00170     if( !data ){
00171         return startLevel;
00172     }
00173 
00174     data->setBlockStart( false );
00175 
00176     QValueList<Symbol> symbols = data->symbolList();
00177     QValueList<Symbol>::Iterator it = symbols.begin();
00178     while( it != symbols.end() ){
00179         Symbol sym = *it++;
00180         if( sym.ch() == '{' ){
00181             ++level;
00182         } else if( sym.ch() == '}' ){
00183             --level;
00184         }
00185     }
00186 
00187     if( level > startLevel ){
00188         data->setBlockStart( true );
00189     }
00190 
00191     return level;
00192 }
00193 
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