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