Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add to PreProcessors only hold positive numbers #410

Merged
merged 4 commits into from
Jul 20, 2023

Conversation

NiumXp
Copy link
Contributor

@NiumXp NiumXp commented Jul 18, 2023

If we put too many endif or else without a pair, we get too many “TOO_MANY_WS” errors:

#endif
#endif
#endif
#endif
#endif
#endif
Error: INVALID_HEADER       (line:   1, col:   1):      Missing or invalid 42 header
Error: PREPROC_BAD_ENDIF    (line:   1, col:   1):      Endif preprocessor statement without if, elif or else
Error: TOO_MANY_WS          (line:   1, col:   1):      Extra whitespaces for indent level
Error: TOO_MANY_WS          (line:   2, col:   1):      Extra whitespaces for indent level
Error: TOO_MANY_WS          (line:   3, col:   1):      Extra whitespaces for indent level
Error: TOO_MANY_WS          (line:   4, col:   1):      Extra whitespaces for indent level
Error: TOO_MANY_WS          (line:   5, col:   1):      Extra whitespaces for indent level
Error: TOO_MANY_WS          (line:   6, col:   1):      Extra whitespaces for indent level

To fix it, we can change the indentation value to max(0, indent) in CheckPreprocessorIndent, but we won't get the errors that every endif must have a #if, #elif or # else, because in IsPreprocessorStatement we check whether the indent == 0 instead of < 1.

To fix these two bugs, we need to make indent hold only positive integers as a value. Result:

Error: INVALID_HEADER       (line:   1, col:   1):      Missing or invalid 42 header
Error: PREPROC_BAD_ENDIF    (line:   1, col:   1):      Endif preprocessor statement without if, elif or else
Error: PREPROC_BAD_ENDIF    (line:   2, col:   1):      Endif preprocessor statement without if, elif or else
Error: PREPROC_BAD_ENDIF    (line:   3, col:   1):      Endif preprocessor statement without if, elif or else
Error: PREPROC_BAD_ENDIF    (line:   4, col:   1):      Endif preprocessor statement without if, elif or else
Error: PREPROC_BAD_ENDIF    (line:   5, col:   1):      Endif preprocessor statement without if, elif or else
Error: PREPROC_BAD_ENDIF    (line:   6, col:   1):      Endif preprocessor statement without if, elif or else

@matthieu42Network matthieu42Network merged commit ab50bf5 into 42School:master Jul 20, 2023
@NiumXp NiumXp deleted the fixprepocindent branch July 20, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants