Fixed multiline comment bug
We forgot to skip '-' when parsing multiline comment begining
This commit is contained in:
parent
e528fd9e83
commit
118837f6d8
@ -86,7 +86,7 @@ void assert(bool condition, std::string message, Location loc)
|
|||||||
|
|
||||||
encourage_contact(std::cerr);
|
encourage_contact(std::cerr);
|
||||||
|
|
||||||
std::exit(1);
|
std::exit(42);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void unimplemented(std::string_view message, Location loc)
|
[[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);
|
encourage_contact(std::cerr);
|
||||||
|
|
||||||
std::exit(1);
|
std::exit(42);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void unreachable(Location loc)
|
[[noreturn]] void unreachable(Location loc)
|
||||||
{
|
{
|
||||||
error_heading(std::cerr, loc, Error_Level::Bug, "Reached unreachable state");
|
error_heading(std::cerr, loc, Error_Level::Bug, "Reached unreachable state");
|
||||||
encourage_contact(std::cerr);
|
encourage_contact(std::cerr);
|
||||||
std::exit(1);
|
std::exit(42);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, Error const& err)
|
std::ostream& operator<<(std::ostream& os, Error const& err)
|
||||||
|
46
src/lexer.cc
46
src/lexer.cc
@ -24,25 +24,35 @@ static_assert(Keywords.size() == Keywords_Count, "Table above should contain all
|
|||||||
void Lexer::skip_whitespace_and_comments()
|
void Lexer::skip_whitespace_and_comments()
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
bool done_something = false;
|
{ // Skip whitespace
|
||||||
|
bool done_something = false;
|
||||||
while (consume_if(unicode::is_space)) {
|
while (consume_if(unicode::is_space)) done_something = true;
|
||||||
done_something = true;
|
if (done_something) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #! line comments
|
{ // Skip #! comments
|
||||||
if (consume_if('#', '!')) {
|
if (consume_if('#', '!')) {
|
||||||
done_something = true;
|
while (peek() && peek() != '\n') consume();
|
||||||
while (peek() && peek() != '\n') {
|
continue;
|
||||||
consume();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- line and multiline coments
|
// -- line and multiline coments
|
||||||
if (consume_if('-', '-')) {
|
if (consume_if('-', '-')) {
|
||||||
done_something = true;
|
if (!consume_if('-')) {
|
||||||
if (consume_if('-')) {
|
// skiping a single line comment requires advancing until newline
|
||||||
// multiline
|
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;
|
unsigned count = 0;
|
||||||
while (count < 3) if (consume_if('-')) {
|
while (count < 3) if (consume_if('-')) {
|
||||||
++count;
|
++count;
|
||||||
@ -50,17 +60,15 @@ void Lexer::skip_whitespace_and_comments()
|
|||||||
consume();
|
consume();
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
// skip remaining from multiline comment ending
|
||||||
while (consume_if('-')) {}
|
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
|
||||||
break;
|
// so our work is done
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user