Fixes bug in identifier/keyword parsing, adds lexer integration tests.

This commit is contained in:
2020-10-04 21:05:51 +02:00
parent b6a5e047c2
commit 469c708788
2 changed files with 31 additions and 4 deletions

View File

@@ -466,9 +466,9 @@ namespace ElohimScript::Parser {
while (IsAlphaNumericalOrUnderscore(Peek(offset))) {
offset++;
}
auto str = _script.substr(_position, offset);
Progress(offset);
switch (Hash(str.data())) {
auto str = std::u8string(_script.substr(start, offset));
Progress(offset - 1);
switch (Hash(str.c_str())) {
case Hash(u8"and"): return new LexTokenImpl<LexTokenKind::AndKeyword>(TextSpan(start, _position));
case Hash(u8"abstract"): return new LexTokenImpl<LexTokenKind::AbstractKeyword>(TextSpan(start, _position));
case Hash(u8"auto"): return new LexTokenImpl<LexTokenKind::AutoKeyword>(TextSpan(start, _position));
@@ -537,7 +537,7 @@ namespace ElohimScript::Parser {
case Hash(u8"while"): return new LexTokenImpl<LexTokenKind::WhileKeyword>(TextSpan(start, _position));
case Hash(u8"xor"): return new LexTokenImpl<LexTokenKind::XorKeyword>(TextSpan(start, _position));
default: return new IdentifierToken(TextSpan(start, _position), std::u8string(str));
default: return new IdentifierToken(TextSpan(start, _position), str);
}
}
bool Lexer::IsAlphaNumericalOrUnderscore(char8_t c) {