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