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