]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/ExternalLexer.h
01d9ac71410d9b67c0e372d1ddd0600689e2eac3
[wxWidgets.git] / contrib / src / stc / scintilla / src / ExternalLexer.h
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
13 #elif PLAT_GTK
14 #define EXT_LEXER_DECL
15 #endif
16
17 #if PLAT_WX
18 #ifdef __WXMSW__
19 #define EXT_LEXER_DECL __stdcall
20 #else
21 #define EXT_LEXER_DECL
22 #endif
23 #endif
24
25 // External Lexer function definitions...
26 typedef void (EXT_LEXER_DECL *ExtLexerFunction)(unsigned int lexer, unsigned int startPos, int length, int initStyle,
27 char *words[], WindowID window, char *props);
28 typedef void (EXT_LEXER_DECL *ExtFoldFunction)(unsigned int lexer, unsigned int startPos, int length, int initStyle,
29 char *words[], WindowID window, char *props);
30 typedef void* (EXT_LEXER_DECL *GetLexerFunction)(unsigned int Index);
31 typedef int (EXT_LEXER_DECL *GetLexerCountFn)();
32 typedef void (EXT_LEXER_DECL *GetLexerNameFn)(unsigned int Index, char *name, int buflength);
33
34 //class DynamicLibrary;
35
36 /// Sub-class of LexerModule to use an external lexer.
37 class ExternalLexerModule : protected LexerModule {
38 protected:
39 ExtLexerFunction fneLexer;
40 ExtFoldFunction fneFolder;
41 int externalLanguage;
42 char name[100];
43 public:
44 ExternalLexerModule(int language_, LexerFunction fnLexer_,
45 const char *languageName_=0, LexerFunction fnFolder_=0) : LexerModule(language_, fnLexer_, 0, fnFolder_){
46 strncpy(name, languageName_, sizeof(name));
47 languageName = name;
48 };
49 virtual void Lex(unsigned int startPos, int lengthDoc, int initStyle,
50 WordList *keywordlists[], Accessor &styler) const;
51 virtual void Fold(unsigned int startPos, int lengthDoc, int initStyle,
52 WordList *keywordlists[], Accessor &styler) const;
53 virtual void SetExternal(ExtLexerFunction fLexer, ExtFoldFunction fFolder, int index);
54 };
55
56 /// LexerMinder points to an ExternalLexerModule - so we don't leak them.
57 class LexerMinder {
58 public:
59 ExternalLexerModule *self;
60 LexerMinder *next;
61 };
62
63 /// LexerLibrary exists for every External Lexer DLL, contains LexerMinders.
64 class LexerLibrary {
65 DynamicLibrary *lib;
66 LexerMinder *first;
67 LexerMinder *last;
68
69 public:
70 LexerLibrary(const char* ModuleName);
71 ~LexerLibrary();
72 void Release();
73
74 LexerLibrary *next;
75 SString m_sModuleName;
76 };
77
78 /// LexerManager manages external lexers, contains LexerLibrarys.
79 class LexerManager {
80 public:
81 ~LexerManager();
82
83 static LexerManager *GetInstance();
84 static void DeleteInstance();
85
86 void Load(const char* path);
87 void Clear();
88
89 private:
90 LexerManager();
91 static LexerManager *theInstance;
92
93 void LoadLexerLibrary(const char* module);
94 LexerLibrary *first;
95 LexerLibrary *last;
96 };
97
98 class LMMinder {
99 public:
100 ~LMMinder();
101 };
102
103 #endif