KDevelop API Documentation

ocaml_colorizer.cpp

Go to the documentation of this file.
00001 /* $Id: ocaml_colorizer.cpp,v 1.3 2003/08/30 19:25:36 coolo 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  *  Library 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.LIB.  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 
00025 #include "ocaml_colorizer.h"
00026 #include "paragdata.h"
00027 #include "qeditor_factory.h"
00028 
00029 #include <qfont.h>
00030 #include <qapplication.h>
00031 #include <qsettings.h>
00032 #include <private/qrichtext_p.h>
00033 
00034 #include <kconfig.h>
00035 #include <kglobalsettings.h>
00036 #include <kinstance.h>
00037 
00038 static const char* ocaml_keywords[] = {
00039     // OCaml keywords
00040     "and",
00041     "as",
00042     "assert",
00043     "asr",
00044     "begin",
00045     "class",
00046     "closed",
00047     "constraint",
00048     "do",
00049     "done",
00050     "downto",
00051     "else",
00052     "end",
00053     "exception",
00054     "external",
00055     "false",
00056     "for",
00057     "fun",
00058     "function",
00059     "functor",
00060     "if",
00061     "in",
00062     "include",
00063     "inherit",
00064     "land",
00065     "lazy",
00066     "let",
00067     "lor",
00068     "lsl",
00069     "lsr",
00070     "lxor",
00071     "match",
00072     "method",
00073     "mod",
00074     "module",
00075     "mutable",
00076     "new",
00077     "of",
00078     "open",
00079     "or",
00080     "parser",
00081     "private",
00082     "rec",
00083     "sig",
00084     "struct",
00085     "then",
00086     "to",
00087     "true",
00088     "try",
00089     "type",
00090     "val",
00091     "virtual",
00092     "with",
00093     "when",
00094     "while",
00095     0
00096 };
00097 
00098 enum {
00099     TypeVariable = QSourceColorizer::Custom + 100
00100 };
00101 
00102 OCamlColorizer::OCamlColorizer( QEditor* editor )
00103     : QSourceColorizer( editor )
00104 {
00105     QFont defaultFont = KGlobalSettings::fixedFont();
00106     KConfig* config = QEditorPartFactory::instance()->config();
00107     config->setGroup( "General" );  // or colorizer ?!?!?
00108 
00109     DECLARE_FORMAT_ITEM( TypeVariable, "TypeVariable", defaultFont, Qt::darkGray );
00110 
00111     // default context
00112     HLItemCollection* context0 = new HLItemCollection( 0 );
00113     context0->appendChild( new StartsWithHLItem( "#", PreProcessor, 0 ) );
00114     context0->appendChild( new StringHLItem( "(*", Comment, 1 ) );
00115     context0->appendChild( new StringHLItem( "\"", String, 2 ) );
00116     context0->appendChild( new RegExpHLItem( "'[_a-z]+", TypeVariable, 0 ) );
00117     context0->appendChild( new KeywordsHLItem( ocaml_keywords, Keyword, Normal, 0 ) );
00118     context0->appendChild( new NumberHLItem( Constant, 0 ) );
00119 
00120     // comment context
00121     HLItemCollection* context1 = new HLItemCollection( Comment );
00122     context1->appendChild( new StringHLItem( "*)", Comment, 0 ) );
00123 
00124     HLItemCollection* context2 = new HLItemCollection( String );
00125     context2->appendChild( new StringHLItem( "\\", String, 2 ) );
00126     context2->appendChild( new StringHLItem( "\"", String, 0 ) );
00127 
00128     m_items.append( context0 );
00129     m_items.append( context1 );
00130     m_items.append( context2 );
00131 }
00132 
00133 OCamlColorizer::~OCamlColorizer()
00134 {
00135     KConfig* config = QEditorPartFactory::instance()->config();
00136     config->setGroup( "General" );
00137     
00138     STORE_FORMAT_ITEM( TypeVariable );
00139 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:24 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003