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