aboutsummaryrefslogtreecommitdiffhomepage
path: root/lexlib
diff options
context:
space:
mode:
authormitchell <unknown>2020-01-03 19:46:53 -0500
committermitchell <unknown>2020-01-03 19:46:53 -0500
commitb6d260731bddb23d63f4a0990305b1d9501f7cf8 (patch)
tree2ec6039f887cb14498e469973b68aaca7a2c939e /lexlib
parent8eb134dbbd44002f3acd90d91550875f161136fa (diff)
downloadscintilla-mirror-b6d260731bddb23d63f4a0990305b1d9501f7cf8.tar.gz
Backport: Move collection of modules from Catalogue.cxx to CatalogueModules.h so it can be reused.
Backport of changeset 7866:fff1071ea1db.
Diffstat (limited to 'lexlib')
-rw-r--r--lexlib/CatalogueModules.h70
-rw-r--r--lexlib/LexerModule.h2
2 files changed, 71 insertions, 1 deletions
diff --git a/lexlib/CatalogueModules.h b/lexlib/CatalogueModules.h
new file mode 100644
index 000000000..00ac88d62
--- /dev/null
+++ b/lexlib/CatalogueModules.h
@@ -0,0 +1,70 @@
+// Scintilla source code edit control
+/** @file CatalogueModules.h
+ ** Lexer infrastructure.
+ ** Contains a list of LexerModules which can be searched to find a module appropriate for a
+ ** particular language.
+ **/
+// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#ifndef CATALOGUEMODULES_H
+#define CATALOGUEMODULES_H
+
+namespace Scintilla {
+
+class CatalogueModules {
+ std::vector<LexerModule *> lexerCatalogue;
+public:
+ const LexerModule *Find(int language) {
+ for (const LexerModule *lm : lexerCatalogue) {
+ if (lm->GetLanguage() == language) {
+ return lm;
+ }
+ }
+ return nullptr;
+ }
+
+ const LexerModule *Find(const char *languageName) {
+ if (languageName) {
+ for (const LexerModule *lm : lexerCatalogue) {
+ if (lm->languageName && (0 == strcmp(lm->languageName, languageName))) {
+ return lm;
+ }
+ }
+ }
+ return nullptr;
+ }
+
+ void AddLexerModule(LexerModule *plm) {
+ lexerCatalogue.push_back(plm);
+ }
+
+ unsigned int Count() {
+ return static_cast<unsigned int>(lexerCatalogue.size());
+ }
+
+ const char *Name(unsigned int index) {
+ if (index < static_cast<unsigned int>(lexerCatalogue.size())) {
+ return lexerCatalogue[index]->languageName;
+ } else {
+ return "";
+ }
+ }
+
+ LexerFactoryFunction Factory(unsigned int index) {
+ // Works for object lexers but not for function lexers
+ return lexerCatalogue[index]->fnFactory;
+ }
+
+ ILexer *Create(unsigned int index) {
+ const LexerModule *plm = lexerCatalogue[index];
+ if (!plm) {
+ return nullptr;
+ }
+ return plm->Create();
+ }
+};
+
+}
+
+#endif
diff --git a/lexlib/LexerModule.h b/lexlib/LexerModule.h
index 1b3ad2f30..096df5042 100644
--- a/lexlib/LexerModule.h
+++ b/lexlib/LexerModule.h
@@ -65,7 +65,7 @@ public:
virtual void Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
WordList *keywordlists[], Accessor &styler) const;
- friend class Catalogue;
+ friend class CatalogueModules;
};
inline int Maximum(int a, int b) {