skvadrik / re2c

Lexer generator for C, C++, Go and Rust.
https://re2c.org
Other
1.07k stars 169 forks source link

Cannot comment in the brace of user code. #391

Closed krishna116 closed 2 years ago

krishna116 commented 2 years ago

For example, re2c v2.2 cannot compile follow code because "//comment" used in the brace.

int lex(const char *YYCURSOR) 
{
    for(;;)
    {
    /*!re2c
        re2c:define:YYCTYPE = char;
        re2c:yyfill:enable = 0;

        [123]   { //printf("%c", *YYCURSOR); break; }
    */
    break;
    }
    return 0;
}

The error is: image

skvadrik commented 2 years ago

This is because // comments everything up to the end of line. This is not re2c-specific behavior, it is simply how single-line comments work in any language.

You can either break the code into multiple lines:

    [123] {
        //printf("%c", *YYCURSOR);
        break;
    }

Or use a nested multiline comment /* ... */:

    [123] { /*printf("%c", *YYCURSOR);*/ break; }
krishna116 commented 2 years ago

Ok, thank you for the explain and detail example, so it is closed.