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
27using namespace Lexilla;
28
29//++Autogenerated -- run lexilla/scripts/LexillaGen.py to regenerate
30//**\(extern LexerModule \*;\n\)
31extern LexerModule lmA68k;
32extern LexerModule lmAbaqus;
33extern LexerModule lmAda;
34extern LexerModule lmAPDL;
35extern LexerModule lmAs;
36extern LexerModule lmAsciidoc;
37extern LexerModule lmAsm;
38extern LexerModule lmAsn1;
39extern LexerModule lmASY;
40extern LexerModule lmAU3;
41extern LexerModule lmAVE;
42extern LexerModule lmAVS;
43extern LexerModule lmBaan;
44extern LexerModule lmBash;
45extern LexerModule lmBatch;
46extern LexerModule lmBibTeX;
47extern LexerModule lmBlitzBasic;
48extern LexerModule lmBullant;
49extern LexerModule lmCaml;
50extern LexerModule lmCIL;
51extern LexerModule lmClw;
52extern LexerModule lmClwNoCase;
53extern LexerModule lmCmake;
54extern LexerModule lmCOBOL;
55extern LexerModule lmCoffeeScript;
56extern LexerModule lmConf;
57extern LexerModule lmCPP;
58extern LexerModule lmCPPNoCase;
59extern LexerModule lmCsound;
60extern LexerModule lmCss;
61extern LexerModule lmD;
62extern LexerModule lmDataflex;
63extern LexerModule lmDiff;
64extern LexerModule lmDMAP;
65extern LexerModule lmDMIS;
66extern LexerModule lmECL;
67extern LexerModule lmEDIFACT;
68extern LexerModule lmEiffel;
69extern LexerModule lmEiffelkw;
70extern LexerModule lmErlang;
71extern LexerModule lmErrorList;
72extern LexerModule lmESCRIPT;
73extern LexerModule lmF77;
74extern LexerModule lmFlagShip;
75extern LexerModule lmForth;
76extern LexerModule lmFortran;
77extern LexerModule lmFreeBasic;
78extern LexerModule lmFSharp;
79extern LexerModule lmGAP;
80extern LexerModule lmGDScript;
81extern LexerModule lmGui4Cli;
82extern LexerModule lmHaskell;
83extern LexerModule lmHollywood;
84extern LexerModule lmHTML;
85extern LexerModule lmJS;
86extern LexerModule lmIHex;
87extern LexerModule lmIndent;
88extern LexerModule lmInno;
89extern LexerModule lmJSON;
90extern LexerModule lmJulia;
91extern LexerModule lmKix;
92extern LexerModule lmKVIrc;
93extern LexerModule lmLatex;
94extern LexerModule lmLISP;
95extern LexerModule lmLiterateHaskell;
96extern LexerModule lmLot;
97extern LexerModule lmLout;
98extern LexerModule lmLua;
99extern LexerModule lmMagikSF;
100extern LexerModule lmMake;
101extern LexerModule lmMarkdown;
102extern LexerModule lmMatlab;
103extern LexerModule lmMaxima;
104extern LexerModule lmMETAPOST;
105extern LexerModule lmMMIXAL;
106extern LexerModule lmModula;
107extern LexerModule lmMSSQL;
108extern LexerModule lmMySQL;
109extern LexerModule lmNim;
110extern LexerModule lmNimrod;
111extern LexerModule lmNncrontab;
112extern LexerModule lmNsis;
113extern LexerModule lmNull;
114extern LexerModule lmOctave;
115extern LexerModule lmOpal;
116extern LexerModule lmOScript;
117extern LexerModule lmPascal;
118extern LexerModule lmPB;
119extern LexerModule lmPerl;
120extern LexerModule lmPHPSCRIPT;
121extern LexerModule lmPLM;
122extern LexerModule lmPO;
123extern LexerModule lmPOV;
124extern LexerModule lmPowerPro;
125extern LexerModule lmPowerShell;
126extern LexerModule lmProgress;
127extern LexerModule lmProps;
128extern LexerModule lmPS;
129extern LexerModule lmPureBasic;
130extern LexerModule lmPython;
131extern LexerModule lmR;
132extern LexerModule lmRaku;
133extern LexerModule lmREBOL;
134extern LexerModule lmRegistry;
135extern LexerModule lmRuby;
136extern LexerModule lmRust;
137extern LexerModule lmSAS;
138extern LexerModule lmScriptol;
139extern LexerModule lmSmalltalk;
140extern LexerModule lmSML;
141extern LexerModule lmSorc;
142extern LexerModule lmSpecman;
143extern LexerModule lmSpice;
144extern LexerModule lmSQL;
145extern LexerModule lmSrec;
146extern LexerModule lmStata;
147extern LexerModule lmSTTXT;
148extern LexerModule lmTACL;
149extern LexerModule lmTADS3;
150extern LexerModule lmTAL;
151extern LexerModule lmTCL;
152extern LexerModule lmTCMD;
153extern LexerModule lmTEHex;
154extern LexerModule lmTeX;
155extern LexerModule lmTxt2tags;
156extern LexerModule lmVB;
157extern LexerModule lmVBScript;
158extern LexerModule lmVerilog;
159extern LexerModule lmVHDL;
160extern LexerModule lmVisualProlog;
161extern LexerModule lmX12;
162extern LexerModule lmXML;
163extern LexerModule lmYAML;
164extern LexerModule lmJAVA;
165extern LexerModule lmJAVANoCase;
166//--Autogenerated -- end of automatically generated section
167
168namespace {
169
170CatalogueModules catalogueLexilla;
171
172void 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
324extern "C" {
325
326EXPORT_FUNCTION int CALLING_CONVENTION GetLexerCount() {
327 AddEachLexer();
328 return catalogueLexilla.Count();
329}
330
331EXPORT_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
340EXPORT_FUNCTION LexerFactoryFunction CALLING_CONVENTION GetLexerFactory(unsigned int index) {
341 AddEachLexer();
342 return catalogueLexilla.Factory(index);
343}
344
345EXPORT_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
356EXPORT_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
366EXPORT_FUNCTION const char * CALLING_CONVENTION GetLibraryPropertyNames() {
367 return "";
368}
369
370EXPORT_FUNCTION void CALLING_CONVENTION SetLibraryProperty(const char *, const char *) {
371 // Null implementation
372}
373
374EXPORT_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
380void AddStaticLexerModule(LexerModule *plm) {
381 AddEachLexer();
382 catalogueLexilla.AddLexerModule(plm);
383}
384
385}
386