▲ 8 ▼ My Last Resort - I Need Help Debugging my Program (reddthat.com) submitted 5 months ago by dr_robotBones@reddthat.com to c/csharp@programming.dev 11 comments fedilink hide all child comments
[+] dr_robotBones@reddthat.com [S] 1 point 5 months ago (4 children) [deleted] permalink fedilink source parent hideshow 4 child comments replies: [–] gjoel@programming.dev 2 points 5 months ago (1 child) while (Peek() != '*' && PeekAhead() != '/' && !IsAtEnd()) { Probably this guy. If you encounter an asterisk or a slash, then it stops. You want to stop when you encounter an asterisk and a slash, so: while (!(Peek() == '*' && PeekAhead() == '/') && !IsAtEnd()) { I also find your detection of when to remove the comment a bit scary, but that might be because you haven't shown the Match method. permalink fedilink source parent hideshow 1 child comment load more comments (1 reply) [–] fruitcantfly@programming.dev 1 point 5 months ago (1 child) It's not strictly speaking a bug, but the behavior of Advance is a bit confusing. Based on how you use it in the code snippets, I would suggest changing it to private void Advance() { current++; } So that it only does what it says, and then changing the place where you read the next char to char c = Peek(); Advance(); Alternatively, you could rename it to something like ReadChar, which more closely matches its current behavior, since a read is expected to return the data (character) at the current position, and then advance the position permalink fedilink source parent hideshow 1 child comment load more comments (1 reply)
[–] gjoel@programming.dev 2 points 5 months ago (1 child) while (Peek() != '*' && PeekAhead() != '/' && !IsAtEnd()) { Probably this guy. If you encounter an asterisk or a slash, then it stops. You want to stop when you encounter an asterisk and a slash, so: while (!(Peek() == '*' && PeekAhead() == '/') && !IsAtEnd()) { I also find your detection of when to remove the comment a bit scary, but that might be because you haven't shown the Match method. permalink fedilink source parent hideshow 1 child comment load more comments (1 reply)
[–] fruitcantfly@programming.dev 1 point 5 months ago (1 child) It's not strictly speaking a bug, but the behavior of Advance is a bit confusing. Based on how you use it in the code snippets, I would suggest changing it to private void Advance() { current++; } So that it only does what it says, and then changing the place where you read the next char to char c = Peek(); Advance(); Alternatively, you could rename it to something like ReadChar, which more closely matches its current behavior, since a read is expected to return the data (character) at the current position, and then advance the position permalink fedilink source parent hideshow 1 child comment load more comments (1 reply)