| 1 |
// Scintilla source code edit control |
| 2 |
/** @file CatalogueModules.h |
| 3 |
** Lexer infrastructure. |
| 4 |
** Contains a list of LexerModules which can be searched to find a module appropriate for a |
| 5 |
** particular language. |
| 6 |
**/ |
| 7 |
// Copyright 1998-2010 by Neil Hodgson <[email protected]> |
| 8 |
// The License.txt file describes the conditions under which this software may be distributed. |
| 9 |
|
| 10 |
#ifndef CATALOGUEMODULES_H |
| 11 |
#define CATALOGUEMODULES_H |
| 12 |
|
| 13 |
namespace Lexilla { |
| 14 |
|
| 15 |
class CatalogueModules { |
| 16 |
std::vector<const LexerModule *> lexerCatalogue; |
| 17 |
public: |
| 18 |
const LexerModule *Find(int language) const noexcept { |
| 19 |
for (const LexerModule *lm : lexerCatalogue) { |
| 20 |
if (lm->GetLanguage() == language) { |
| 21 |
return lm; |
| 22 |
} |
| 23 |
} |
| 24 |
return nullptr; |
| 25 |
} |
| 26 |
|
| 27 |
const LexerModule *Find(const char *languageName) const noexcept { |
| 28 |
if (languageName) { |
| 29 |
for (const LexerModule *lm : lexerCatalogue) { |
| 30 |
if (lm->languageName && (0 == strcmp(lm->languageName, languageName))) { |
| 31 |
return lm; |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
return nullptr; |
| 36 |
} |
| 37 |
|
| 38 |
void AddLexerModule(const LexerModule *plm) { |
| 39 |
lexerCatalogue.push_back(plm); |
| 40 |
} |
| 41 |
|
| 42 |
void AddLexerModules(std::initializer_list<const LexerModule *> modules) { |
| 43 |
lexerCatalogue.insert(lexerCatalogue.end(), modules); |
| 44 |
} |
| 45 |
|
| 46 |
size_t Count() const noexcept { |
| 47 |
return lexerCatalogue.size(); |
| 48 |
} |
| 49 |
|
| 50 |
const char *Name(size_t index) const noexcept { |
| 51 |
if (index < lexerCatalogue.size()) { |
| 52 |
return lexerCatalogue[index]->languageName; |
| 53 |
} |
| 54 |
return ""; |
| 55 |
} |
| 56 |
|
| 57 |
LexerFactoryFunction Factory(size_t index) const noexcept { |
| 58 |
// Works for object lexers but not for function lexers |
| 59 |
return lexerCatalogue[index]->fnFactory; |
| 60 |
} |
| 61 |
|
| 62 |
Scintilla::ILexer5 *Create(size_t index) const { |
| 63 |
const LexerModule *plm = lexerCatalogue[index]; |
| 64 |
if (!plm) { |
| 65 |
return nullptr; |
| 66 |
} |
| 67 |
return plm->Create(); |
| 68 |
} |
| 69 |
}; |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
#endif |