Skip to content

Commit

Permalink
fix line pos with escaped chars (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiumXp authored Jul 31, 2023
1 parent cd03c5c commit 4fcbb1b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion norminette/lexer/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def pop_char(self, skip_escaped=True):
if self.peek_char() == "\t":
self.__line_pos += 4 - (self.__line_pos - 1 & 3)
else:
self.__line_pos += 1
self.__line_pos += len(self.peek_char())
if self.__pos < self.len and skip_escaped and self.src[self.__pos] == "\\":
self.__pos += 1
self.__pos += 1
Expand Down
14 changes: 14 additions & 0 deletions tests/rules/samples/test_file_2007.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int philo(int argc, char const *argv[], char *const envp[])
{
char *str;

if (argc != 1)
{
ft_putstr("\033[0;33mUsage: ./philo number_of_philosophers time_to_die");
ft_putstr("time_to_eat time_to_sleep [number_of_times_each_philosopher");
ft_putstr("_must_eat]\033[0m\n");
ft_putstr("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
ft_putstr("time_to_eat time_to_sleep [number_of_times_each_philosopher");
}
(void) argv;
}
35 changes: 35 additions & 0 deletions tests/rules/samples/test_file_2007.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
test_file_2007.c - IsFuncDeclaration In "GlobalScope" from "None" line 1":
<INT> <TAB> <IDENTIFIER=philo> <LPARENTHESIS> <INT> <SPACE> <IDENTIFIER=argc> <COMMA> <SPACE> <CHAR> <SPACE> <CONST> <SPACE> <MULT> <IDENTIFIER=argv> <LBRACKET> <RBRACKET> <COMMA> <SPACE> <CHAR> <SPACE> <MULT> <CONST> <SPACE> <IDENTIFIER=envp> <LBRACKET> <RBRACKET> <RPARENTHESIS> <NEWLINE>
test_file_2007.c - IsBlockStart In "Function" from "GlobalScope" line 2":
<LBRACE> <NEWLINE>
test_file_2007.c - IsVarDeclaration In "Function" from "GlobalScope" line 3":
<TAB> <CHAR> <SPACE> <MULT> <IDENTIFIER=str> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsEmptyLine In "Function" from "GlobalScope" line 4":
<NEWLINE>
test_file_2007.c - IsControlStatement In "Function" from "GlobalScope" line 5":
<TAB> <IF> <SPACE> <LPARENTHESIS> <IDENTIFIER=argc> <SPACE> <NOT_EQUAL> <SPACE> <CONSTANT=1> <RPARENTHESIS> <NEWLINE>
test_file_2007.c - IsBlockStart In "ControlStructure" from "Function" line 6":
<TAB> <LBRACE> <NEWLINE>
test_file_2007.c - IsFunctionCall In "ControlStructure" from "Function" line 7":
<TAB> <TAB> <IDENTIFIER=ft_putstr> <LPARENTHESIS> <STRING="\033[0;33mUsage: ./philo number_of_philosophers time_to_die"> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsFunctionCall In "ControlStructure" from "Function" line 8":
<TAB> <TAB> <IDENTIFIER=ft_putstr> <LPARENTHESIS> <STRING="time_to_eat time_to_sleep [number_of_times_each_philosopher"> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsFunctionCall In "ControlStructure" from "Function" line 9":
<TAB> <TAB> <IDENTIFIER=ft_putstr> <LPARENTHESIS> <STRING="_must_eat]\033[0m\n"> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsFunctionCall In "ControlStructure" from "Function" line 10":
<TAB> <TAB> <IDENTIFIER=ft_putstr> <LPARENTHESIS> <STRING="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsFunctionCall In "ControlStructure" from "Function" line 11":
<TAB> <TAB> <IDENTIFIER=ft_putstr> <LPARENTHESIS> <STRING="time_to_eat time_to_sleep [number_of_times_each_philosopher"> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsBlockEnd In "ControlStructure" from "Function" line 12":
<TAB> <RBRACE> <NEWLINE>
test_file_2007.c - IsExpressionStatement In "Function" from "GlobalScope" line 13":
<TAB> <LPARENTHESIS> <VOID> <RPARENTHESIS> <SPACE> <IDENTIFIER=argv> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsBlockEnd In "Function" from "GlobalScope" line 14":
<RBRACE> <NEWLINE>
test_file_2007.c: Error!
Error: INVALID_HEADER (line: 1, col: 1): Missing or invalid 42 header
Error: SPACE_REPLACE_TAB (line: 3, col: 9): Found space when expecting tab
Error: LINE_TOO_LONG (line: 7, col: 82): line too long
Error: LINE_TOO_LONG (line: 8, col: 82): line too long
Error: LINE_TOO_LONG (line: 10, col: 117): line too long
Error: LINE_TOO_LONG (line: 11, col: 82): line too long
4 changes: 2 additions & 2 deletions tests/rules/samples/test_file_210923.out
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ Error: MULT_ASSIGN_LINE (line: 6, col: 16): Multiple assignations on a si
Error: INCLUDE_START_FILE (line: 9, col: 1): Include must be at the start of file
Error: TOO_FEW_TAB (line: 15, col: 13): Missing tabs for indent level
Error: TOO_MANY_INSTR (line: 15, col: 13): Too many instructions on a single line
Error: TOO_FEW_TAB (line: 23, col: 23): Missing tabs for indent level
Error: TOO_MANY_INSTR (line: 23, col: 23): Too many instructions on a single line
Error: TOO_FEW_TAB (line: 23, col: 24): Missing tabs for indent level
Error: TOO_MANY_INSTR (line: 23, col: 24): Too many instructions on a single line
Error: TOO_FEW_TAB (line: 31, col: 12): Missing tabs for indent level
Error: TOO_MANY_INSTR (line: 31, col: 12): Too many instructions on a single line
Error: TOO_MANY_FUNCS (line: 47, col: 1): Too many functions in file
Expand Down

0 comments on commit 4fcbb1b

Please sign in to comment.