Fixes for tests, support for comments.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-01-09 13:43:29 +01:00
parent 59af34fac9
commit 0fbca3f01e
7 changed files with 153 additions and 133 deletions

View File

@@ -9,6 +9,7 @@ namespace MalachScript::Parser {
Unknown,
EndOfFile,
Whitespace,
Comment,
// Symbols
StarSymbol,
@@ -265,6 +266,7 @@ namespace MalachScript::Parser {
case LexTokenKind::IntegerLiteral: return "integer";
case LexTokenKind::StringLiteral: return "string";
case LexTokenKind::Identifier: return "identifier";
case LexTokenKind::Comment: return "Comment";
}
return "FAIL";
}

View File

@@ -57,6 +57,25 @@ namespace MalachScript::Parser {
// /=
return Create<LexTokenImpl<LexTokenKind::SlashEqualsSymbol>>(
ScriptTextSpan(start, start + 2, _scriptName));
} else if (Peek() == '/') {
Progress();
while (true) {
auto next = Consume();
if (next == '\n' || next == '\0') {
return Create<LexTokenImpl<LexTokenKind::Comment>>(
ScriptTextSpan(start, _position, _scriptName));
}
}
} else if (Peek() == '*') {
Progress();
while (true) {
auto next = Consume();
if ((next == '*' && Peek() == '/') || next == '\0') {
Progress();
return Create<LexTokenImpl<LexTokenKind::Comment>>(
ScriptTextSpan(start, _position, _scriptName));
}
}
}
// /
return Create<LexTokenImpl<LexTokenKind::SlashSymbol>>(ScriptTextSpan(start, start + 1, _scriptName));

View File

@@ -5,7 +5,7 @@
#define PROGRESS_TOKEN(token) \
token = (token)->GetNext().get(); \
while ((token)->GetKind() == LexTokenKind::Whitespace) { \
while ((token)->GetKind() == LexTokenKind::Whitespace || (token)->GetKind() == LexTokenKind::Comment) { \
(token) = (token)->GetNext().get(); \
}
@@ -57,7 +57,7 @@ namespace MalachScript::Parser {
size_t currentAmount = 0;
const auto* current = currentToken;
while (true) {
while (current->GetKind() == LexTokenKind::Whitespace) {
while (current->GetKind() == LexTokenKind::Whitespace || current->GetKind() == LexTokenKind::Comment) {
current = current->GetNext().get();
}
if (current->GetKind() == LexTokenKind::EndOfFile) {