end -> newline

This commit is contained in:
Nikita Ivanov 2022-06-08 08:42:55 +05:00
parent 9227cea15d
commit ecf560c2b8
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
3 changed files with 9 additions and 9 deletions

View File

@ -162,12 +162,12 @@ static int command(void)
static int commands(void)
{
accept(TOK_END);
accept(TOK_NEW_LN);
while (1) {
CHECK_NULL(accept(TOK_EOF));
CHECK_OK(command());
CHECK_OK_NULL(accept(TOK_END));
CHECK_OK_NULL(accept(TOK_NEW_LN));
}
}

10
lexer.c
View File

@ -222,13 +222,13 @@ static inline Token get_tok(Lexer *ctx, enum TokenType type)
.col = ctx->tok_pos.col };
}
static inline Token read_end(Lexer *ctx)
static inline Token read_new_line(Lexer *ctx)
{
Token tok = get_tok(ctx, TOK_NULL);
while (peek_char(ctx) == '\n') {
next_char(ctx);
tok.type = TOK_END;
tok.type = TOK_NEW_LN;
}
return tok;
@ -364,7 +364,7 @@ Token lexer_get_token(Lexer *ctx)
ATTEMPT_READ_CHAR(ctx, tok, '*', TOK_STAR);
ATTEMPT_READ_CHAR(ctx, tok, '.', TOK_DOT);
ATTEMPT_READ(ctx, read_end);
ATTEMPT_READ(ctx, read_new_line);
ATTEMPT_READ(ctx, read_symbol);
ATTEMPT_READ(ctx, read_digit);
ATTEMPT_READ(ctx, read_block);
@ -390,8 +390,8 @@ char *lexer_token_type_str(enum TokenType type)
return "<end of file>";
case TOK_ERR:
return "<TOKEN ERROR>";
case TOK_END:
return "<end>";
case TOK_NEW_LN:
return "<newline>";
case TOK_BLK_OPEN:
return block_open;
case TOK_BLK_CLS:

View File

@ -11,12 +11,12 @@
typedef struct Lexer Lexer;
typedef struct {
int line, col;
unsigned int line, col;
enum TokenType {
TOK_NULL,
TOK_EOF,
TOK_ERR,
TOK_END,
TOK_NEW_LN,
TOK_BLK_OPEN,
TOK_BLK_CLS,
TOK_SLASH,