editors/qeditor/cs_colorizer.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
This file is part of the documentation for KDevelop Version 3.0.4.