-
Notifications
You must be signed in to change notification settings - Fork 3
/
LexerCatalogue.cpp
101 lines (82 loc) · 2.66 KB
/
LexerCatalogue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/** @file LexerCatalogue.cpp
** A simple Lexer catalogue
**/
// Copyright (C) 2022 - Leonardo Silva
// The License.txt file describes the conditions under which this software may be distributed.
#include "pch.h"
//#include <stdexcept>
//#include <algorithm>
//#include <string>
#include "LexerCatalogue.h"
/*
* TASK: Include all your lexer modules here; update InstalledLexers
*/
#include "LexNWScript.h"
using std::size;
using namespace LexerInterface;
constexpr static LexerDefinition InstalledLexers[] = {
{"NWScript", TEXT("NWScript file"), SCLEX_NWSCRIPT, LexerNWScript::LexerFactoryNWScript, ExternalLexerAutoIndentMode::C_Like},
// {"NWScript NoCase", TEXT("NWScript Case Insensitive file"), SCLEX_NWSCRIPTNOCASE, LexerNWScript::LexerFactoryNWScriptInsensitive, ExternalLexerAutoIndentMode::Extended},
};
constexpr const int InstalledLexersCount = (int)std::size(InstalledLexers);
// To create different lexers for Notepad 8.3.4+ versions, add other classes on this function.
ILexer5* LexerCatalogue::CreateLexer(const char* name)
{
std::string _name = name;
if (_name == InstalledLexers[0].lexerName)
return new LexerNWScript(true); // The only supported option for this plugin.
else
return nullptr;
}
/*
* END OF TASK
*/
int LexerCatalogue::GetLexerCount() noexcept {
return InstalledLexersCount;
}
void LexerCatalogue::GetLexerName(unsigned int index, char* name, int buflength)
{
if (index < InstalledLexersCount)
{
strncpy_s(name, buflength, InstalledLexers[index].lexerName, _TRUNCATE);
name[buflength - 1] = L'\0';
}
else
throw std::out_of_range("index out of bounds");
}
std::string LexerCatalogue::GetLexerName(unsigned int index, bool toLower)
{
if (index < InstalledLexersCount)
{
std::string retVal = InstalledLexers[index].lexerName;
if (toLower)
std::transform(retVal.begin(), retVal.end(), retVal.begin(), ::tolower);
return retVal;
}
else
throw std::out_of_range("index out of bounds");
}
void LexerCatalogue::GetLexerStatusText(unsigned int index, WCHAR* desc, int buflength)
{
if (index < InstalledLexersCount)
{
wcsncpy_s(desc, buflength, InstalledLexers[index].lexerStatusText, _TRUNCATE);
desc[buflength - 1] = L'\0';
}
else
throw std::out_of_range("index out of bounds");
}
MyLexerFactoryFunction LexerCatalogue::GetLexerFactory(unsigned int index)
{
if (index < InstalledLexersCount)
return InstalledLexers[index].ptrFactoryFunction;
else
throw std::out_of_range("index out of bounds");
}
ExternalLexerAutoIndentMode LexerCatalogue::GetLexerIndentType(unsigned int index)
{
if (index < InstalledLexersCount)
return InstalledLexers[index].langAutoIndent;
else
throw std::out_of_range("index out of bounds");
}