jamesjuett / lobster

Interactive Program Visualization Tools
8 stars 3 forks source link

Bug: Comment at end of file with no extra newline causes syntax error #328

Open jamesjuett opened 2 years ago

jamesjuett commented 2 years ago

Repro:

#include <iostream>

using namespace std;

int main() {
  cout << "Hello World!" << endl;
}
//test
iteemhe commented 2 years ago

This error is caused by the cpp_parser, which is generated by the grammar file. In this case, because it is harder to modify the grammar file. The best alternative is to play a trick in Program text.

My fix is to always add a newline to the end of text in SourceFile. It will not cause any issues in most cases. The only side effect this fix will cause is when there is a syntax error in the last line of code.

iteemhe commented 2 years ago

Proposed fix

Screen Shot 2022-03-12 at 19 44 20

Bug it will cause(there is no line 10).

Screen Shot 2022-03-12 at 19 44 51

iteemhe commented 2 years ago

the bug has been handled in getSourceReference. See follow up in pull request.