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
00026
00027
00028 #ifndef LANGUAGEDEFINITION_H
00029 #define LANGUAGEDEFINITION_H
00030
00031 #include <string>
00032 #include <map>
00033 #include <iostream>
00034 #include <fstream>
00035 #include <iterator>
00036 #include <sstream>
00037
00038 #include "configurationreader.h"
00039 #include "platform_fs.h"
00040 #include "enums.h"
00041 #include "re/Pattern.h"
00042 #include "re/Matcher.h"
00043
00044 namespace highlight
00045 {
00046
00047 class RegexElement;
00048
00050 typedef map <string, int> KeywordMap;
00051
00053 typedef map <string, string> EmbedLangDelimMap;
00054
00063 class LanguageDefinition
00064 {
00065
00066 public:
00067
00068 LanguageDefinition();
00069
00070 ~LanguageDefinition();
00071
00073 const string &getSymbolString() const { return symbolString; }
00074
00076 const string &getFailedRegex() const { return failedRegex; }
00077
00079 unsigned char getRawStringPrefix() const { return rawStringPrefix; }
00080
00082 unsigned char getContinuationChar() const { return continuationChar; }
00083
00085 bool highlightingEnabled() const { return !disableHighlighting;}
00086
00088 bool isIgnoreCase() const { return ignoreCase;}
00089
00092 int isKeyword ( const string &s ) ;
00093
00098 bool load ( const string& langDefPath, bool clear=true );
00099
00101 bool allowNestedMLComments() const { return allowNestedComments; }
00102
00105 bool highlightingDisabled() const { return disableHighlighting; }
00106
00109 bool needsReload ( const string &langDefPath ) const { return currentPath!=langDefPath; }
00110
00112 bool enableReformatting() const { return reformatCode;}
00113
00115 bool allowExtEscSeq() const { return allowExtEscape; }
00116
00118 const KeywordMap& getKeywords() const { return keywords; }
00119
00121 const vector<string>& getKeywordClasses() const { return keywordClasses;}
00122
00124 const vector<RegexElement*>& getRegexElements() const {return regex;};
00125
00127 const string & getDescription () const {return langDesc;}
00128
00132 bool delimiterIsDistinct ( int stateID )
00133 {
00134 return delimiterDistinct[stateID];
00135 }
00136
00141 int getDelimiterPairID ( const string& token )
00142 {
00143 return delimiterPair[token];
00144 }
00145
00146 string getDelimRegex(const string & lang){
00147 return exitDelimiters[lang];
00148 }
00149
00153 void restoreLangEndDelim(const string&langPath);
00154
00159 string getNewPath(const string& lang);
00160
00161 string getCurrentPath() { return currentPath;}
00162
00163 private:
00164
00165 static const string REGEX_IDENTIFIER;
00166 static const string REGEX_NUMBER;
00167
00168
00169 string symbolString;
00170
00171
00172 string currentPath;
00173
00174
00175 string langDesc;
00176
00177 string failedRegex;
00178
00179 KeywordMap keywords;
00180
00181 vector <string> keywordClasses;
00182
00183 vector <RegexElement*> regex;
00184
00185 KeywordMap delimiterPrefixes;
00186
00187 EmbedLangDelimMap exitDelimiters;
00188
00189
00190 map <int, bool> delimiterDistinct;
00191
00192 map <string, int> delimiterPair;
00193
00194
00195 bool ignoreCase,
00196
00197
00198 disableHighlighting,
00199
00200
00201 allowExtEscape,
00202
00203
00204 allowNestedComments,
00205
00206
00207 fullLineComment,
00208
00209
00210 reformatCode;
00211
00212
00213 unsigned char rawStringPrefix,
00214
00215
00216 continuationChar;
00217
00218
00219 void reset();
00220
00221
00222 void addSimpleSymbol ( stringstream& symbolStream, State state,
00223 const string& paramValue );
00224
00225 void addSymbol ( stringstream& symbolStream,
00226 State stateBegin,
00227 State stateEnd,
00228 bool isDelimiter,
00229 const string& paramValue,
00230 unsigned int classID=0 );
00231
00232
00233 void addDelimiterSymbol ( stringstream& symbolStream,
00234 State stateBegin, State stateEnd,
00235 const string& paramValue,
00236 unsigned int classID=0 );
00237
00238 void addDelimiterRegex ( stringstream& symbolStream,
00239 State stateBegin, State stateEnd,
00240 const string& paramValue, const string& langName);
00241
00242
00243
00244
00245 void getFlag ( string& paramValue, bool& flag );
00246
00247 void getSymbol ( const string& paramValue, unsigned char& symbol );
00248
00249
00250 unsigned int generateNewKWClass ( const string& newClassName );
00251
00252
00253 void addKeywords ( const string &kwList,State stateBegin, State stateEnd, int classID );
00254
00255 struct RegexDef extractRegex ( const string ¶mValue );
00256
00257 Pattern * reDefPattern;
00258
00259 };
00260
00261
00267 class RegexElement
00268 {
00269 public:
00270 RegexElement()
00271 :open ( STANDARD ), end ( STANDARD ), rePattern ( NULL ), kwClass ( 0 ),capturingGroup ( -1 ), langName()
00272 {
00273 }
00274
00275 RegexElement ( State oState, State eState, Pattern *re, unsigned int cID=0, int group=-1, const string& name="" ) :
00276 open ( oState ), end ( eState ), rePattern ( re ), kwClass ( cID ), capturingGroup ( group ), langName(name)
00277 {
00278
00279 }
00280
00281 ~RegexElement() { if ( rePattern ) delete rePattern; }
00282
00283 State open,
00284 end;
00285 Pattern *rePattern;
00286 unsigned int kwClass;
00287 int capturingGroup;
00288 string langName;
00289
00290 private:
00291 RegexElement (const RegexElement& rhs){
00292
00293
00294
00295
00296
00297
00298
00299
00300 }
00301 RegexElement& operator=(const RegexElement& rhs){
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 return *this;
00312 }
00313 };
00314
00317 struct RegexDef
00318 {
00319 RegexDef() :capturingGroup ( -1 ) {}
00320 string reString;
00321 int capturingGroup;
00322 };
00323
00324 }
00325 #endif