]>
Commit | Line | Data |
---|---|---|
65ec6247 RD |
1 | // Scintilla source code edit control |
2 | /** @file KeyWords.cxx | |
3 | ** Colourise for particular languages. | |
4 | **/ | |
5 | // Copyright 1998-2001 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 | ||
f6bcfd97 | 22 | LexerModule *LexerModule::base = 0; |
65ec6247 | 23 | int LexerModule::nextLanguage = SCLEX_AUTOMATIC+1; |
f6bcfd97 | 24 | |
65ec6247 RD |
25 | LexerModule::LexerModule(int language_, LexerFunction fnLexer_, |
26 | const char *languageName_, LexerFunction fnFolder_) : | |
27 | language(language_), | |
28 | languageName(languageName_), | |
29 | fnLexer(fnLexer_), | |
30 | fnFolder(fnFolder_) { | |
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 | ||
65ec6247 | 39 | LexerModule *LexerModule::Find(int language) { |
f6bcfd97 BP |
40 | LexerModule *lm = base; |
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 | ||
50 | LexerModule *LexerModule::Find(const char *languageName) { | |
51 | if (languageName) { | |
52 | LexerModule *lm = base; | |
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 | ||
63 | void LexerModule::Lex(unsigned int startPos, int lengthDoc, int initStyle, | |
64 | WordList *keywordlists[], Accessor &styler) { | |
65 | if (fnLexer) | |
66 | fnLexer(startPos, lengthDoc, initStyle, keywordlists, styler); | |
67 | } | |
68 | ||
69 | void LexerModule::Fold(unsigned int startPos, int lengthDoc, int initStyle, | |
70 | WordList *keywordlists[], Accessor &styler) { | |
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 | ||
88 | static 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 | |
98 | LexerModule lmNull(SCLEX_NULL, ColouriseNullDoc, "null"); | |
99 | ||
100 | #ifdef __vms | |
101 | ||
102 | // The following code forces a reference to all of the Scintilla lexers. | |
103 | // If we don't do something like this, then the linker tends to "optimize" | |
104 | // them away. (eric@sourcegear.com) | |
105 | ||
106 | // Taken from wxWindow's stc.cpp. Walter. | |
107 | ||
108 | int wxForceScintillaLexers(void) { | |
109 | extern LexerModule lmAda; | |
110 | extern LexerModule lmAVE; | |
b8b0e402 | 111 | extern LexerModule lmBatch; |
65ec6247 | 112 | extern LexerModule lmConf; |
65ec6247 | 113 | extern LexerModule lmCPP; |
b8b0e402 RD |
114 | extern LexerModule lmDiff; |
115 | extern LexerModule lmEiffel; | |
116 | extern LexerModule lmEiffelkw; | |
65ec6247 | 117 | extern LexerModule lmErrorList; |
b8b0e402 RD |
118 | extern LexerModule lmHTML; |
119 | extern LexerModule lmLatex; | |
120 | extern LexerModule lmLISP; | |
121 | extern LexerModule lmLua; | |
65ec6247 | 122 | extern LexerModule lmMake; |
b8b0e402 | 123 | extern LexerModule lmPascal; |
65ec6247 | 124 | extern LexerModule lmPerl; |
b8b0e402 | 125 | extern LexerModule lmProps; |
65ec6247 | 126 | extern LexerModule lmPython; |
b8b0e402 | 127 | extern LexerModule lmRuby; |
65ec6247 RD |
128 | extern LexerModule lmSQL; |
129 | extern LexerModule lmVB; | |
b8b0e402 | 130 | extern LexerModule lmXML; |
65ec6247 RD |
131 | |
132 | if ( | |
133 | &lmAda | |
134 | && &lmAVE | |
135 | && &lmConf | |
136 | && &lmDiff | |
137 | && &lmLatex | |
138 | && &lmPascal | |
139 | && &lmCPP | |
140 | && &lmHTML | |
141 | && &lmXML | |
142 | && &lmProps | |
143 | && &lmErrorList | |
144 | && &lmMake | |
145 | && &lmBatch | |
146 | && &lmPerl | |
147 | && &lmPython | |
148 | && &lmSQL | |
149 | && &lmVB | |
b8b0e402 RD |
150 | && &lmRuby |
151 | && &lmEiffel | |
152 | && &lmEiffelkw | |
153 | && &lmLISP | |
154 | && &lmLua | |
155 | && &lmNull | |
65ec6247 RD |
156 | ) |
157 | { | |
158 | return 1; | |
159 | } | |
160 | else | |
161 | { | |
162 | return 0; | |
163 | } | |
164 | } | |
165 | #endif |