loom

Форк
0
/
LexicalParametersModule.cpp 
238 строк · 9.5 Кб
1
/*
2
MIT License
3

4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
5

6
https://bmstu.codes/lsx/simodo/loom
7
*/
8

9
#include "simodo/interpret/builtins/modules/LexicalParametersModule.h"
10
#include "simodo/variable/VariableSetWrapper.h"
11
#include "simodo/inout/convert/functions.h"
12

13
#include <cassert>
14

15
// #include <iostream>
16

17
namespace simodo::interpret::builtins
18
{
19
    namespace
20
    {
21
        variable::Value clearMarkups(variable::Module_interface * host, const variable::VariableSetWrapper & )
22
        {
23
            // std::cout << "clearMarkups" << std::endl;
24

25
            assert(host != nullptr);
26
            LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
27
            lex().markups.clear();
28

29
            return u"";
30
        }
31

32
        variable::Value addMarkup(variable::Module_interface * host, const variable::VariableSetWrapper & args)
33
        {
34
            // std::cout << "addMarkup" << std::endl;
35

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());
40

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)});
44

45
            return u"";
46
        }
47

48
        variable::Value clearMasks(variable::Module_interface * host, const variable::VariableSetWrapper & )
49
        {
50
            // std::cout << "clearMasks" << std::endl;
51

52
            assert(host != nullptr);
53
            LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
54
            lex().masks.clear();
55

56
            return u"";
57
        }
58

59
        variable::Value addMask(variable::Module_interface * host, const variable::VariableSetWrapper & args)
60
        {
61
            // std::cout << "addMask" << std::endl;
62

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());
66

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)});
70

71
            return u"";
72
        }
73

74
        variable::Value setNationalAlphabet(variable::Module_interface * host, const variable::VariableSetWrapper & args)
75
        {
76
            // std::cout << "setNationalAlphabet" << std::endl;
77

78
            std::u16string national_alphabet = get<std::u16string>(args[0].origin().variant());
79

80
            assert(host != nullptr);
81
            LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
82
            lex().national_alphabet = national_alphabet;
83

84
            return u"";
85
        }
86

87
        variable::Value setIdExtraSymbols(variable::Module_interface * host, const variable::VariableSetWrapper & args)
88
        {
89
            // std::cout << "setIdExtraSymbols" << std::endl;
90

91
            std::u16string id_extra_symbols = get<std::u16string>(args[0].origin().variant());
92

93
            assert(host != nullptr);
94
            LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
95
            lex().id_extra_symbols = id_extra_symbols;
96

97
            return u"";
98
        }
99

100
        variable::Value setNationalLettersUse(variable::Module_interface * host, const variable::VariableSetWrapper & args)
101
        {
102
            // std::cout << "setNationalLettersUse" << std::endl;
103

104
            bool may_national_letters_use = get<bool>(args[0].origin().variant());
105

106
            assert(host != nullptr);
107
            LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
108
            lex().may_national_letters_use = may_national_letters_use;
109

110
            return u"";
111
        }
112

113
        variable::Value setNationalLettersMix(variable::Module_interface * host, const variable::VariableSetWrapper & args)
114
        {
115
            // std::cout << "setNationalLettersMix" << std::endl;
116

117
            bool may_national_letters_mix = get<bool>(args[0].origin().variant());
118

119
            assert(host != nullptr);
120
            LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
121
            lex().may_national_letters_mix = may_national_letters_mix;
122

123
            return u"";
124
        }
125

126
        variable::Value setCaseSensitive(variable::Module_interface * host, const variable::VariableSetWrapper & args)
127
        {
128
            // std::cout << "setCaseSensitive" << std::endl;
129

130
            bool is_case_sensitive = get<bool>(args[0].origin().variant());
131

132
            assert(host != nullptr);
133
            LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
134
            lex().is_case_sensitive = is_case_sensitive;
135

136
            return u"";
137
        }
138

139
        variable::Value setNewLineSubstitution(variable::Module_interface * host, const variable::VariableSetWrapper & args)
140
        {
141
            // std::cout << "setNewLineSubstitution" << std::endl;
142

143
            std::u16string nl_substitution = get<std::u16string>(args[0].origin().variant());
144

145
            assert(host != nullptr);
146
            LexicalParametersModule & lex = *(static_cast<LexicalParametersModule *>(host));
147
            lex().nl_substitution = nl_substitution;
148

149
            return u"";
150
        }
151

152
    }
153

154
    LexicalParametersModule::LexicalParametersModule(inout::LexicalParameters &lex)
155
        : _lex(lex)
156
    {
157
        // std::cout << "LexicalParametersModule" << std::endl;
158
    }
159

160
    LexicalParametersModule::~LexicalParametersModule()
161
    {
162
        // std::cout << "~LexicalParametersModule" << std::endl;
163
    }
164

165
    using namespace simodo::variable;
166

167
    variable::Value LexicalParametersModule::instantiate(std::shared_ptr<variable::Module_interface> module_host)
168
    {
169
        // std::cout << "instantiate" << std::endl;
170

171
        return {{
172
            {u"clearMarkups", {ValueType::Function, Object {{
173
                {u"@", ExternalFunction {{module_host}, clearMarkups}},
174
                {{}, ValueType::Null},
175
            }}}},
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},
183
            }}}},
184
            {u"clearMasks", {ValueType::Function, Object {{
185
                {u"@", ExternalFunction {{module_host}, clearMasks}},
186
                {{}, ValueType::Null},
187
            }}}},
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},
194
            }}}},
195
            {u"setNationalAlphabet", {ValueType::Function, Object {{
196
                {u"@", ExternalFunction {{module_host}, setNationalAlphabet}},
197
                {{}, ValueType::Null},
198
                {u"national_alphabet", ValueType::String},
199
            }}}},
200
            {u"setIdExtraSymbols", {ValueType::Function, Object {{
201
                {u"@", ExternalFunction {{module_host}, setIdExtraSymbols}},
202
                {{}, ValueType::Null},
203
                {u"id_extra_symbols", ValueType::String},
204
            }}}},
205
            {u"setNationalLettersUse", {ValueType::Function, Object {{
206
                {u"@", ExternalFunction {{module_host}, setNationalLettersUse}},
207
                {{}, ValueType::Null},
208
                {u"may_national_letters_use", ValueType::Bool},
209
            }}}},
210
            {u"setNationalLettersMix", {ValueType::Function, Object {{
211
                {u"@", ExternalFunction {{module_host}, setNationalLettersMix}},
212
                {{}, ValueType::Null},
213
                {u"may_national_letters_mix", ValueType::Bool},
214
            }}}},
215
            {u"setCaseSensitive", {ValueType::Function, Object {{
216
                {u"@", ExternalFunction {{module_host}, setCaseSensitive}},
217
                {{}, ValueType::Null},
218
                {u"is_case_sensitive", ValueType::Bool},
219
            }}}},
220
            {u"setNewLineSubstitution", {ValueType::Function, Object {{
221
                {u"@", ExternalFunction {{module_host}, setNewLineSubstitution}},
222
                {{}, ValueType::Null},
223
                {u"new_line_substitution_string", ValueType::String},
224
            }}}},
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)},
235
            }}},
236
        }};
237
    }
238
}
239

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.