you are viewing a single comment's thread
view the rest of the comments
[+] [S] 1 point 5 months ago (4 children)
  • [–] 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.

  • source
  • parent
  • hideshow 1 child comment
  • load more comments (1 reply)
  • [–] 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

  • source
  • parent
  • hideshow 1 child comment
  • load more comments (1 reply)