1 // Scintilla source code edit control
2 /** @file Lexilla.cxx
3  ** Lexer infrastructure.
4  ** Provides entry points to shared library.
5  **/
6 // Copyright 2019 by Neil Hodgson <neilh@scintilla.org>
7 // The License.txt file describes the conditions under which this software may be distributed.
8 
9 #include <cstring>
10 
11 #include <vector>
12 
13 #if _WIN32
14 #define EXPORT_FUNCTION __declspec(dllexport)
15 #define CALLING_CONVENTION __stdcall
16 #else
17 #define EXPORT_FUNCTION __attribute__((visibility("default")))
18 #define CALLING_CONVENTION
19 #endif
20 
21 #include "ILexer.h"
22 
23 #include "LexerModule.h"
24 #include "CatalogueModules.h"
25 
26 using namespace Scintilla;
27 
28 //++Autogenerated -- run lexilla/scripts/LexillaGen.py to regenerate
29 //**\(extern LexerModule \*;\n\)
30 extern LexerModule lmA68k;
31 extern LexerModule lmAbaqus;
32 extern LexerModule lmAda;
33 extern LexerModule lmAPDL;
34 extern LexerModule lmAs;
35 extern LexerModule lmAsm;
36 extern LexerModule lmAsn1;
37 extern LexerModule lmASY;
38 extern LexerModule lmAU3;
39 extern LexerModule lmAVE;
40 extern LexerModule lmAVS;
41 extern LexerModule lmBaan;
42 extern LexerModule lmBash;
43 extern LexerModule lmBatch;
44 extern LexerModule lmBibTeX;
45 extern LexerModule lmBlitzBasic;
46 extern LexerModule lmBullant;
47 extern LexerModule lmCaml;
48 extern LexerModule lmCIL;
49 extern LexerModule lmClw;
50 extern LexerModule lmClwNoCase;
51 extern LexerModule lmCmake;
52 extern LexerModule lmCOBOL;
53 extern LexerModule lmCoffeeScript;
54 extern LexerModule lmConf;
55 extern LexerModule lmCPP;
56 extern LexerModule lmCPPNoCase;
57 extern LexerModule lmCsound;
58 extern LexerModule lmCss;
59 extern LexerModule lmD;
60 extern LexerModule lmDataflex;
61 extern LexerModule lmDiff;
62 extern LexerModule lmDMAP;
63 extern LexerModule lmDMIS;
64 extern LexerModule lmECL;
65 extern LexerModule lmEDIFACT;
66 extern LexerModule lmEiffel;
67 extern LexerModule lmEiffelkw;
68 extern LexerModule lmErlang;
69 extern LexerModule lmErrorList;
70 extern LexerModule lmESCRIPT;
71 extern LexerModule lmF77;
72 extern LexerModule lmFlagShip;
73 extern LexerModule lmForth;
74 extern LexerModule lmFortran;
75 extern LexerModule lmFreeBasic;
76 extern LexerModule lmGAP;
77 extern LexerModule lmGui4Cli;
78 extern LexerModule lmHaskell;
79 extern LexerModule lmHollywood;
80 extern LexerModule lmHTML;
81 extern LexerModule lmIHex;
82 extern LexerModule lmIndent;
83 extern LexerModule lmInno;
84 extern LexerModule lmJSON;
85 extern LexerModule lmKix;
86 extern LexerModule lmKVIrc;
87 extern LexerModule lmLatex;
88 extern LexerModule lmLISP;
89 extern LexerModule lmLiterateHaskell;
90 extern LexerModule lmLot;
91 extern LexerModule lmLout;
92 extern LexerModule lmLua;
93 extern LexerModule lmMagikSF;
94 extern LexerModule lmMake;
95 extern LexerModule lmMarkdown;
96 extern LexerModule lmMatlab;
97 extern LexerModule lmMaxima;
98 extern LexerModule lmMETAPOST;
99 extern LexerModule lmMMIXAL;
100 extern LexerModule lmModula;
101 extern LexerModule lmMSSQL;
102 extern LexerModule lmMySQL;
103 extern LexerModule lmNim;
104 extern LexerModule lmNimrod;
105 extern LexerModule lmNncrontab;
106 extern LexerModule lmNsis;
107 extern LexerModule lmNull;
108 extern LexerModule lmOctave;
109 extern LexerModule lmOpal;
110 extern LexerModule lmOScript;
111 extern LexerModule lmPascal;
112 extern LexerModule lmPB;
113 extern LexerModule lmPerl;
114 extern LexerModule lmPHPSCRIPT;
115 extern LexerModule lmPLM;
116 extern LexerModule lmPO;
117 extern LexerModule lmPOV;
118 extern LexerModule lmPowerPro;
119 extern LexerModule lmPowerShell;
120 extern LexerModule lmProgress;
121 extern LexerModule lmProps;
122 extern LexerModule lmPS;
123 extern LexerModule lmPureBasic;
124 extern LexerModule lmPython;
125 extern LexerModule lmR;
126 extern LexerModule lmRaku;
127 extern LexerModule lmREBOL;
128 extern LexerModule lmRegistry;
129 extern LexerModule lmRuby;
130 extern LexerModule lmRust;
131 extern LexerModule lmSAS;
132 extern LexerModule lmScriptol;
133 extern LexerModule lmSmalltalk;
134 extern LexerModule lmSML;
135 extern LexerModule lmSorc;
136 extern LexerModule lmSpecman;
137 extern LexerModule lmSpice;
138 extern LexerModule lmSQL;
139 extern LexerModule lmSrec;
140 extern LexerModule lmStata;
141 extern LexerModule lmSTTXT;
142 extern LexerModule lmTACL;
143 extern LexerModule lmTADS3;
144 extern LexerModule lmTAL;
145 extern LexerModule lmTCL;
146 extern LexerModule lmTCMD;
147 extern LexerModule lmTEHex;
148 extern LexerModule lmTeX;
149 extern LexerModule lmTxt2tags;
150 extern LexerModule lmVB;
151 extern LexerModule lmVBScript;
152 extern LexerModule lmVerilog;
153 extern LexerModule lmVHDL;
154 extern LexerModule lmVisualProlog;
155 extern LexerModule lmX12;
156 extern LexerModule lmXML;
157 extern LexerModule lmYAML;
158 
159 //--Autogenerated -- end of automatically generated section
160 
161 namespace {
162 
163 CatalogueModules catalogueLexilla;
164 
AddEachLexer()165 void AddEachLexer() {
166 
167 	if (catalogueLexilla.Count() > 0) {
168 		return;
169 	}
170 
171 //++Autogenerated -- run scripts/LexGen.py to regenerate
172 //**\(\tcatalogueLexilla.AddLexerModule(&\*);\n\)
173 	catalogueLexilla.AddLexerModule(&lmA68k);
174 	catalogueLexilla.AddLexerModule(&lmAbaqus);
175 	catalogueLexilla.AddLexerModule(&lmAda);
176 	catalogueLexilla.AddLexerModule(&lmAPDL);
177 	catalogueLexilla.AddLexerModule(&lmAs);
178 	catalogueLexilla.AddLexerModule(&lmAsm);
179 	catalogueLexilla.AddLexerModule(&lmAsn1);
180 	catalogueLexilla.AddLexerModule(&lmASY);
181 	catalogueLexilla.AddLexerModule(&lmAU3);
182 	catalogueLexilla.AddLexerModule(&lmAVE);
183 	catalogueLexilla.AddLexerModule(&lmAVS);
184 	catalogueLexilla.AddLexerModule(&lmBaan);
185 	catalogueLexilla.AddLexerModule(&lmBash);
186 	catalogueLexilla.AddLexerModule(&lmBatch);
187 	catalogueLexilla.AddLexerModule(&lmBibTeX);
188 	catalogueLexilla.AddLexerModule(&lmBlitzBasic);
189 	catalogueLexilla.AddLexerModule(&lmBullant);
190 	catalogueLexilla.AddLexerModule(&lmCaml);
191 	catalogueLexilla.AddLexerModule(&lmCIL);
192 	catalogueLexilla.AddLexerModule(&lmClw);
193 	catalogueLexilla.AddLexerModule(&lmClwNoCase);
194 	catalogueLexilla.AddLexerModule(&lmCmake);
195 	catalogueLexilla.AddLexerModule(&lmCOBOL);
196 	catalogueLexilla.AddLexerModule(&lmCoffeeScript);
197 	catalogueLexilla.AddLexerModule(&lmConf);
198 	catalogueLexilla.AddLexerModule(&lmCPP);
199 	catalogueLexilla.AddLexerModule(&lmCPPNoCase);
200 	catalogueLexilla.AddLexerModule(&lmCsound);
201 	catalogueLexilla.AddLexerModule(&lmCss);
202 	catalogueLexilla.AddLexerModule(&lmD);
203 	catalogueLexilla.AddLexerModule(&lmDataflex);
204 	catalogueLexilla.AddLexerModule(&lmDiff);
205 	catalogueLexilla.AddLexerModule(&lmDMAP);
206 	catalogueLexilla.AddLexerModule(&lmDMIS);
207 	catalogueLexilla.AddLexerModule(&lmECL);
208 	catalogueLexilla.AddLexerModule(&lmEDIFACT);
209 	catalogueLexilla.AddLexerModule(&lmEiffel);
210 	catalogueLexilla.AddLexerModule(&lmEiffelkw);
211 	catalogueLexilla.AddLexerModule(&lmErlang);
212 	catalogueLexilla.AddLexerModule(&lmErrorList);
213 	catalogueLexilla.AddLexerModule(&lmESCRIPT);
214 	catalogueLexilla.AddLexerModule(&lmF77);
215 	catalogueLexilla.AddLexerModule(&lmFlagShip);
216 	catalogueLexilla.AddLexerModule(&lmForth);
217 	catalogueLexilla.AddLexerModule(&lmFortran);
218 	catalogueLexilla.AddLexerModule(&lmFreeBasic);
219 	catalogueLexilla.AddLexerModule(&lmGAP);
220 	catalogueLexilla.AddLexerModule(&lmGui4Cli);
221 	catalogueLexilla.AddLexerModule(&lmHaskell);
222 	catalogueLexilla.AddLexerModule(&lmHollywood);
223 	catalogueLexilla.AddLexerModule(&lmHTML);
224 	catalogueLexilla.AddLexerModule(&lmIHex);
225 	catalogueLexilla.AddLexerModule(&lmIndent);
226 	catalogueLexilla.AddLexerModule(&lmInno);
227 	catalogueLexilla.AddLexerModule(&lmJSON);
228 	catalogueLexilla.AddLexerModule(&lmKix);
229 	catalogueLexilla.AddLexerModule(&lmKVIrc);
230 	catalogueLexilla.AddLexerModule(&lmLatex);
231 	catalogueLexilla.AddLexerModule(&lmLISP);
232 	catalogueLexilla.AddLexerModule(&lmLiterateHaskell);
233 	catalogueLexilla.AddLexerModule(&lmLot);
234 	catalogueLexilla.AddLexerModule(&lmLout);
235 	catalogueLexilla.AddLexerModule(&lmLua);
236 	catalogueLexilla.AddLexerModule(&lmMagikSF);
237 	catalogueLexilla.AddLexerModule(&lmMake);
238 	catalogueLexilla.AddLexerModule(&lmMarkdown);
239 	catalogueLexilla.AddLexerModule(&lmMatlab);
240 	catalogueLexilla.AddLexerModule(&lmMaxima);
241 	catalogueLexilla.AddLexerModule(&lmMETAPOST);
242 	catalogueLexilla.AddLexerModule(&lmMMIXAL);
243 	catalogueLexilla.AddLexerModule(&lmModula);
244 	catalogueLexilla.AddLexerModule(&lmMSSQL);
245 	catalogueLexilla.AddLexerModule(&lmMySQL);
246 	catalogueLexilla.AddLexerModule(&lmNim);
247 	catalogueLexilla.AddLexerModule(&lmNimrod);
248 	catalogueLexilla.AddLexerModule(&lmNncrontab);
249 	catalogueLexilla.AddLexerModule(&lmNsis);
250 	catalogueLexilla.AddLexerModule(&lmNull);
251 	catalogueLexilla.AddLexerModule(&lmOctave);
252 	catalogueLexilla.AddLexerModule(&lmOpal);
253 	catalogueLexilla.AddLexerModule(&lmOScript);
254 	catalogueLexilla.AddLexerModule(&lmPascal);
255 	catalogueLexilla.AddLexerModule(&lmPB);
256 	catalogueLexilla.AddLexerModule(&lmPerl);
257 	catalogueLexilla.AddLexerModule(&lmPHPSCRIPT);
258 	catalogueLexilla.AddLexerModule(&lmPLM);
259 	catalogueLexilla.AddLexerModule(&lmPO);
260 	catalogueLexilla.AddLexerModule(&lmPOV);
261 	catalogueLexilla.AddLexerModule(&lmPowerPro);
262 	catalogueLexilla.AddLexerModule(&lmPowerShell);
263 	catalogueLexilla.AddLexerModule(&lmProgress);
264 	catalogueLexilla.AddLexerModule(&lmProps);
265 	catalogueLexilla.AddLexerModule(&lmPS);
266 	catalogueLexilla.AddLexerModule(&lmPureBasic);
267 	catalogueLexilla.AddLexerModule(&lmPython);
268 	catalogueLexilla.AddLexerModule(&lmR);
269 	catalogueLexilla.AddLexerModule(&lmRaku);
270 	catalogueLexilla.AddLexerModule(&lmREBOL);
271 	catalogueLexilla.AddLexerModule(&lmRegistry);
272 	catalogueLexilla.AddLexerModule(&lmRuby);
273 	catalogueLexilla.AddLexerModule(&lmRust);
274 	catalogueLexilla.AddLexerModule(&lmSAS);
275 	catalogueLexilla.AddLexerModule(&lmScriptol);
276 	catalogueLexilla.AddLexerModule(&lmSmalltalk);
277 	catalogueLexilla.AddLexerModule(&lmSML);
278 	catalogueLexilla.AddLexerModule(&lmSorc);
279 	catalogueLexilla.AddLexerModule(&lmSpecman);
280 	catalogueLexilla.AddLexerModule(&lmSpice);
281 	catalogueLexilla.AddLexerModule(&lmSQL);
282 	catalogueLexilla.AddLexerModule(&lmSrec);
283 	catalogueLexilla.AddLexerModule(&lmStata);
284 	catalogueLexilla.AddLexerModule(&lmSTTXT);
285 	catalogueLexilla.AddLexerModule(&lmTACL);
286 	catalogueLexilla.AddLexerModule(&lmTADS3);
287 	catalogueLexilla.AddLexerModule(&lmTAL);
288 	catalogueLexilla.AddLexerModule(&lmTCL);
289 	catalogueLexilla.AddLexerModule(&lmTCMD);
290 	catalogueLexilla.AddLexerModule(&lmTEHex);
291 	catalogueLexilla.AddLexerModule(&lmTeX);
292 	catalogueLexilla.AddLexerModule(&lmTxt2tags);
293 	catalogueLexilla.AddLexerModule(&lmVB);
294 	catalogueLexilla.AddLexerModule(&lmVBScript);
295 	catalogueLexilla.AddLexerModule(&lmVerilog);
296 	catalogueLexilla.AddLexerModule(&lmVHDL);
297 	catalogueLexilla.AddLexerModule(&lmVisualProlog);
298 	catalogueLexilla.AddLexerModule(&lmX12);
299 	catalogueLexilla.AddLexerModule(&lmXML);
300 	catalogueLexilla.AddLexerModule(&lmYAML);
301 
302 //--Autogenerated -- end of automatically generated section
303 
304 }
305 
306 }
307 
308 extern "C" {
309 
GetLexerCount()310 EXPORT_FUNCTION int CALLING_CONVENTION GetLexerCount() {
311 	AddEachLexer();
312 	return catalogueLexilla.Count();
313 }
314 
GetLexerName(unsigned int index,char * name,int buflength)315 EXPORT_FUNCTION void CALLING_CONVENTION GetLexerName(unsigned int index, char *name, int buflength) {
316 	AddEachLexer();
317 	*name = 0;
318 	const char *lexerName = catalogueLexilla.Name(index);
319 	if (static_cast<size_t>(buflength) > strlen(lexerName)) {
320 		strcpy(name, lexerName);
321 	}
322 }
323 
GetLexerFactory(unsigned int index)324 EXPORT_FUNCTION LexerFactoryFunction CALLING_CONVENTION GetLexerFactory(unsigned int index) {
325 	AddEachLexer();
326 	return catalogueLexilla.Factory(index);
327 }
328 
CreateLexer(const char * name)329 EXPORT_FUNCTION ILexer5 * CALLING_CONVENTION CreateLexer(const char *name) {
330 	AddEachLexer();
331 	for (unsigned int i = 0; i < catalogueLexilla.Count(); i++) {
332 		const char *lexerName = catalogueLexilla.Name(i);
333 		if (0 == strcmp(lexerName, name)) {
334 			return catalogueLexilla.Create(i);
335 		}
336 	}
337 	return nullptr;
338 }
339 
340 }
341