]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/KeyWords.cxx
8a03aa8ac4fbb42e7eb46b1793bfabccb2912682
[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 static void ColouriseNullDoc(unsigned int startPos, int length, int, WordList *[],
116 Accessor &styler) {
117 // Null language means all style bytes are 0 so just mark the end - no need to fill in.
118 if (length > 0) {
119 styler.StartAt(startPos + length - 1);
120 styler.StartSegment(startPos + length - 1);
121 styler.ColourTo(startPos + length - 1, 0);
122 }
123 }
124
125 LexerModule lmNull(SCLEX_NULL, ColouriseNullDoc, "null");
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(lmAda);
145 LINK_LEXER(lmAVE);
146 LINK_LEXER(lmBaan);
147 LINK_LEXER(lmBullant);
148 LINK_LEXER(lmConf);
149 LINK_LEXER(lmCPP);
150 LINK_LEXER(lmTCL);
151 LINK_LEXER(lmNncrontab);
152 LINK_LEXER(lmEiffel);
153 LINK_LEXER(lmEiffelkw);
154 LINK_LEXER(lmHTML);
155 LINK_LEXER(lmXML);
156 LINK_LEXER(lmASP);
157 LINK_LEXER(lmPHP);
158 LINK_LEXER(lmLISP);
159 LINK_LEXER(lmLua);
160 LINK_LEXER(lmMatlab);
161 LINK_LEXER(lmBatch);
162 LINK_LEXER(lmDiff);
163 LINK_LEXER(lmProps);
164 LINK_LEXER(lmMake);
165 LINK_LEXER(lmErrorList);
166 LINK_LEXER(lmLatex);
167 LINK_LEXER(lmPascal);
168 LINK_LEXER(lmPerl);
169 LINK_LEXER(lmPython);
170 LINK_LEXER(lmRuby);
171 LINK_LEXER(lmSQL);
172 LINK_LEXER(lmVB);
173 LINK_LEXER(lmVBScript);
174
175 //--Autogenerated -- end of automatically generated section
176
177 return 1;
178 }