Add support for CRLF text files
This commit is contained in:
parent
edf807a5b3
commit
26095748df
2 changed files with 25 additions and 0 deletions
|
@ -33,6 +33,7 @@ Here, common macros are specified
|
||||||
#define ASCII_TAB 9
|
#define ASCII_TAB 9
|
||||||
#define ASCII_SPACE 32
|
#define ASCII_SPACE 32
|
||||||
#define ASCII_NEWLINE 10
|
#define ASCII_NEWLINE 10
|
||||||
|
#define ASCII_CARRIAGE_RETURN 13
|
||||||
|
|
||||||
#define INSTR_INP 0b0001
|
#define INSTR_INP 0b0001
|
||||||
#define INSTR_OUT 0b0010
|
#define INSTR_OUT 0b0010
|
||||||
|
|
24
src/lexer.c
24
src/lexer.c
|
@ -91,6 +91,30 @@ void lexer(FILE *input_file, dynamic_buffer_t *tokens)
|
||||||
|
|
||||||
is_pos_line_start = 1;
|
is_pos_line_start = 1;
|
||||||
break;
|
break;
|
||||||
|
case ASCII_CARRIAGE_RETURN:
|
||||||
|
// Some operating systems use \r\n or just \r for newlines in texts.
|
||||||
|
|
||||||
|
// This is a indice of a new token -> increase token_index
|
||||||
|
token_index++;
|
||||||
|
|
||||||
|
// This also is a indice of a new instruction beginning
|
||||||
|
// in the tokens array, instructions are seperated by semicolons
|
||||||
|
((char (*)[MAX_TOKEN_SIZE]) tokens->buffer)[token_index][0] = ';';
|
||||||
|
tokens->used += MAX_TOKEN_SIZE;
|
||||||
|
|
||||||
|
// Since the Instruction seperator (';') is also a token, we need to increase token_index again
|
||||||
|
token_index++;
|
||||||
|
|
||||||
|
// Check for \r\n
|
||||||
|
if((char) prefgetc(input_file) == ASCII_NEWLINE)
|
||||||
|
{
|
||||||
|
// Skip over this \n
|
||||||
|
current_char = fgetc(input_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
is_pos_line_start = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case ';':
|
case ';':
|
||||||
// Loop over the comment
|
// Loop over the comment
|
||||||
while (prefgetc(input_file) != ASCII_NEWLINE && prefgetc(input_file) != '\0')
|
while (prefgetc(input_file) != ASCII_NEWLINE && prefgetc(input_file) != '\0')
|
||||||
|
|
Loading…
Reference in a new issue