1 // Scintilla source code edit control
2 /** @file ExternalLexer.h
3 ** Support external lexers in DLLs.
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.
8 #ifndef EXTERNALLEXER_H
9 #define EXTERNALLEXER_H
12 #define EXT_LEXER_DECL __stdcall
14 #define EXT_LEXER_DECL
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
);
26 //class DynamicLibrary;
28 /// Sub-class of LexerModule to use an external lexer.
29 class ExternalLexerModule
: protected LexerModule
{
31 ExtLexerFunction fneLexer
;
32 ExtFoldFunction fneFolder
;
36 ExternalLexerModule(int language_
, LexerFunction fnLexer_
,
37 const char *languageName_
=0, LexerFunction fnFolder_
=0) : LexerModule(language_
, fnLexer_
, 0, fnFolder_
){
38 strncpy(name
, languageName_
, sizeof(name
));
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
);
48 /// LexerMinder points to an ExternalLexerModule - so we don't leak them.
51 ExternalLexerModule
*self
;
55 /// LexerLibrary exists for every External Lexer DLL, contains LexerMinders.
62 LexerLibrary(const char* ModuleName
);
67 SString m_sModuleName
;
70 /// LexerManager manages external lexers, contains LexerLibrarys.
75 static LexerManager
*GetInstance();
76 static void DeleteInstance();
78 void Load(const char* path
);
83 static LexerManager
*theInstance
;
85 void LoadLexerLibrary(const char* module);