42School / norminette

Official 42 norminette
MIT License
956 stars 140 forks source link

feat: add to allow use comments in other scopes that is not from a function #454

Closed NiumXp closed 11 months ago

NiumXp commented 11 months ago

Fixes #434.

Now the users can do whaterver they want with comments that is not in a function or in the middle of a instruction/line:

struct {
    // points is to something
    int points; // is an int :D
};

void hello(/* nothing */ void) // error because comment is in middle of the line
{
   // error because scope is from a function
   {
      // are you trying to cheat?
      // error because scope is from a function
   }
}; 
NiumXp commented 11 months ago

Just adding some a know bug here:

void hello(void)
{
    /* 1 */ /* 2 */ /* 3 */ // 4
}
Error: INVALID_HEADER       (line:   1, col:   1):      Missing or invalid 42 header
Error: SPACE_BEFORE_FUNC    (line:   1, col:   5):      space before function name
Error: WRONG_SCOPE_COMMENT  (line:   3, col:   5):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  13):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  13):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  21):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  21):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  21):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  29):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  29):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  29):      Comment is invalid in this scope
Error: WRONG_SCOPE_COMMENT  (line:   3, col:  29):      Comment is invalid in this scope

The first comment triggers one error, the second triggers two, ..., btw, I don't think this can be an issue since it only appears in this specific scenario that is not usual