Fixed multiline comment bug

We forgot to skip '-' when parsing multiline comment begining
This commit is contained in:
Robert Bendun 2022-06-06 03:08:34 +02:00
parent e528fd9e83
commit 118837f6d8
2 changed files with 30 additions and 22 deletions

View File

@ -86,7 +86,7 @@ void assert(bool condition, std::string message, Location loc)
encourage_contact(std::cerr);
std::exit(1);
std::exit(42);
}
[[noreturn]] void unimplemented(std::string_view message, Location loc)
@ -99,14 +99,14 @@ void assert(bool condition, std::string message, Location loc)
encourage_contact(std::cerr);
std::exit(1);
std::exit(42);
}
[[noreturn]] void unreachable(Location loc)
{
error_heading(std::cerr, loc, Error_Level::Bug, "Reached unreachable state");
encourage_contact(std::cerr);
std::exit(1);
std::exit(42);
}
std::ostream& operator<<(std::ostream& os, Error const& err)

View File

@ -24,25 +24,35 @@ static_assert(Keywords.size() == Keywords_Count, "Table above should contain all
void Lexer::skip_whitespace_and_comments()
{
for (;;) {
{ // Skip whitespace
bool done_something = false;
while (consume_if(unicode::is_space)) {
done_something = true;
while (consume_if(unicode::is_space)) done_something = true;
if (done_something) continue;
}
// #! line comments
{ // Skip #! comments
if (consume_if('#', '!')) {
done_something = true;
while (peek() && peek() != '\n') {
consume();
while (peek() && peek() != '\n') consume();
continue;
}
}
// -- line and multiline coments
if (consume_if('-', '-')) {
done_something = true;
if (consume_if('-')) {
// multiline
if (!consume_if('-')) {
// skiping a single line comment requires advancing until newline
while (peek() && peek() != '\n') consume();
continue;
}
// multiline comments begins with at least 3 '-' and ends with at least 3 '-'
// so when we encounter 3 '-', we must explicitly skip remaining '-', so they
// wil not end multiline comment
// skip remaining from multiline comment begining
while (consume_if('-')) {}
{ // parse multiline comment until '---' marking end
unsigned count = 0;
while (count < 3) if (consume_if('-')) {
++count;
@ -50,16 +60,14 @@ void Lexer::skip_whitespace_and_comments()
consume();
count = 0;
}
// skip remaining from multiline comment ending
while (consume_if('-')) {}
} else {
// single line
while (peek() && peek() != '\n') {
consume();
}
}
continue;
}
if (not done_something)
// When we reached this place, we didn't skip any whitespace or comment
// so our work is done
break;
}
}