Skip to content

Commit

Permalink
fix #470 (#481)
Browse files Browse the repository at this point in the history
* fix #470
  • Loading branch information
NiumXp committed Feb 1, 2024
1 parent bdf04dd commit 7e1a8b1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions norminette/rules/is_preprocessor_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import contextlib

from norminette.rules import Rule, Primary
from norminette.lexer.dictionary import keywords
from norminette.exceptions import CParsingError
from norminette.context import Macro

Expand Down Expand Up @@ -45,6 +46,8 @@
"DOT",
"SPACE",
"TAB",
# TODO Remove all keyword tokens and add to just use 'IDENTIFIER' instead
*keywords.values(), # https://github.com/42School/norminette/issues/470
)


Expand Down
12 changes: 11 additions & 1 deletion tests/rules/samples/check_preprocessor_include.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ void main(void);

#if 1
# include "ok but not ok.h"
#endif
#endif

#include <float.h>
#include <int.h>
#include <char.h>
#include <wchar.h>
#include <if.h>
#include <else.h>
#include <bool.h>
#include <null.h>
#include <NULL.h>
31 changes: 30 additions & 1 deletion tests/rules/samples/check_preprocessor_include.out
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,40 @@
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 11":
<HASH> <SPACE> <IDENTIFIER=include> <SPACE> <STRING="ok but not ok.h"> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 12":
<HASH> <IDENTIFIER=endif>
<HASH> <IDENTIFIER=endif> <NEWLINE>
check_preprocessor_include.c - IsEmptyLine In "GlobalScope" from "None" line 13":
<NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 14":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <FLOAT> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 15":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <INT> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 16":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <CHAR> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 17":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <IDENTIFIER=wchar> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 18":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <IF> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 19":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <ELSE> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 20":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <IDENTIFIER=bool> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 21":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <IDENTIFIER=null> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c - IsPreprocessorStatement In "GlobalScope" from "None" line 22":
<HASH> <IDENTIFIER=include> <SPACE> <LESS_THAN> <NULL> <DOT> <IDENTIFIER=h> <MORE_THAN> <NEWLINE>
check_preprocessor_include.c: Error!
Error: INVALID_HEADER (line: 1, col: 1): Missing or invalid 42 header
Error: INCLUDE_HEADER_ONLY (line: 2, col: 10): .c file includes are forbidden
Error: INCLUDE_HEADER_ONLY (line: 3, col: 10): .c file includes are forbidden
Error: CONSECUTIVE_NEWLINES (line: 5, col: 1): Consecutive newlines
Error: INCLUDE_START_FILE (line: 8, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 11, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 14, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 15, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 16, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 17, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 18, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 19, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 20, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 21, col: 1): Include must be at the start of file
Error: INCLUDE_START_FILE (line: 22, col: 1): Include must be at the start of file

0 comments on commit 7e1a8b1

Please sign in to comment.