4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo/loom
9
#include "simodo/interpret/builtins/modules/LexicalParametersModule.h"
10
#include "simodo/variable/VariableSetWrapper.h"
11
#include "simodo/inout/convert/functions.h"
17
namespace simodo::interpret::builtins
21
variable::Value clearMarkups(variable::Module_interface * host, const variable::VariableSetWrapper & )
23
// std::cout << "clearMarkups" << std::endl;
25
assert(host != nullptr);
26
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
27
lex().markups.clear();
32
variable::Value addMarkup(variable::Module_interface * host, const variable::VariableSetWrapper & args)
34
// std::cout << "addMarkup" << std::endl;
36
std::u16string start = get<std::u16string>(args[0].origin().variant());
37
std::u16string end = get<std::u16string>(args[1].origin().variant());
38
std::u16string ignore_sign = get<std::u16string>(args[2].origin().variant());
39
int64_t type = get<int64_t>(args[3].origin().variant());
41
assert(host != nullptr);
42
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
43
lex().markups.push_back({start, end, ignore_sign, static_cast<inout::LexemeType>(type)});
48
variable::Value clearMasks(variable::Module_interface * host, const variable::VariableSetWrapper & )
50
// std::cout << "clearMasks" << std::endl;
52
assert(host != nullptr);
53
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
59
variable::Value addMask(variable::Module_interface * host, const variable::VariableSetWrapper & args)
61
// std::cout << "addMask" << std::endl;
63
std::u16string chars = get<std::u16string>(args[0].origin().variant());
64
int64_t type = get<int64_t>(args[1].origin().variant());
65
int64_t system = get<int64_t>(args[2].origin().variant());
67
assert(host != nullptr);
68
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
69
lex().masks.push_back({chars, static_cast<inout::LexemeType>(type), static_cast<inout::number_system_t>(system)});
74
variable::Value setNationalAlphabet(variable::Module_interface * host, const variable::VariableSetWrapper & args)
76
// std::cout << "setNationalAlphabet" << std::endl;
78
std::u16string national_alphabet = get<std::u16string>(args[0].origin().variant());
80
assert(host != nullptr);
81
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
82
lex().national_alphabet = national_alphabet;
87
variable::Value setIdExtraSymbols(variable::Module_interface * host, const variable::VariableSetWrapper & args)
89
// std::cout << "setIdExtraSymbols" << std::endl;
91
std::u16string id_extra_symbols = get<std::u16string>(args[0].origin().variant());
93
assert(host != nullptr);
94
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
95
lex().id_extra_symbols = id_extra_symbols;
100
variable::Value setNationalLettersUse(variable::Module_interface * host, const variable::VariableSetWrapper & args)
102
// std::cout << "setNationalLettersUse" << std::endl;
104
bool may_national_letters_use = get<bool>(args[0].origin().variant());
106
assert(host != nullptr);
107
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
108
lex().may_national_letters_use = may_national_letters_use;
113
variable::Value setNationalLettersMix(variable::Module_interface * host, const variable::VariableSetWrapper & args)
115
// std::cout << "setNationalLettersMix" << std::endl;
117
bool may_national_letters_mix = get<bool>(args[0].origin().variant());
119
assert(host != nullptr);
120
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
121
lex().may_national_letters_mix = may_national_letters_mix;
126
variable::Value setCaseSensitive(variable::Module_interface * host, const variable::VariableSetWrapper & args)
128
// std::cout << "setCaseSensitive" << std::endl;
130
bool is_case_sensitive = get<bool>(args[0].origin().variant());
132
assert(host != nullptr);
133
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
134
lex().is_case_sensitive = is_case_sensitive;
139
variable::Value setNewLineSubstitution(variable::Module_interface * host, const variable::VariableSetWrapper & args)
141
// std::cout << "setNewLineSubstitution" << std::endl;
143
std::u16string nl_substitution = get<std::u16string>(args[0].origin().variant());
145
assert(host != nullptr);
146
LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
147
lex().nl_substitution = nl_substitution;
154
LexicalParametersModule::LexicalParametersModule(inout::LexicalParameters &lex)
157
// std::cout << "LexicalParametersModule" << std::endl;
160
LexicalParametersModule::~LexicalParametersModule()
162
// std::cout << "~LexicalParametersModule" << std::endl;
165
using namespace simodo::variable;
167
variable::Value LexicalParametersModule::instantiate(std::shared_ptr<variable::Module_interface> module_host)
169
// std::cout << "instantiate" << std::endl;
172
{u"clearMarkups", {ValueType::Function, Object {{
173
{u"@", ExternalFunction {{module_host}, clearMarkups}},
174
{{}, ValueType::Null},
176
{u"addMarkup", {ValueType::Function, Object {{
177
{u"@", ExternalFunction {{module_host}, addMarkup}},
178
{{}, ValueType::Null},
179
{u"start", ValueType::String},
180
{u"end", ValueType::String},
181
{u"ignore_sign", ValueType::String},
182
{u"type", ValueType::Int},
184
{u"clearMasks", {ValueType::Function, Object {{
185
{u"@", ExternalFunction {{module_host}, clearMasks}},
186
{{}, ValueType::Null},
188
{u"addMask", {ValueType::Function, Object {{
189
{u"@", ExternalFunction {{module_host}, addMask}},
190
{{}, ValueType::Null},
191
{u"chars", ValueType::String},
192
{u"type", ValueType::Int},
193
{u"system", ValueType::Int},
195
{u"setNationalAlphabet", {ValueType::Function, Object {{
196
{u"@", ExternalFunction {{module_host}, setNationalAlphabet}},
197
{{}, ValueType::Null},
198
{u"national_alphabet", ValueType::String},
200
{u"setIdExtraSymbols", {ValueType::Function, Object {{
201
{u"@", ExternalFunction {{module_host}, setIdExtraSymbols}},
202
{{}, ValueType::Null},
203
{u"id_extra_symbols", ValueType::String},
205
{u"setNationalLettersUse", {ValueType::Function, Object {{
206
{u"@", ExternalFunction {{module_host}, setNationalLettersUse}},
207
{{}, ValueType::Null},
208
{u"may_national_letters_use", ValueType::Bool},
210
{u"setNationalLettersMix", {ValueType::Function, Object {{
211
{u"@", ExternalFunction {{module_host}, setNationalLettersMix}},
212
{{}, ValueType::Null},
213
{u"may_national_letters_mix", ValueType::Bool},
215
{u"setCaseSensitive", {ValueType::Function, Object {{
216
{u"@", ExternalFunction {{module_host}, setCaseSensitive}},
217
{{}, ValueType::Null},
218
{u"is_case_sensitive", ValueType::Bool},
220
{u"setNewLineSubstitution", {ValueType::Function, Object {{
221
{u"@", ExternalFunction {{module_host}, setNewLineSubstitution}},
222
{{}, ValueType::Null},
223
{u"new_line_substitution_string", ValueType::String},
225
{u"LexemeType", Object {{
226
{u"Id", static_cast<int64_t>(inout::LexemeType::Id)},
227
{u"Empty", static_cast<int64_t>(inout::LexemeType::Empty)},
228
{u"Error", static_cast<int64_t>(inout::LexemeType::Error)},
229
{u"Number", static_cast<int64_t>(inout::LexemeType::Number)},
230
{u"Comment", static_cast<int64_t>(inout::LexemeType::Comment)},
231
{u"Compound", static_cast<int64_t>(inout::LexemeType::Compound)},
232
{u"Annotation", static_cast<int64_t>(inout::LexemeType::Annotation)},
233
{u"Punctuation", static_cast<int64_t>(inout::LexemeType::Punctuation)},
234
{u"NewLine", static_cast<int64_t>(inout::LexemeType::NewLine)},