]>
Commit | Line | Data |
---|---|---|
e14d10b0 RD |
1 | // Scintilla source code edit control |
2 | /** @file ExternalLexer.h | |
3 | ** Support external lexers in DLLs. | |
4 | **/ | |
5 | // Copyright 2001 Simon Steele <ss@pnotepad.org>, portions copyright Neil Hodgson. | |
6 | // The License.txt file describes the conditions under which this software may be distributed. | |
7 | ||
8 | #ifndef EXTERNALLEXER_H | |
9 | #define EXTERNALLEXER_H | |
10 | ||
11 | #if PLAT_WIN | |
12 | #define EXT_LEXER_DECL __stdcall | |
e14d10b0 | 13 | #else |
88a8b04e | 14 | #define EXT_LEXER_DECL |
e14d10b0 RD |
15 | #endif |
16 | ||
17 | // External Lexer function definitions... | |
18 | typedef void (EXT_LEXER_DECL *ExtLexerFunction)(unsigned int lexer, unsigned int startPos, int length, int initStyle, | |
19 | char *words[], WindowID window, char *props); | |
20 | typedef void (EXT_LEXER_DECL *ExtFoldFunction)(unsigned int lexer, unsigned int startPos, int length, int initStyle, | |
21 | char *words[], WindowID window, char *props); | |
22 | typedef void* (EXT_LEXER_DECL *GetLexerFunction)(unsigned int Index); | |
23 | typedef int (EXT_LEXER_DECL *GetLexerCountFn)(); | |
24 | typedef void (EXT_LEXER_DECL *GetLexerNameFn)(unsigned int Index, char *name, int buflength); | |
25 | ||
26 | //class DynamicLibrary; | |
27 | ||
28 | /// Sub-class of LexerModule to use an external lexer. | |
29 | class ExternalLexerModule : protected LexerModule { | |
30 | protected: | |
31 | ExtLexerFunction fneLexer; | |
32 | ExtFoldFunction fneFolder; | |
33 | int externalLanguage; | |
34 | char name[100]; | |
35 | public: | |
88a8b04e | 36 | ExternalLexerModule(int language_, LexerFunction fnLexer_, |
e14d10b0 RD |
37 | const char *languageName_=0, LexerFunction fnFolder_=0) : LexerModule(language_, fnLexer_, 0, fnFolder_){ |
38 | strncpy(name, languageName_, sizeof(name)); | |
39 | languageName = name; | |
40 | }; | |
41 | virtual void Lex(unsigned int startPos, int lengthDoc, int initStyle, | |
42 | WordList *keywordlists[], Accessor &styler) const; | |
43 | virtual void Fold(unsigned int startPos, int lengthDoc, int initStyle, | |
44 | WordList *keywordlists[], Accessor &styler) const; | |
45 | virtual void SetExternal(ExtLexerFunction fLexer, ExtFoldFunction fFolder, int index); | |
46 | }; | |
47 | ||
48 | /// LexerMinder points to an ExternalLexerModule - so we don't leak them. | |
49 | class LexerMinder { | |
50 | public: | |
51 | ExternalLexerModule *self; | |
52 | LexerMinder *next; | |
53 | }; | |
54 | ||
55 | /// LexerLibrary exists for every External Lexer DLL, contains LexerMinders. | |
56 | class LexerLibrary { | |
57 | DynamicLibrary *lib; | |
58 | LexerMinder *first; | |
59 | LexerMinder *last; | |
60 | ||
61 | public: | |
62 | LexerLibrary(const char* ModuleName); | |
63 | ~LexerLibrary(); | |
64 | void Release(); | |
88a8b04e | 65 | |
e14d10b0 RD |
66 | LexerLibrary *next; |
67 | SString m_sModuleName; | |
68 | }; | |
69 | ||
70 | /// LexerManager manages external lexers, contains LexerLibrarys. | |
71 | class LexerManager { | |
72 | public: | |
73 | ~LexerManager(); | |
88a8b04e | 74 | |
e14d10b0 RD |
75 | static LexerManager *GetInstance(); |
76 | static void DeleteInstance(); | |
88a8b04e | 77 | |
e14d10b0 RD |
78 | void Load(const char* path); |
79 | void Clear(); | |
80 | ||
81 | private: | |
82 | LexerManager(); | |
83 | static LexerManager *theInstance; | |
84 | ||
85 | void LoadLexerLibrary(const char* module); | |
86 | LexerLibrary *first; | |
87 | LexerLibrary *last; | |
88 | }; | |
89 | ||
90 | class LMMinder { | |
91 | public: | |
92 | ~LMMinder(); | |
93 | }; | |
94 | ||
95 | #endif |