Skip to content

Commit

Permalink
fix: add to avoid calculating the length of a escaped char in char_co…
Browse files Browse the repository at this point in the history
…nstant_function (#451)

* fix: add to avoid calculating the length of a escaped char in char_constant function

* add to test a line with escaped chars
  • Loading branch information
NiumXp authored Nov 13, 2023
1 parent 0e28c3b commit eefad71
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 0 additions & 3 deletions norminette/lexer/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ def char_constant(self):
self.tokens.append(Token("TKN_ERROR", pos))
return
if self.peek_char() == "'":
for i in tkn_value:
if i == "\\":
self.__line_pos += 1
self.pop_char()
self.tokens.append(Token("CHAR_CONST", pos, tkn_value))
return
Expand Down
2 changes: 2 additions & 0 deletions tests/rules/samples/test_file_2007.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ int philo(int argc, char const *argv[], char *const envp[])
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");
}
if (c == ' ' & c == '\t' & c == '\n' & c == '\v' & c == '\f' & c == '\r')
return (1);
(void) argv;
}
8 changes: 6 additions & 2 deletions tests/rules/samples/test_file_2007.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
<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":
test_file_2007.c - IsControlStatement In "Function" from "GlobalScope" line 13":
<TAB> <IF> <SPACE> <LPARENTHESIS> <IDENTIFIER=c> <SPACE> <EQUALS> <SPACE> <CHAR_CONST=' '> <SPACE> <BWISE_AND> <SPACE> <IDENTIFIER=c> <SPACE> <EQUALS> <SPACE> <CHAR_CONST='\t'> <SPACE> <BWISE_AND> <SPACE> <IDENTIFIER=c> <SPACE> <EQUALS> <SPACE> <CHAR_CONST='\n'> <SPACE> <BWISE_AND> <SPACE> <IDENTIFIER=c> <SPACE> <EQUALS> <SPACE> <CHAR_CONST='\v'> <SPACE> <BWISE_AND> <SPACE> <IDENTIFIER=c> <SPACE> <EQUALS> <SPACE> <CHAR_CONST='\f'> <SPACE> <BWISE_AND> <SPACE> <IDENTIFIER=c> <SPACE> <EQUALS> <SPACE> <CHAR_CONST='\r'> <RPARENTHESIS> <NEWLINE>
test_file_2007.c - IsExpressionStatement In "ControlStructure" from "Function" line 14":
<TAB> <TAB> <RETURN> <SPACE> <LPARENTHESIS> <CONSTANT=1> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsExpressionStatement In "Function" from "GlobalScope" line 15":
<TAB> <LPARENTHESIS> <VOID> <RPARENTHESIS> <SPACE> <IDENTIFIER=argv> <SEMI_COLON> <NEWLINE>
test_file_2007.c - IsBlockEnd In "Function" from "GlobalScope" line 14":
test_file_2007.c - IsBlockEnd In "Function" from "GlobalScope" line 16":
<RBRACE> <NEWLINE>
test_file_2007.c: Error!
Error: INVALID_HEADER (line: 1, col: 1): Missing or invalid 42 header
Expand Down

0 comments on commit eefad71

Please sign in to comment.