]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/KeyWords.cxx
29538d57b5aa7dbcfbb20648bc64e39cda7a9d78
[wxWidgets.git] / src / stc / scintilla / src / KeyWords.cxx
1 // Scintilla source code edit control
2 /** @file KeyWords.cxx
3 ** Colourise for particular languages.
4 **/
5 // Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
7
8 #include <stdlib.h>
9 #include <string.h>
10 #include <ctype.h>
11 #include <stdio.h>
12 #include <stdarg.h>
13
14 #include "Platform.h"
15
16 #include "PropSet.h"
17 #include "Accessor.h"
18 #include "KeyWords.h"
19 #include "Scintilla.h"
20 #include "SciLexer.h"
21
22 #ifdef SCI_NAMESPACE
23 using namespace Scintilla;
24 #endif
25
26 const LexerModule *LexerModule::base = 0;
27 int LexerModule::nextLanguage = SCLEX_AUTOMATIC+1;
28
29 LexerModule::LexerModule(int language_,
30 LexerFunction fnLexer_,
31 const char *languageName_,
32 LexerFunction fnFolder_,
33 const char * const wordListDescriptions_[],
34 int styleBits_) :
35 language(language_),
36 fnLexer(fnLexer_),
37 fnFolder(fnFolder_),
38 wordListDescriptions(wordListDescriptions_),
39 styleBits(styleBits_),
40 languageName(languageName_) {
41 next = base;
42 base = this;
43 if (language == SCLEX_AUTOMATIC) {
44 language = nextLanguage;
45 nextLanguage++;
46 }
47 }
48
49 int LexerModule::GetNumWordLists() const {
50 if (wordListDescriptions == NULL) {
51 return -1;
52 } else {
53 int numWordLists = 0;
54
55 while (wordListDescriptions[numWordLists]) {
56 ++numWordLists;
57 }
58
59 return numWordLists;
60 }
61 }
62
63 const char *LexerModule::GetWordListDescription(int index) const {
64 static const char *emptyStr = "";
65
66 PLATFORM_ASSERT(index < GetNumWordLists());
67 if (index >= GetNumWordLists()) {
68 return emptyStr;
69 } else {
70 return wordListDescriptions[index];
71 }
72 }
73
74 int LexerModule::GetStyleBitsNeeded() const {
75 return styleBits;
76 }
77
78 const LexerModule *LexerModule::Find(int language) {
79 const LexerModule *lm = base;
80 while (lm) {
81 if (lm->language == language) {
82 return lm;
83 }
84 lm = lm->next;
85 }
86 return 0;
87 }
88
89 const LexerModule *LexerModule::Find(const char *languageName) {
90 if (languageName) {
91 const LexerModule *lm = base;
92 while (lm) {
93 if (lm->languageName && 0 == strcmp(lm->languageName, languageName)) {
94 return lm;
95 }
96 lm = lm->next;
97 }
98 }
99 return 0;
100 }
101
102 void LexerModule::Lex(unsigned int startPos, int lengthDoc, int initStyle,
103 WordList *keywordlists[], Accessor &styler) const {
104 if (fnLexer)
105 fnLexer(startPos, lengthDoc, initStyle, keywordlists, styler);
106 }
107
108 void LexerModule::Fold(unsigned int startPos, int lengthDoc, int initStyle,
109 WordList *keywordlists[], Accessor &styler) const {
110 if (fnFolder) {
111 int lineCurrent = styler.GetLine(startPos);
112 // Move back one line in case deletion wrecked current line fold state
113 if (lineCurrent > 0) {
114 lineCurrent--;
115 int newStartPos = styler.LineStart(lineCurrent);
116 lengthDoc += startPos - newStartPos;
117 startPos = newStartPos;
118 initStyle = 0;
119 if (startPos > 0) {
120 initStyle = styler.StyleAt(startPos - 1);
121 }
122 }
123 fnFolder(startPos, lengthDoc, initStyle, keywordlists, styler);
124 }
125 }
126
127 // Alternative historical name for Scintilla_LinkLexers
128 int wxForceScintillaLexers(void) {
129 return Scintilla_LinkLexers();
130 }
131
132 // To add or remove a lexer, add or remove its file and run LexGen.py.
133
134 // Force a reference to all of the Scintilla lexers so that the linker will
135 // not remove the code of the lexers.
136 int Scintilla_LinkLexers() {
137 static int forcer = 0;
138
139 // Shorten the code that declares a lexer and ensures it is linked in by calling a method.
140 #define LINK_LEXER(lexer) extern LexerModule lexer; forcer += lexer.GetLanguage();
141
142 //++Autogenerated -- run src/LexGen.py to regenerate
143 //**\(\tLINK_LEXER(\*);\n\)
144 LINK_LEXER(lmAbaqus);
145 LINK_LEXER(lmAda);
146 LINK_LEXER(lmAns1);
147 LINK_LEXER(lmAPDL);
148 LINK_LEXER(lmAsm);
149 LINK_LEXER(lmASP);
150 LINK_LEXER(lmASY);
151 LINK_LEXER(lmAU3);
152 LINK_LEXER(lmAVE);
153 LINK_LEXER(lmBaan);
154 LINK_LEXER(lmBash);
155 LINK_LEXER(lmBatch);
156 LINK_LEXER(lmBlitzBasic);
157 LINK_LEXER(lmBullant);
158 LINK_LEXER(lmCaml);
159 LINK_LEXER(lmClw);
160 LINK_LEXER(lmClwNoCase);
161 LINK_LEXER(lmCmake);
162 LINK_LEXER(lmConf);
163 LINK_LEXER(lmCPP);
164 LINK_LEXER(lmCPPNoCase);
165 LINK_LEXER(lmCsound);
166 LINK_LEXER(lmCss);
167 LINK_LEXER(lmD);
168 LINK_LEXER(lmDiff);
169 LINK_LEXER(lmEiffel);
170 LINK_LEXER(lmEiffelkw);
171 LINK_LEXER(lmErlang);
172 LINK_LEXER(lmErrorList);
173 LINK_LEXER(lmESCRIPT);
174 LINK_LEXER(lmF77);
175 LINK_LEXER(lmFlagShip);
176 LINK_LEXER(lmForth);
177 LINK_LEXER(lmFortran);
178 LINK_LEXER(lmFreeBasic);
179 LINK_LEXER(lmGAP);
180 LINK_LEXER(lmGui4Cli);
181 LINK_LEXER(lmHaskell);
182 LINK_LEXER(lmHTML);
183 LINK_LEXER(lmInno);
184 LINK_LEXER(lmKix);
185 LINK_LEXER(lmLatex);
186 LINK_LEXER(lmLISP);
187 LINK_LEXER(lmLot);
188 LINK_LEXER(lmLout);
189 LINK_LEXER(lmLua);
190 LINK_LEXER(lmMake);
191 LINK_LEXER(lmMatlab);
192 LINK_LEXER(lmMETAPOST);
193 LINK_LEXER(lmMMIXAL);
194 LINK_LEXER(lmMSSQL);
195 LINK_LEXER(lmNncrontab);
196 LINK_LEXER(lmNsis);
197 LINK_LEXER(lmNull);
198 LINK_LEXER(lmOctave);
199 LINK_LEXER(lmOpal);
200 LINK_LEXER(lmPascal);
201 LINK_LEXER(lmPB);
202 LINK_LEXER(lmPerl);
203 LINK_LEXER(lmPHP);
204 LINK_LEXER(lmPHPSCRIPT);
205 LINK_LEXER(lmPLM);
206 LINK_LEXER(lmPOV);
207 LINK_LEXER(lmProgress);
208 LINK_LEXER(lmProps);
209 LINK_LEXER(lmPS);
210 LINK_LEXER(lmPureBasic);
211 LINK_LEXER(lmPython);
212 LINK_LEXER(lmR);
213 LINK_LEXER(lmREBOL);
214 LINK_LEXER(lmRuby);
215 LINK_LEXER(lmScriptol);
216 LINK_LEXER(lmSmalltalk);
217 LINK_LEXER(lmSpecman);
218 LINK_LEXER(lmSpice);
219 LINK_LEXER(lmSQL);
220 LINK_LEXER(lmTADS3);
221 LINK_LEXER(lmTCL);
222 LINK_LEXER(lmTeX);
223 LINK_LEXER(lmVB);
224 LINK_LEXER(lmVBScript);
225 LINK_LEXER(lmVerilog);
226 LINK_LEXER(lmVHDL);
227 LINK_LEXER(lmXML);
228 LINK_LEXER(lmYAML);
229
230 //--Autogenerated -- end of automatically generated section
231
232 return 1;
233 }