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 <neilh@scintilla.org> |
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<LexerModule *> lexerCatalogue; |
17 | public: |
18 | const LexerModule *Find(int language) const { |
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(LexerModule *plm) { |
39 | lexerCatalogue.push_back(plm); |
40 | } |
41 | |
42 | void AddLexerModules(std::initializer_list<LexerModule *> modules) { |
43 | lexerCatalogue.insert(lexerCatalogue.end(), modules); |
44 | } |
45 | |
46 | unsigned int Count() const noexcept { |
47 | return static_cast<unsigned int>(lexerCatalogue.size()); |
48 | } |
49 | |
50 | const char *Name(unsigned int index) const noexcept { |
51 | if (index < static_cast<unsigned int>(lexerCatalogue.size())) { |
52 | return lexerCatalogue[index]->languageName; |
53 | } else { |
54 | return ""; |
55 | } |
56 | } |
57 | |
58 | LexerFactoryFunction Factory(unsigned int index) const noexcept { |
59 | // Works for object lexers but not for function lexers |
60 | return lexerCatalogue[index]->fnFactory; |
61 | } |
62 | |
63 | Scintilla::ILexer5 *Create(unsigned int index) const { |
64 | const LexerModule *plm = lexerCatalogue[index]; |
65 | if (!plm) { |
66 | return nullptr; |
67 | } |
68 | return plm->Create(); |
69 | } |
70 | }; |
71 | |
72 | } |
73 | |
74 | #endif |
75 |