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