1 // Scintilla source code edit control 2 /** @file LexerModule.h 3 ** Colourise for particular languages. 4 **/ 5 // Copyright 1998-2001 by Neil Hodgson <[email protected]> 6 // The License.txt file describes the conditions under which this software may be distributed. 7 8 #ifndef LEXERMODULE_H 9 #define LEXERMODULE_H 10 11 namespace Scintilla { 12 13 class Accessor; 14 class WordList; 15 struct LexicalClass; 16 17 typedef void (*LexerFunction)(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, 18 WordList *keywordlists[], Accessor &styler); 19 typedef ILexer5 *(*LexerFactoryFunction)(); 20 21 /** 22 * A LexerModule is responsible for lexing and folding a particular language. 23 * The Catalogue class maintains a list of LexerModules which can be searched to find a 24 * module appropriate to a particular language. 25 * The ExternalLexerModule subclass holds lexers loaded from DLLs or shared libraries. 26 */ 27 class LexerModule { 28 protected: 29 int language; 30 LexerFunction fnLexer; 31 LexerFunction fnFolder; 32 LexerFactoryFunction fnFactory; 33 const char * const * wordListDescriptions; 34 const LexicalClass *lexClasses; 35 size_t nClasses; 36 37 public: 38 const char *languageName; 39 LexerModule( 40 int language_, 41 LexerFunction fnLexer_, 42 const char *languageName_=nullptr, 43 LexerFunction fnFolder_= nullptr, 44 const char * const wordListDescriptions_[]=nullptr, 45 const LexicalClass *lexClasses_=nullptr, 46 size_t nClasses_=0) noexcept; 47 LexerModule( 48 int language_, 49 LexerFactoryFunction fnFactory_, 50 const char *languageName_, 51 const char * const wordListDescriptions_[]=nullptr) noexcept; 52 int GetLanguage() const noexcept; 53 54 // -1 is returned if no WordList information is available 55 int GetNumWordLists() const noexcept; 56 const char *GetWordListDescription(int index) const noexcept; 57 const LexicalClass *LexClasses() const noexcept; 58 size_t NamedStyles() const noexcept; 59 60 ILexer5 *Create() const; 61 62 void Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, 63 WordList *keywordlists[], Accessor &styler) const; 64 void Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, 65 WordList *keywordlists[], Accessor &styler) const; 66 67 friend class CatalogueModules; 68 }; 69 70 inline int Maximum(int a, int b) noexcept { 71 return (a > b) ? a : b; 72 } 73 74 // Shut up annoying Visual C++ warnings: 75 #ifdef _MSC_VER 76 #pragma warning(disable: 4244 4456 4457) 77 #endif 78 79 // Turn off shadow warnings for lexers as may be maintained by others 80 #if defined(__GNUC__) 81 #pragma GCC diagnostic ignored "-Wshadow" 82 #endif 83 84 // Clang doesn't like omitting braces in array initialization but they just add 85 // noise to LexicalClass arrays in lexers 86 #if defined(__clang__) 87 #pragma clang diagnostic ignored "-Wmissing-braces" 88 #endif 89 90 } 91 92 #endif 93