| 1 |
// Scintilla source code edit control |
| 2 |
/** @file LexerBase.cxx |
| 3 |
** A simple lexer with no state. |
| 4 |
**/ |
| 5 |
// Copyright 1998-2010 by Neil Hodgson <[email protected]> |
| 6 |
// The License.txt file describes the conditions under which this software may be distributed. |
| 7 |
|
| 8 |
#include <cstdlib> |
| 9 |
#include <cassert> |
| 10 |
#include <cstring> |
| 11 |
|
| 12 |
#include <string> |
| 13 |
#include <string_view> |
| 14 |
|
| 15 |
#include "ILexer.h" |
| 16 |
#include "Scintilla.h" |
| 17 |
#include "SciLexer.h" |
| 18 |
|
| 19 |
#include "PropSetSimple.h" |
| 20 |
#include "WordList.h" |
| 21 |
#include "LexAccessor.h" |
| 22 |
#include "Accessor.h" |
| 23 |
#include "LexerModule.h" |
| 24 |
#include "LexerBase.h" |
| 25 |
|
| 26 |
using namespace Lexilla; |
| 27 |
|
| 28 |
static const char styleSubable[] = { 0 }; |
| 29 |
|
| 30 |
LexerBase::LexerBase(const LexicalClass *lexClasses_, size_t nClasses_) : |
| 31 |
lexClasses(lexClasses_), nClasses(nClasses_) { |
| 32 |
for (int wl = 0; wl < numWordLists; wl++) |
| 33 |
keyWordLists[wl] = new WordList; |
| 34 |
keyWordLists[numWordLists] = nullptr; |
| 35 |
} |
| 36 |
|
| 37 |
LexerBase::~LexerBase() { |
| 38 |
for (int wl = 0; wl < numWordLists; wl++) { |
| 39 |
delete keyWordLists[wl]; |
| 40 |
keyWordLists[wl] = nullptr; |
| 41 |
} |
| 42 |
keyWordLists[numWordLists] = nullptr; |
| 43 |
} |
| 44 |
|
| 45 |
void SCI_METHOD LexerBase::Release() { |
| 46 |
delete this; |
| 47 |
} |
| 48 |
|
| 49 |
int SCI_METHOD LexerBase::Version() const { |
| 50 |
return Scintilla::lvRelease5; |
| 51 |
} |
| 52 |
|
| 53 |
const char * SCI_METHOD LexerBase::PropertyNames() { |
| 54 |
return ""; |
| 55 |
} |
| 56 |
|
| 57 |
int SCI_METHOD LexerBase::PropertyType(const char *) { |
| 58 |
return SC_TYPE_BOOLEAN; |
| 59 |
} |
| 60 |
|
| 61 |
const char * SCI_METHOD LexerBase::DescribeProperty(const char *) { |
| 62 |
return ""; |
| 63 |
} |
| 64 |
|
| 65 |
Sci_Position SCI_METHOD LexerBase::PropertySet(const char *key, const char *val) { |
| 66 |
if (props.Set(key, val)) { |
| 67 |
return 0; |
| 68 |
} else { |
| 69 |
return -1; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
const char *SCI_METHOD LexerBase::PropertyGet(const char *key) { |
| 74 |
return props.Get(key); |
| 75 |
} |
| 76 |
|
| 77 |
const char * SCI_METHOD LexerBase::DescribeWordListSets() { |
| 78 |
return ""; |
| 79 |
} |
| 80 |
|
| 81 |
Sci_Position SCI_METHOD LexerBase::WordListSet(int n, const char *wl) { |
| 82 |
if (n < numWordLists) { |
| 83 |
if (keyWordLists[n]->Set(wl)) { |
| 84 |
return 0; |
| 85 |
} |
| 86 |
} |
| 87 |
return -1; |
| 88 |
} |
| 89 |
|
| 90 |
void * SCI_METHOD LexerBase::PrivateCall(int, void *) { |
| 91 |
return nullptr; |
| 92 |
} |
| 93 |
|
| 94 |
int SCI_METHOD LexerBase::LineEndTypesSupported() { |
| 95 |
return SC_LINE_END_TYPE_DEFAULT; |
| 96 |
} |
| 97 |
|
| 98 |
int SCI_METHOD LexerBase::AllocateSubStyles(int, int) { |
| 99 |
return -1; |
| 100 |
} |
| 101 |
|
| 102 |
int SCI_METHOD LexerBase::SubStylesStart(int) { |
| 103 |
return -1; |
| 104 |
} |
| 105 |
|
| 106 |
int SCI_METHOD LexerBase::SubStylesLength(int) { |
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
int SCI_METHOD LexerBase::StyleFromSubStyle(int subStyle) { |
| 111 |
return subStyle; |
| 112 |
} |
| 113 |
|
| 114 |
int SCI_METHOD LexerBase::PrimaryStyleFromStyle(int style) { |
| 115 |
return style; |
| 116 |
} |
| 117 |
|
| 118 |
void SCI_METHOD LexerBase::FreeSubStyles() { |
| 119 |
} |
| 120 |
|
| 121 |
void SCI_METHOD LexerBase::SetIdentifiers(int, const char *) { |
| 122 |
} |
| 123 |
|
| 124 |
int SCI_METHOD LexerBase::DistanceToSecondaryStyles() { |
| 125 |
return 0; |
| 126 |
} |
| 127 |
|
| 128 |
const char * SCI_METHOD LexerBase::GetSubStyleBases() { |
| 129 |
return styleSubable; |
| 130 |
} |
| 131 |
|
| 132 |
int SCI_METHOD LexerBase::NamedStyles() { |
| 133 |
return static_cast<int>(nClasses); |
| 134 |
} |
| 135 |
|
| 136 |
const char * SCI_METHOD LexerBase::NameOfStyle(int style) { |
| 137 |
return (style < NamedStyles()) ? lexClasses[style].name : ""; |
| 138 |
} |
| 139 |
|
| 140 |
const char * SCI_METHOD LexerBase::TagsOfStyle(int style) { |
| 141 |
return (style < NamedStyles()) ? lexClasses[style].tags : ""; |
| 142 |
} |
| 143 |
|
| 144 |
const char * SCI_METHOD LexerBase::DescriptionOfStyle(int style) { |
| 145 |
return (style < NamedStyles()) ? lexClasses[style].description : ""; |
| 146 |
} |
| 147 |
|
| 148 |
// ILexer5 methods |
| 149 |
|
| 150 |
const char *SCI_METHOD LexerBase::GetName() { |
| 151 |
return ""; |
| 152 |
} |
| 153 |
|
| 154 |
int SCI_METHOD LexerBase::GetIdentifier() { |
| 155 |
return SCLEX_AUTOMATIC; |
| 156 |
} |