00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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" );
00108
00109 DECLARE_FORMAT_ITEM( TypeVariable, "TypeVariable", defaultFont, Qt::darkGray );
00110
00111
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
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 }