]> git.saurik.com Git - wxWidgets.git/blame - src/stc/scintilla/src/KeyWords.cxx
improved error messages
[wxWidgets.git] / src / stc / scintilla / src / KeyWords.cxx
CommitLineData
65ec6247
RD
1// Scintilla source code edit control
2/** @file KeyWords.cxx
3 ** Colourise for particular languages.
4 **/
1a2fb4cd 5// Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
9ce192d4
RD
6// The License.txt file describes the conditions under which this software may be distributed.
7
65ec6247
RD
8#include <stdlib.h>
9#include <string.h>
10#include <ctype.h>
11#include <stdio.h>
12#include <stdarg.h>
9ce192d4
RD
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
1a2fb4cd 22const LexerModule *LexerModule::base = 0;
65ec6247 23int LexerModule::nextLanguage = SCLEX_AUTOMATIC+1;
f6bcfd97 24
65ec6247
RD
25LexerModule::LexerModule(int language_, LexerFunction fnLexer_,
26 const char *languageName_, LexerFunction fnFolder_) :
27 language(language_),
65ec6247 28 fnLexer(fnLexer_),
1a2fb4cd
RD
29 fnFolder(fnFolder_),
30 languageName(languageName_) {
f6bcfd97
BP
31 next = base;
32 base = this;
65ec6247
RD
33 if (language == SCLEX_AUTOMATIC) {
34 language = nextLanguage;
35 nextLanguage++;
36 }
f6bcfd97
BP
37}
38
1a2fb4cd
RD
39const LexerModule *LexerModule::Find(int language) {
40 const LexerModule *lm = base;
f6bcfd97
BP
41 while (lm) {
42 if (lm->language == language) {
65ec6247 43 return lm;
f6bcfd97
BP
44 }
45 lm = lm->next;
46 }
65ec6247
RD
47 return 0;
48}
49
1a2fb4cd 50const LexerModule *LexerModule::Find(const char *languageName) {
65ec6247 51 if (languageName) {
1a2fb4cd 52 const LexerModule *lm = base;
65ec6247
RD
53 while (lm) {
54 if (lm->languageName && 0 == strcmp(lm->languageName, languageName)) {
55 return lm;
56 }
57 lm = lm->next;
58 }
59 }
60 return 0;
61}
62
63void LexerModule::Lex(unsigned int startPos, int lengthDoc, int initStyle,
1a2fb4cd 64 WordList *keywordlists[], Accessor &styler) const {
65ec6247
RD
65 if (fnLexer)
66 fnLexer(startPos, lengthDoc, initStyle, keywordlists, styler);
67}
68
69void LexerModule::Fold(unsigned int startPos, int lengthDoc, int initStyle,
1a2fb4cd 70 WordList *keywordlists[], Accessor &styler) const {
65ec6247
RD
71 if (fnFolder) {
72 int lineCurrent = styler.GetLine(startPos);
73 // Move back one line in case deletion wrecked current line fold state
74 if (lineCurrent > 0) {
75 lineCurrent--;
76 int newStartPos = styler.LineStart(lineCurrent);
77 lengthDoc += startPos - newStartPos;
78 startPos = newStartPos;
79 initStyle = 0;
80 if (startPos > 0) {
81 initStyle = styler.StyleAt(startPos - 1);
82 }
83 }
84 fnFolder(startPos, lengthDoc, initStyle, keywordlists, styler);
85 }
86}
87
88static void ColouriseNullDoc(unsigned int startPos, int length, int, WordList *[],
89 Accessor &styler) {
f6bcfd97 90 // Null language means all style bytes are 0 so just mark the end - no need to fill in.
65ec6247
RD
91 if (length > 0) {
92 styler.StartAt(startPos + length - 1);
93 styler.StartSegment(startPos + length - 1);
94 styler.ColourTo(startPos + length - 1, 0);
9ce192d4
RD
95 }
96}
65ec6247
RD
97
98LexerModule lmNull(SCLEX_NULL, ColouriseNullDoc, "null");
99
4e4dc03d 100#ifdef __vms
1a2fb4cd
RD
101#define LINK_LEXERS
102#endif
103
104#ifdef LINK_LEXERS
65ec6247
RD
105
106// The following code forces a reference to all of the Scintilla lexers.
107// If we don't do something like this, then the linker tends to "optimize"
108// them away. (eric@sourcegear.com)
109
110// Taken from wxWindow's stc.cpp. Walter.
111
112int wxForceScintillaLexers(void) {
1a2fb4cd
RD
113 return Scintilla_LinkLexers();
114}
115
116int Scintilla_LinkLexers() {
65ec6247
RD
117 extern LexerModule lmAda;
118 extern LexerModule lmAVE;
1a2fb4cd 119 extern LexerModule lmBaan;
b8b0e402 120 extern LexerModule lmBatch;
65ec6247 121 extern LexerModule lmConf;
65ec6247 122 extern LexerModule lmCPP;
b8b0e402
RD
123 extern LexerModule lmDiff;
124 extern LexerModule lmEiffel;
125 extern LexerModule lmEiffelkw;
65ec6247 126 extern LexerModule lmErrorList;
b8b0e402
RD
127 extern LexerModule lmHTML;
128 extern LexerModule lmLatex;
129 extern LexerModule lmLISP;
130 extern LexerModule lmLua;
65ec6247 131 extern LexerModule lmMake;
1a2fb4cd 132 extern LexerModule lmMatlab;
b8b0e402 133 extern LexerModule lmPascal;
65ec6247 134 extern LexerModule lmPerl;
b8b0e402 135 extern LexerModule lmProps;
65ec6247 136 extern LexerModule lmPython;
b8b0e402 137 extern LexerModule lmRuby;
65ec6247
RD
138 extern LexerModule lmSQL;
139 extern LexerModule lmVB;
b8b0e402 140 extern LexerModule lmXML;
1a2fb4cd 141 extern LexerModule lmBullant;
65ec6247
RD
142
143 if (
144 &lmAda
145 && &lmAVE
1a2fb4cd 146 && &lmBaan
65ec6247
RD
147 && &lmConf
148 && &lmDiff
149 && &lmLatex
150 && &lmPascal
151 && &lmCPP
152 && &lmHTML
153 && &lmXML
154 && &lmProps
155 && &lmErrorList
156 && &lmMake
1a2fb4cd 157 && &lmMatlab
65ec6247
RD
158 && &lmBatch
159 && &lmPerl
160 && &lmPython
161 && &lmSQL
162 && &lmVB
b8b0e402
RD
163 && &lmRuby
164 && &lmEiffel
165 && &lmEiffelkw
166 && &lmLISP
167 && &lmLua
168 && &lmNull
1a2fb4cd 169 && &lmBullant
65ec6247
RD
170 )
171 {
172 return 1;
173 }
174 else
175 {
176 return 0;
177 }
178}
179#endif