|
28 | 28 | #include <cctype> |
29 | 29 |
|
30 | 30 |
|
31 | | -static std::string trim(std::string_view str); |
32 | | - |
33 | | -static std::string trim(std::string_view str) |
| 31 | +std::string FrontendLexer::trim(std::string_view str) |
34 | 32 | { |
35 | 33 | auto finish = str.end(); |
36 | 34 | auto start = str.begin(); |
@@ -142,7 +140,7 @@ std::variant<FrontendLexer::SingleStatement, FrontendLexer::IncompleteTokenError |
142 | 140 |
|
143 | 141 | while (pos < end) |
144 | 142 | { |
145 | | - if (end - pos >= term.length() && std::equal(term.begin(), term.end(), pos)) |
| 143 | + if (std::size_t(end - pos) >= term.length() && std::equal(term.begin(), term.end(), pos)) |
146 | 144 | { |
147 | 145 | const auto initialStatement = std::string(buffer.cbegin(), pos); |
148 | 146 | pos += term.length(); |
@@ -224,13 +222,58 @@ FrontendLexer::Token FrontendLexer::getToken() |
224 | 222 | return token; |
225 | 223 | } |
226 | 224 |
|
227 | | -std::optional<FrontendLexer::Token> FrontendLexer::getStringToken() |
| 225 | +FrontendLexer::Token FrontendLexer::getNameToken() |
228 | 226 | { |
| 227 | + skipSpacesAndComments(); |
| 228 | + |
229 | 229 | Token token; |
230 | 230 |
|
| 231 | + if (pos >= end) |
| 232 | + { |
| 233 | + token.type = Token::TYPE_EOF; |
| 234 | + return token; |
| 235 | + } |
| 236 | + |
| 237 | + if (const auto optStringToken = getStringToken(); optStringToken.has_value()) |
| 238 | + return optStringToken.value(); |
| 239 | + |
| 240 | + const auto start = pos; |
| 241 | + bool first = true; |
| 242 | + |
| 243 | + while (pos < end) |
| 244 | + { |
| 245 | + const auto c = *pos++; |
| 246 | + |
| 247 | + if (!((c >= 'A' && c <= 'Z') || |
| 248 | + (c >= 'a' && c <= 'z') || |
| 249 | + c == '{' || |
| 250 | + c == '}' || |
| 251 | + (!first && c >= '0' && c <= '9') || |
| 252 | + (!first && c == '$') || |
| 253 | + (!first && c == '_'))) |
| 254 | + { |
| 255 | + if (!first) |
| 256 | + --pos; |
| 257 | + |
| 258 | + break; |
| 259 | + } |
| 260 | + |
| 261 | + first = false; |
| 262 | + } |
| 263 | + |
| 264 | + token.processedText = token.rawText = std::string(start, pos); |
| 265 | + std::transform(token.processedText.begin(), token.processedText.end(), |
| 266 | + token.processedText.begin(), toupper); |
| 267 | + |
| 268 | + return token; |
| 269 | +} |
| 270 | + |
| 271 | +std::optional<FrontendLexer::Token> FrontendLexer::getStringToken() |
| 272 | +{ |
231 | 273 | if (pos >= end) |
232 | 274 | return std::nullopt; |
233 | 275 |
|
| 276 | + Token token; |
234 | 277 | const auto start = pos; |
235 | 278 |
|
236 | 279 | switch (toupper(*pos)) |
|
0 commit comments