languagedefinition.h

00001 /***************************************************************************
00002                           languagedefinition.h  -  description
00003                              -------------------
00004     begin                : Wed Nov 28 2001
00005     copyright            : (C) 2001 by Andre Simon
00006     email                : andre.simon1@gmx.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef LANGUAGEDEFINITION_H
00019 #define LANGUAGEDEFINITION_H
00020 
00021 #include <string>
00022 #include <map>
00023 #include <iostream>
00024 #include <fstream>
00025 #include <iterator>
00026 #include <sstream>
00027 
00028 #include "configurationreader.h"
00029 #include "platform_fs.h"
00030 #include "enums.h"
00031 #include "re/Pattern.h"
00032 
00033 namespace highlight {
00034 
00035 class RegexElement;
00036 
00038 typedef map <string, int> KeywordMap;
00039 
00040 
00049 class LanguageDefinition  {
00050 
00051   public:
00052 
00053     LanguageDefinition();
00054 
00055     ~LanguageDefinition();
00056 
00058     string &getSymbolString();
00059 
00061     unsigned char getRawStringPrefix();
00062 
00064     unsigned char getContinuationChar();
00065 
00066     // /** \return List of characters allowed within identifiers */
00067     //string &getAllowedChars();
00068 
00070     bool getSyntaxHighlight();
00071 
00073     bool isIgnoreCase();
00074 
00077     int isKeyword(const string &s);
00078 
00083     bool load(const string& langDefPath, bool clear=true);
00084 
00086     bool isVHDL();
00087 
00089     bool allowNestedMLComments();
00090 
00092     bool highlightingDisabled();
00093 
00096     bool needsReload(const string &langDefPath);
00097 
00099     bool enableReformatting();
00100 
00102     bool allowExtEscSeq();
00103 
00106     unsigned int getDelimPrefixClassID(const string& prefix);
00107 
00109     const KeywordMap& getKeywords() const;
00110 
00112     const vector<string>& getKeywordClasses() const;
00113 
00115      vector<RegexElement*>& getRegexElements()  {return regex;};
00116 
00117   private:
00118     // string containing symbols and their IDs of the programming language
00119     string symbolString;
00120 
00121     // path to laoded language definition
00122     string currentPath;
00123 
00124     KeywordMap keywords;
00125 
00126     vector <string> keywordClasses;
00127 
00128     vector <RegexElement*> regex;
00129 
00130     KeywordMap delimiterPrefixes;
00131 
00132     // keywords are not case sensitive if set
00133     bool ignoreCase,
00134     disableHighlighting,
00135     allowExtEscape,
00136 
00137     // switch to enable VHDL workarounds
00138     vhdlMode,
00139 
00140     // allow nested multi line comment blocks
00141     allowNestedComments,
00142 
00143     // single line comments have to start in coloumn 1 if set
00144     fullLineComment,
00145 
00146     // code formatting is enabled if set
00147     reformatCode;
00148 
00149     // Character, die eine Variable bzw. ein Keyword kennzeichnen
00150     unsigned char rawStringPrefix,
00151                   continuationChar;
00152 
00154     void reset();
00155 
00156     // add a symbol sequencs to the symbolStream
00157     void addSimpleSymbol(stringstream& symbolStream, State state,
00158                          const string& paramValue );
00159 
00160     void addSymbol(stringstream& symbolStream,
00161                                        State stateBegin,
00162                                        State stateEnd,
00163                                        bool isDelimiter,
00164                                        const string& paramValue,
00165                                        unsigned int classID=0 );
00166 
00167     // add a delimiter symbol sequencs to the symbolStream
00168     void addDelimiterSymbol(stringstream& symbolStream,
00169                             State stateBegin, State stateEnd,
00170                             const string& paramValue,
00171                             unsigned int classID=0);
00172 
00173     bool getFlag( string& paramValue);
00174 
00175     unsigned char getSymbol(const string& paramValue);
00176 
00177     // generate a unique class ID of the class name
00178     unsigned int generateNewKWClass(const string& newClassName);
00179 
00180     // add keywords to the given class
00181     void addKeywords(const string &kwList,State stateBegin, State stateEnd, int classID);
00182 
00183     string extractRE(const string &paramValue);
00184 
00185   };
00186 
00187 
00188   class RegexElement {
00189     public:
00190     RegexElement():open(STANDARD), end(STANDARD), rePattern(NULL), kwClass(0)
00191         {
00192         }
00193 
00194         RegexElement(State oState, State eState,
00195                      Pattern *re, unsigned int cID=0):open(oState), end(eState), rePattern(re), kwClass(cID)
00196         {
00197        // cerr << "new re element "<<  rePattern->getPattern() <<" open: "<<open<<" end "<<end<<"\n";
00198         }
00199 
00200         ~RegexElement() { delete rePattern; }
00201 
00202         State open, end;
00203         Pattern *rePattern;
00204         unsigned int kwClass;
00205   };
00206 
00207 }
00208 #endif

Generated on Fri Apr 27 13:12:36 2007 for Highlight Code Converter by  doxygen 1.5.2