1
// Scintilla source code edit control
2
/** @file ExternalLexer.cxx
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.
19
#include "Scintilla.h"
22
#include "LexerModule.h"
23
#include "Catalogue.h"
24
#include "ExternalLexer.h"
27
using namespace Scintilla;
30
LexerManager *LexerManager::theInstance = NULL;
32
//------------------------------------------
34
// ExternalLexerModule
36
//------------------------------------------
38
void ExternalLexerModule::SetExternal(GetLexerFactoryFunction fFactory, int index) {
39
fneFactory = fFactory;
40
fnFactory = fFactory(index);
43
//------------------------------------------
47
//------------------------------------------
49
LexerLibrary::LexerLibrary(const char *ModuleName) {
50
// Initialise some members...
55
lib = DynamicLibrary::Load(ModuleName);
57
m_sModuleName = ModuleName;
58
//Cannot use reinterpret_cast because: ANSI C++ forbids casting between pointers to functions and objects
59
GetLexerCountFn GetLexerCount = (GetLexerCountFn)(sptr_t)lib->FindFunction("GetLexerCount");
62
ExternalLexerModule *lex;
65
// Find functions in the DLL
66
GetLexerNameFn GetLexerName = (GetLexerNameFn)(sptr_t)lib->FindFunction("GetLexerName");
67
GetLexerFactoryFunction fnFactory = (GetLexerFactoryFunction)(sptr_t)lib->FindFunction("GetLexerFactory");
69
// Assign a buffer for the lexer name.
73
int nl = GetLexerCount();
75
for (int i = 0; i < nl; i++) {
76
GetLexerName(i, lexname, 100);
77
lex = new ExternalLexerModule(SCLEX_AUTOMATIC, NULL, lexname, NULL);
78
Catalogue::AddLexerModule(lex);
80
// Create a LexerMinder so we don't leak the ExternalLexerModule...
92
// The external lexer needs to know how to call into its DLL to
93
// do its lexing and folding, we tell it here.
94
lex->SetExternal(fnFactory, i);
101
LexerLibrary::~LexerLibrary() {
106
void LexerLibrary::Release() {
121
//------------------------------------------
125
//------------------------------------------
127
/// Return the single LexerManager instance...
128
LexerManager *LexerManager::GetInstance() {
130
theInstance = new LexerManager;
134
/// Delete any LexerManager instance...
135
void LexerManager::DeleteInstance() {
140
/// protected constructor - this is a singleton...
141
LexerManager::LexerManager() {
146
LexerManager::~LexerManager() {
150
void LexerManager::Load(const char *path) {
151
LoadLexerLibrary(path);
154
void LexerManager::LoadLexerLibrary(const char *module) {
155
for (LexerLibrary *ll = first; ll; ll= ll->next) {
156
if (strcmp(ll->m_sModuleName.c_str(), module) == 0)
159
LexerLibrary *lib = new LexerLibrary(module);
169
void LexerManager::Clear() {
171
LexerLibrary *cur = first;
183
//------------------------------------------
187
//------------------------------------------
189
LMMinder::~LMMinder() {
190
LexerManager::DeleteInstance();